-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer_python-version.sh
executable file
·278 lines (243 loc) · 9.36 KB
/
installer_python-version.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
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
welcome() {
echo "
╔═══════════════════════════════════════╗
║ ║
║ ~ NovaNav Browser ~ ║
║ Developed with ❤️ by ║
║ Felipe Alfonso González L. ║
║ Computer Science Engineer ║
║ Chile ║
║ ║
║ Contact: [email protected] ║
║ Licensed under BSD 3-clause ║
║ GitHub: github.com/felipealfonsog ║
║ ║
╚═══════════════════════════════════════╝
"
echo "Welcome to the NovaNav Browser - Bash installer!"
echo "---------------------------------------------------------------------"
}
check_execute_permission() {
if [[ ! -x "$0" ]]; then
echo "The installer script does not have execute permission. Do you want to grant it?"
select yn in "Yes" "No"; do
case $yn in
Yes)
chmod +x "$0"
exec "$0" "$@"
;;
No)
echo "Exiting program."
exit 0
;;
*)
echo "Invalid option. Please choose a valid option."
;;
esac
done
fi
}
check_homebrew_installation_macOS() {
if ! command -v brew &> /dev/null; then
echo "Homebrew is not installed on macOS. Do you want to install it?"
select yn in "Yes" "No"; do
case $yn in
Yes)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
break
;;
No)
echo "Exiting program."
exit 0
;;
*)
echo "Invalid option. Please choose a valid option."
;;
esac
done
fi
}
check_homebrew_installation_linux() {
if ! command -v brew &> /dev/null; then
echo "Homebrew/Linuxbrew is not installed on Linux. Do you want to install it?"
select yn in "Yes" "No"; do
case $yn in
Yes)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
break
;;
No)
echo "Exiting program."
exit 0
;;
*)
echo "Invalid option. Please choose a valid option."
;;
esac
done
fi
}
install_dependencies_linux() {
if ! command -v python3 &> /dev/null; then
echo "Python3 is not installed on Linux. Do you want to install it?"
select yn in "Yes, using Homebrew" "Yes, using package manager" "No"; do
case $yn in
"Yes, using Homebrew")
brew install python python-pip python-pyqt5 python-pyqt5-webengine
break
;;
"Yes, using package manager")
if [[ -f /etc/arch-release ]]; then
sudo pacman -S python python-pip python-pyqt5 python-pyqt5-webengine
elif [[ -f /etc/debian_version ]]; then
sudo apt-get update && sudo apt-get install python python-pip python-pyqt5 python-pyqt5-webengine
else
echo "Unsupported Linux distribution. Please install Python3 manually, read documentation according to your distro, and re-run the installer."
exit 1
fi
break
;;
"No")
echo "Exiting program."
exit 0
;;
*)
echo "Invalid option. Please choose a valid option."
;;
esac
done
fi
}
download_source_code() {
if [[ $(uname) == "Darwin" ]]; then
source_file_url="https://raw.githubusercontent.com/felipealfonsog/GitSyncMaster/main/src/python/novanav_macos.py"
source_file_name="novanav_macos.py"
elif [[ $(uname) == "Linux" ]]; then
source_file_url="https://raw.githubusercontent.com/felipealfonsog/GitSyncMaster/main/src/python/novanav_linux.py"
source_file_name="novanav_linux.py"
else
echo "Unsupported operating system. Please install manually, read documentation, and re-run the installer."
exit 1
fi
curl -o "$source_file_name" "$source_file_url"
}
move_exec_file() {
if [[ -f "$source_file_name" ]]; then
# Transform the source file into an executable
chmod +x "$source_file_name"
if [[ $(uname) == "Darwin" ]]; then
# Move the executable file to /usr/local/bin/
sudo cp "$source_file_name" /usr/local/bin/
# Assign execution permissions if novanav doesn't exist in that location
if [[ ! -x /usr/local/bin/novanav ]]; then
sudo chmod +x /usr/local/bin/novanav
fi
else
# Copy the source file to /bin directory of each distribution
if [[ -f /etc/arch-release ]]; then
sudo cp "$source_file_name" /usr/bin/
elif [[ -f /etc/debian_version ]]; then
sudo cp "$source_file_name" /usr/local/bin/
else
sudo cp "$source_file_name" /usr/local/bin/
fi
# Move the executable file to the appropriate location
if [[ -f /etc/arch-release ]]; then
sudo mv "$source_file_name" /usr/bin/novanav
elif [[ -f /etc/debian_version ]]; then
sudo mv "$source_file_name" /usr/local/bin/novanav
else
sudo mv "$source_file_name" /usr/local/bin/novanav
fi
# Assign execution permissions to the novanav file if it already exists in any of those locations
if [[ -x /usr/bin/novanav ]]; then
sudo chmod +x /usr/bin/novanav
elif [[ -x /usr/local/bin/novanav ]]; then
sudo chmod +x /usr/local/bin/novanav
fi
fi
else
echo "Error: File $source_file_name not found."
exit 1
fi
}
install_icon_desk_file() {
# Destination directory for the files
destination_dir="/usr/share"
# Download the icon
curl -o nnav-iconlogo.png https://raw.githubusercontent.com/felipealfonsog/NovaNav/821d0ab8103a79dcefcd2458396d72a7304660ea/src/nnav-iconlogo.png
# Install the icon to the pixmaps folder
sudo install -Dm644 -p nnav-iconlogo.png "$destination_dir/pixmaps/novanav.png"
# Download the .desktop file
curl -o novanav.desktop https://raw.githubusercontent.com/felipealfonsog/NovaNav/main/src/novanav.desktop
# Install the .desktop file to the applications folder
sudo install -Dm644 -p novanav.desktop "$destination_dir/applications/novanav.desktop"
# Remove the downloaded temporary files
rm nnav-iconlogo.png novanav.desktop
}
configure_path() {
if [[ $(uname) == "Darwin" ]]; then
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
else
if [[ -f ~/.bashrc ]]; then
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
elif [[ -f ~/.bash_profile ]]; then
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
else
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.profile
source ~/.profile
fi
fi
}
reload_shell() {
if [[ $(uname) == "Darwin" ]]; then
source ~/.bash_profile
elif [[ $(uname) == "Linux" ]]; then
if [[ -f /etc/arch-release ]]; then
source ~/.bashrc
elif [[ -f /etc/debian_version ]]; then
source ~/.bashrc
else
source ~/.bashrc
fi
fi
}
cleanup() {
if [[ -f "$source_file_name" ]]; then
rm "$source_file_name"
echo "Downloaded file '$source_file_name' has been deleted."
fi
if [[ -f "installer.sh" ]]; then
rm "installer.sh"
echo "Installer script 'installer.sh' has been deleted."
fi
if [[ -f "novanav" ]]; then
rm "novanav"
echo "Installer binary has been deleted."
fi
}
main() {
welcome
check_execute_permission
if [[ $(uname) == "Darwin" ]]; then
check_homebrew_installation_macOS
elif [[ $(uname) == "Linux" ]]; then
check_homebrew_installation_linux
install_dependencies_linux
fi
download_source_code
move_exec_file
install_icon_desk_file
configure_path
reload_shell
cleanup
echo "--------------------------------------------------------------------------------"
echo "You can now run the program by typing 'novanav' in the terminal."
echo "If you're using Arch Linux, you can find NovaNav Browser in your program menu!."
echo "--------------------------------------------------------------------------------"
}
main