-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·218 lines (200 loc) · 6.85 KB
/
setup.sh
File metadata and controls
executable file
·218 lines (200 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
echo "==============================================="
echo "IPyCam Setup Script"
echo "==============================================="
echo
# Check if Python is installed
if ! command -v python3 &> /dev/null; then
echo "ERROR: Python 3 is not installed or not in PATH"
echo "Please install Python 3.8+ from your package manager"
exit 1
fi
# Check if python3-venv is available
echo "Checking for python3-venv..."
if ! python3 -c "import ensurepip" &> /dev/null; then
echo "python3-venv is not installed"
PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
echo
read -p "Would you like to install python${PYTHON_VERSION}-venv? (Y/N): " install_venv
if [ "${install_venv,,}" = "y" ]; then
echo "Installing python${PYTHON_VERSION}-venv..."
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y python${PYTHON_VERSION}-venv
elif command -v dnf &> /dev/null; then
sudo dnf install -y python${PYTHON_VERSION}-venv
elif command -v yum &> /dev/null; then
sudo yum install -y python${PYTHON_VERSION}-venv
elif command -v pacman &> /dev/null; then
sudo pacman -S --noconfirm python
else
echo "ERROR: No supported package manager found"
echo "Please install python${PYTHON_VERSION}-venv manually"
exit 1
fi
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install python${PYTHON_VERSION}-venv"
exit 1
fi
echo "python${PYTHON_VERSION}-venv has been installed"
else
echo "ERROR: python3-venv is required to continue"
echo "Please install it manually: sudo apt install python${PYTHON_VERSION}-venv"
exit 1
fi
fi
echo
echo "[1/4] Creating virtual environment..."
if [ -d ".venv" ]; then
echo "Virtual environment already exists, skipping creation"
else
python3 -m venv .venv
if [ $? -ne 0 ]; then
echo "ERROR: Failed to create virtual environment"
exit 1
fi
echo "Virtual environment created successfully"
fi
echo
echo "[2/4] Activating virtual environment..."
source .venv/bin/activate
if [ $? -ne 0 ]; then
echo "ERROR: Failed to activate virtual environment"
exit 1
fi
echo
echo "[3/4] Installing dependencies..."
python -m pip install --upgrade pip
pip install -r requirements.txt
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install dependencies"
exit 1
fi
echo
echo "[4/4] Installing IPyCam package..."
pip install -e .
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install IPyCam package"
exit 1
fi
echo
# Detect OS and architecture for go2rtc
detect_platform() {
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux*)
case "$ARCH" in
x86_64) echo "go2rtc_linux_amd64" ;;
aarch64|arm64) echo "go2rtc_linux_arm64" ;;
armv7l) echo "go2rtc_linux_arm" ;;
armv6l) echo "go2rtc_linux_armv6" ;;
i386|i686) echo "go2rtc_linux_i386" ;;
*) echo "" ;;
esac
;;
darwin*)
case "$ARCH" in
x86_64) echo "go2rtc_mac_amd64.zip" ;;
arm64) echo "go2rtc_mac_arm64.zip" ;;
*) echo "" ;;
esac
;;
*) echo "" ;;
esac
}
# Check for go2rtc
echo "[5/6] Checking for go2rtc..."
if [ -f "go2rtc" ] || [ -f "go2rtc.exe" ]; then
echo "go2rtc is already installed"
else
echo "go2rtc is not installed"
echo
read -p "Would you like to download go2rtc? (Y/N): " download
if [ "${download,,}" = "y" ]; then
PLATFORM=$(detect_platform)
if [ -z "$PLATFORM" ]; then
echo "ERROR: Unsupported platform $(uname -s)/$(uname -m)"
echo "Please download go2rtc manually from https://github.com/AlexxIT/go2rtc/releases"
else
echo
echo "Downloading go2rtc v1.9.9 for $PLATFORM..."
GO2RTC_URL="https://github.com/AlexxIT/go2rtc/releases/download/v1.9.9/$PLATFORM"
if command -v curl &> /dev/null; then
curl -L -o "go2rtc_download" "$GO2RTC_URL"
elif command -v wget &> /dev/null; then
wget -O "go2rtc_download" "$GO2RTC_URL"
else
echo "ERROR: Neither curl nor wget found. Please install one of them."
exit 1
fi
if [ $? -ne 0 ]; then
echo "ERROR: Failed to download go2rtc"
exit 1
fi
echo "Extracting go2rtc..."
if [[ "$PLATFORM" == *.zip ]]; then
unzip -o "go2rtc_download" && rm "go2rtc_download"
else
mv "go2rtc_download" "go2rtc"
fi
chmod +x go2rtc
echo "go2rtc has been installed"
fi
else
echo "Skipping go2rtc installation"
fi
fi
echo
# Check for ffmpeg
echo "[6/6] Checking for ffmpeg..."
if command -v ffmpeg &> /dev/null; then
echo "ffmpeg is already installed"
else
echo "ffmpeg is not installed"
echo
read -p "Would you like to install ffmpeg via package manager? (Y/N): " download_ffmpeg
if [ "${download_ffmpeg,,}" = "y" ]; then
echo
echo "Installing ffmpeg..."
# Detect package manager and install
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y ffmpeg
elif command -v yum &> /dev/null; then
sudo yum install -y ffmpeg
elif command -v dnf &> /dev/null; then
sudo dnf install -y ffmpeg
elif command -v pacman &> /dev/null; then
sudo pacman -S --noconfirm ffmpeg
elif command -v brew &> /dev/null; then
brew install ffmpeg
else
echo "ERROR: No supported package manager found"
echo "Please install ffmpeg manually from https://ffmpeg.org/"
exit 1
fi
if [ $? -eq 0 ]; then
echo "ffmpeg has been installed"
else
echo "ERROR: Failed to install ffmpeg"
exit 1
fi
else
echo "Skipping ffmpeg installation"
echo "Note: You can install it later with your package manager:"
echo " Ubuntu/Debian: sudo apt-get install ffmpeg"
echo " Fedora: sudo dnf install ffmpeg"
echo " Arch: sudo pacman -S ffmpeg"
echo " macOS: brew install ffmpeg"
fi
fi
echo
echo "==============================================="
echo "Setup completed successfully!"
echo "==============================================="
echo
echo "To activate the environment, run:"
echo " source .venv/bin/activate"
echo
echo "To run the camera, use:"
echo " python -m ipycam"
echo