-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
267 lines (249 loc) · 7.45 KB
/
setup.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
# Function to check if the OS is macOS
check_macos() {
if [ $(uname) == "Darwin" ]; then
echo "macOS detected."
return 0
else
echo "This is not macOS."
return 1
fi
}
# Function to check if the OS is Debian-based (e.g., Ubuntu)
check_debian() {
if [ -f /etc/debian_version ] || [ -f /etc/lsb-release ]; then
echo "Debian-based Linux detected."
return 0
else
echo "This is not a Debian-based Linux distribution."
return 1
fi
}
# Function to check if the OS is Red Hat-based (e.g., CentOS, Fedora)
check_redhat() {
if [[ -f /etc/redhat-release ]]; then
echo "Red Hat-based Linux detected."
return 0
else
echo "This is not a Red Hat-based Linux distribution."
return 1
fi
}
# Function to check if Python 3 exists, and install if necessary (macOS)
check_python_macos() {
if command -v python3 &>/dev/null; then
echo "Python 3 is already installed."
return 0
else
echo "Python 3 is not installed. Attempting to install..."
brew install python3
if [ $? -eq 0 ]; then
echo "Python 3 installation successful."
return 0
else
echo "Failed to install Python 3."
return 1
fi
fi
}
# Function to check if Python 3 exists, and install if necessary (Debian-based Linux)
check_python_debian() {
if command -v python3 &>/dev/null; then
echo "Python 3 is already installed."
return 0
else
echo "Python 3 is not installed. Attempting to install..."
sudo apt-get update && sudo apt-get install -y python3
if [ $? -eq 0 ]; then
echo "Python 3 installation successful."
return 0
else
echo "Failed to install Python 3."
return 1
fi
fi
}
# Function to check if Python 3 exists, and install if necessary (Red Hat-based Linux)
check_python_redhat() {
if command -v python3 &>/dev/null; then
echo "Python 3 is already installed."
return 0
else
echo "Python 3 is not installed. Attempting to install..."
sudo yum install -y python3
if [ $? -eq 0 ]; then
echo "Python 3 installation successful."
return 0
else
echo "Failed to install Python 3."
return 1
fi
fi
}
# Function to check if pip3 exists, and install if necessary (macOS)
check_pip_macos() {
if command -v pip3 &>/dev/null; then
echo "pip3 is already installed."
return 0
else
echo "pip3 is not installed. Attempting to install..."
brew install pip3
if [ $? -eq 0 ]; then
echo "pip3 installation successful."
return 0
else
echo "Failed to install pip3."
return 1
fi
fi
}
# Function to check if pip3 exists, and install if necessary (Debian-based Linux)
check_pip_debian() {
if command -v pip3 &>/dev/null; then
echo "pip3 is already installed."
return 0
else
echo "pip3 is not installed. Attempting to install..."
sudo apt-get update && sudo apt-get install -y python3-pip
if [ $? -eq 0 ]; then
echo "pip3 installation successful."
return 0
else
echo "Failed to install pip3."
return 1
fi
fi
}
# Function to check if pip3 exists, and install if necessary (Red Hat-based Linux)
check_pip_redhat() {
if command -v pip3 &>/dev/null; then
echo "pip3 is already installed."
return 0
else
echo "pip3 is not installed. Attempting to install..."
sudo yum install -y python3-pip
if [ $? -eq 0 ]; then
echo "pip3 installation successful."
return 0
else
echo "Failed to install pip3."
return 1
fi
fi
}
# Function to check if Python 3's venv module exists, and install if necessary (macOS)
check_venv_macos() {
if python3 -m venv --help &>/dev/null; then
echo "Python 3 venv module is already installed."
return 0
else
echo "Python 3 venv module is not installed. Attempting to install..."
python3 -m pip install virtualenv
if [ $? -eq 0 ]; then
echo "Python 3 venv module installation successful."
return 0
else
echo "Failed to install Python 3 venv module."
return 1
fi
fi
}
# Function to check if Python 3's venv module exists, and install if necessary (Debian-based Linux)
check_venv_debian() {
sudo apt-get update && sudo apt-get install -y python3-venv
if [ $? -eq 0 ]; then
echo "Python 3 venv module installation successful."
return 0
else
echo "Failed to install Python 3 venv module."
return 1
fi
}
# Function to check if Python 3's venv module exists, and install if necessary (Red Hat-based Linux)
check_venv_redhat() {
sudo pip3 install virtualenv
if [ $? -eq 0 ]; then
echo "Python 3 venv module installation successful."
return 0
else
echo "Failed to install Python 3 venv module."
return 1
fi
}
# Call the appropriate function based on the OS
create_venv() {
echo "Creating virtual environment 'myvenv'"
python3 -m venv myvenv
if [ $? -eq 0 ]; then
echo "Virtual environment 'myvenv' created."
return 0
else
echo "Cannot create virtual environment."
return 1
fi
}
install_requirements() {
echo "Installing requirements..."
./myvenv/bin/pip install -r requirements.txt
if [ $? -eq 0 ]; then
echo "Requirements installed."
return 0
else
echo "requirements.txt file not found."
return 1
fi
}
# Function to create a one-file executable using PyInstaller
create_executable() {
if [ -f "app.py" ]; then
echo "Creating one-file executable using PyInstaller..."
if ./myvenv/bin/pyinstaller --onefile --add-data "resources:resources" --add-data "appresources:appresources" "app.py"; then
echo "Executable created."
else
echo "failed to create executable"
fi
else
echo "app.py file not found."
fi
}
main() {
if check_macos; then
if check_python_macos; then
if check_pip_macos; then
if check_venv_macos; then
if create_venv; then
if install_requirements; then
create_executable
fi
fi
fi
fi
fi
elif check_debian; then
if check_python_debian; then
if check_pip_debian; then
if check_venv_debian; then
if create_venv; then
if install_requirements; then
create_executable
fi
fi
fi
fi
fi
elif check_redhat; then
if check_python_redhat; then
if check_pip_redhat; then
if check_venv_redhat; then
if create_venv; then
if install_requirements; then
create_executable
fi
fi
fi
fi
fi
fi
}
# Call the main function
main