-
Notifications
You must be signed in to change notification settings - Fork 17
/
unix_install.sh
200 lines (179 loc) · 6.17 KB
/
unix_install.sh
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
#!/bin/sh
# Function to check if a command exists
command_exists() {
command -v "$1" > /dev/null 2>&1
}
# Install on Debian/Ubuntu-based systems
install_on_debian() {
echo "Installing $1..."
sudo apt update
sudo apt install -y "$1"
}
# Install on Red Hat/CentOS/Fedora-based systems
install_on_redhat() {
echo "Installing $1..."
sudo yum install -y "$1"
}
# Install on Arch-based systems
install_on_arch() {
echo "Installing $1..."
sudo pacman -Sy --noconfirm "$1"
}
# Install on BSD-based systems
install_on_bsd() {
echo "Installing $1..."
env ASSUME_ALWAYS_YES=yes sudo pkg install -y "$1"
}
# Install on macOS
install_on_macos() {
echo "Installing $1..."
if command_exists brew; then
brew install "$1"
else
echo "Homebrew is not installed. Installing Homebrew first..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install "$1"
fi
}
set -e
# Check and install Python3
# if command_exists python3 > /dev/null 2>&1; then
# echo "Checking Python..."
# else
# # Detect the platform and install Python3 accordingly
# if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# # Detect the package manager
# if command_exists apt; then
# install_on_debian "python3"
# elif command_exists yum; then
# install_on_redhat "python3"
# elif command_exists pacman; then
# install_on_arch "python-pip"
# else
# echo "Unsupported Linux distribution."
# exit 1
# fi
# elif [[ "$OSTYPE" == "bsd"* ]]; then
# echo "Detected BSD-based system."
# install_on_bsd "python39"
# elif [[ "$OSTYPE" == "darwin"* ]]; then
# install_on_macos "python"
# else
# echo "Unsupported operating system."
# exit 1
# fi
# fi
# Get the Python version
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')
# Compare the Python version with 3.8
REQUIRED_VERSION="3.8"
if [ "$(echo -e "$PYTHON_VERSION\n$REQUIRED_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
echo "Python version $PYTHON_VERSION is >= $REQUIRED_VERSION. Continuing..."
else
echo "ERROR: Python version $PYTHON_VERSION is < $REQUIRED_VERSION. Exiting..."
exit 1
fi
if [ -d ".venv/" ]; then
echo ".venv exists. Installing requirements.txt..."
.venv/bin/pip install -r requirements.txt
else
echo "Making .venv and installing requirements.txt..."
if [ "$(uname)" = "Linux" ]; then
# Detect the package manager for venv installation check.
if command_exists apt; then
echo "Detected Debian-based system. Checking python3-venv."
if dpkg -l | grep -q "python3-venv"; then
echo "python3-venv found."
else
echo "python3-venv not found, installing..."
install_on_debian "python3-venv"
fi
fi
fi
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
fi
if command_exists ffmpeg; then
echo "ffmpeg exists."
else
echo "ffmpeg does not exist."
# Detect the platform and install ffmpeg accordingly.
case "$(uname)" in
Linux)
if command_exists apt; then
echo "Detected Debian-based system."
install_on_debian "ffmpeg"
elif command_exists yum; then
echo "Detected Red Hat-based system."
echo "Installing needed repos for ffmpeg..."
sudo yum config-manager --set-enabled crb > /dev/null 2>&1 || true
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-$(rpm -E %rhel).noarch.rpm > /dev/null 2>&1 || true
sudo yum install -y --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm > /dev/null 2>&1 || true
install_on_redhat "ffmpeg"
elif command_exists pacman; then
echo "Detected Arch-based system."
install_on_arch "ffmpeg"
else
echo "Unsupported Linux distribution."
exit 1
fi
;;
FreeBSD|NetBSD|OpenBSD)
echo "Detected BSD-based system."
install_on_bsd "ffmpeg"
;;
Darwin)
echo "Detected macOS."
install_on_macos "ffmpeg"
;;
*)
echo "Unsupported operating system."
exit 1
;;
esac
fi
if command_exists openssl || .venv/bin/pip list | grep -q pycryptodome; then
echo "openssl or pycryptodome exists."
else
echo "Please choose an option:"
echo "1) openssl"
echo "2) pycryptodome"
read -p "Enter your choice (1): " choice
case "$choice" in
2)
echo "Installing pycryptodome."
.venv/bin/pip install pycryptodome
;;
*)
# Detect the platform and install OpenSSL accordingly.
case "$(uname)" in
Linux)
if command_exists apt; then
install_on_debian openssl
elif command_exists yum; then
install_on_redhat openssl
elif command_exists pacman; then
install_on_arch openssl
else
echo "Unsupported Linux distribution."
exit 1
fi
;;
FreeBSD|NetBSD|OpenBSD)
install_on_bsd openssl
;;
Darwin)
install_on_macos openssl
;;
*)
echo "Unsupported operating system."
exit 1
;;
esac
;;
esac
fi
sed -i.bak '1s|.*|#!.venv/bin/python3|' run.py
sudo chmod +x run.py
echo 'Everything is installed!'
echo 'Run StreamingCommunity with "./run.py"'