-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefox-portable-installer
282 lines (250 loc) · 9.17 KB
/
firefox-portable-installer
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
279
280
281
282
#!/bin/bash
# Script designed to download and install Firefox portable.
VERSION="6"
LICENCE="GPL v3: https://www.gnu.org/licenses/gpl.html "
TRADEMARKS="Name Firefox is trademark Mozilla: https://www.mozilla.org/en-US/foundation/trademarks/list/"
SOURCE="https://github.com/tele1/LinuxScripts"
WARNING="I can help you only with this script. \
But I am not a Firefox developer and I am not responsible for errors in the portable application. \
If you see a problem in the portable application, look for the right developer. \
Try find contact at the end of the web page https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt"
#==================={
ERROR()
{
echo "$@" ; exit 1
}
#===================}
#==================={
ERROR2()
{
echo "$@"
}
#===================}
#======================================={
change_language() {
echo " "
echo "--> Available other languages:"
LIST_LANG=$(curl -v --silent https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt --stderr - | grep -E "^ .* lang=")
echo "$LIST_LANG"
echo " "
echo "--> Set new language or leave empty to set lang=en-US and click Enter key"
read -p "lang=" LANG
# If empty
[[ -z "$LANG" ]] && LANGUAGE="en-US" || LANGUAGE="$LANG"
# If wrong lang
if echo "$LIST_LANG" | grep -qw "lang=$LANG" ; then
echo " "
echo "Chosen language: lang=$LANG"
else
ERROR2 "lang="$LANG" not found :( "
LANGUAGE="en-US"
fi
}
#=======================================}
#=========================={
change_version() {
list_version_firefox() {
LIST_VER=$(curl -v --silent https://ftp.mozilla.org/pub/firefox/releases/ --stderr - | sed -e '/releases\/[0-9]/!d' -e 's/[\t]*<\/*[^>]*>//g' -e 's/\///g' -e '/[a-Z]/d' )
}
list_version_firefox_esr() {
LIST_VER=$(curl --silent https://ftp.mozilla.org/pub/firefox/releases/ --stderr - | sed -e '/[0-9]esr\//!d' -e 's/[\t]*<\/*[^>]*>//g' -e 's/\///g' )
}
echo " "
echo "--> Available versions :"
echo " "
echo "1. Firefox"
echo "2. Firefox ESR"
echo " "
read -p "--> Write a number to choose:" branch_firefox
case "$branch_firefox" in
1 ) BRANCH="Firefox" ; list_version_firefox ;;
2 ) BRANCH="Firefox ESR" ; list_version_firefox_esr ;;
* ) echo "###########################################"
echo "--> Incorrect number."
ERROR2 "###########################################" ;;
esac
echo "Chosen branch: $BRANCH"
echo " "
echo "--> Available versions :"
echo " "
echo "$LIST_VER" | sort --version-sort | column
echo " "
echo "--> Set new version and click Enter key"
read -p "version=" VERSION_FIREFOX
# If wrong version
if echo "$LIST_VER" | grep -qw "$VERSION_FIREFOX" ; then
echo "Chosen version: $VERSION_FIREFOX"
else
ERROR2 "version="$VERSION_FIREFOX" not found :( "
VERSION_FIREFOX="$RELEASE"
fi
}
#==========================}
#================================================================================={
install_app_f() {
# Is installed "curl" ?
[ "$(curl --version)" ] || ERROR "--> Please install Curl before run this script."
LANGUAGE="en-US"
LINK1="https://download.mozilla.org/?product=firefox-latest-ssl&os=linux&lang=${LANGUAGE}"
RELEASE=$(curl -s "${LINK1}" | sed -e 's/.*releases\/\(.*\)\/linux.*/\1/g' -e 1q)
LINK_ESR="https://download.mozilla.org/?product=firefox-esr-latest&os=linux&lang=${LANGUAGE}"
RELEASE_ESR=$(curl -s "${LINK_ESR}" | sed -e 's/.*releases\/\(.*\)\/linux.*/\1/g' -e 1q)
VERSION_FIREFOX="$RELEASE"
LOOPS="y"
while [[ "$LOOPS" == "y" ]] ; do
echo " "
echo "=============================="
echo "--> Language: \"${LANGUAGE}\""
echo "--> Version: \"${VERSION_FIREFOX}\""
echo " ( Latest Firefox: ${RELEASE} )"
echo " ( Latest Firefox ESR: ${RELEASE_ESR} )"
echo " "
echo "1. Change Language"
echo "2. Change Version"
echo "3. Exit"
echo "4. Install Firefox"
echo "5. Uninstall Firefox"
echo "=============================="
echo " "
read -p "--> Write a number to choose:" choice
case "$choice" in
1 ) change_language ;;
2 ) change_version ;;
3 ) exit 0 ;;
4 ) LOOPS="n";;
5 ) uninstall_app_f;;
* ) echo "###########################################"
echo "--> Incorrect number."
echo "###########################################" ;;
esac
done
echo " "
# Download firefox
echo "--> Downloading..."
curl -O https://ftp.mozilla.org/pub/firefox/releases/${VERSION_FIREFOX}/linux-i686/${LANGUAGE}/firefox-${VERSION_FIREFOX}.tar.bz2
# Check if downloaded file exist.
[ "$(ls -A ./firefox*tar.bz2)" ] || ERROR "--> Firefox was not downloaded!"
# Check sum
SUM=$(curl -v --silent https://ftp.mozilla.org/pub/firefox/releases/${VERSION_FIREFOX}/SHA256SUMS --stderr - | grep "linux-i686/${LANGUAGE}/firefox-${VERSION_FIREFOX}.tar.bz2" \
| awk '{print $1}')
echo " "
echo "--> Checking the checksum sha256sum"
echo "$SUM firefox-${VERSION_FIREFOX}.tar.bz2" | sha256sum --check
[ $? == 0 ] || ERROR "--> Downloaded file is broken or sha256sum not exist!"
echo " "
###################################
## Security theory:
# chown -R root:root /opt/firefox
# chmod -R 755 /opt/firefox
# find /opt/ -perm /4000 -o -perm /2000 -o -perm /6000 -o -perm /1000
#
## Important:
# If the regular user can hang the program
# (which is owned by the root user and has the suid or sgid flag set)
# to get to the shell, then he will get the program owner's rights
# (in this case the root user).
# So avoid "suid" or "sgid" flag, if you can.
# Info: https://www.techrepublic.com/blog/it-security/understand-the-setuid-and-setgid-permissions-to-improve-security/
# Calculator: http://permissions-calculator.org/
# How find: https://www.tecmint.com/how-to-find-files-with-suid-and-sgid-permissions-in-linux/
#
## Update Menu theory:
# update-desktop-database /usr/share/applications
# update-menus
## Create link
# ln -s /opt/firefox/firefox ~/Desktop/portable.firefox
###################################
# Own item to menu
cat <<'EOF' >> portablefirefox.desktop
[Desktop Entry]
Version=1.0
Name=Portable.Firefox
GenericName=Web Browser
Comment=Browse the Web
Exec=/opt/firefox/firefox %u
Icon=firefox
Terminal=false
Type=Application
StartupWMClass=PortableFirefox
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;
Categories=GTK;Network;WebBrowser;X-MandrivaLinux-Internet-WebBrowsers;X-MandrivaLinux-CrossDesktop;
EOF
echo " "
# Unpack to /opt/
# Change owner to root
# Add icon to "Menu"
echo "--> Installation:"
if uname -a | grep -iq ubuntu ; then
sudo bash -c 'rm -rf /opt/firefox ; bzip2 -dc firefox*tar.bz2 | tar xvf - -C /opt ; chown -R root:root /opt/firefox ; mv portablefirefox.desktop /usr/share/applications/ ; update-desktop-database /usr/share/applications'
else
su root -c 'rm -rf /opt/firefox ; bzip2 -dc firefox*tar.bz2 | tar xvf - -C /opt ; chown -R root:root /opt/firefox ; mv portablefirefox.desktop /usr/share/applications/ ; update-desktop-database /usr/share/applications'
fi
# Checking file permissions
echo " "
echo "------------------"
# Find files with "suid" or "sgid" flag.
if [[ ! "$(find /opt/firefox -perm /4000 -o -perm /2000 -o -perm /6000 | wc -l)" == "0" ]]; then
RC='\e[0;31m' # Red Color
NC='\e[0m' # No Color
echo -e "${RC} Potentially dangerous files: ${NC}"
find /opt/firefox -perm /4000 -o -perm /2000 -o -perm /6000
echo -e "${RC} Warning! ${NC}"
echo -e "${RC} Found "suid" or "sgid" flag. Using firefox can be dangerous. ${NC}"
exit 1
fi
# Find writable files
if [[ ! "$(find /opt/firefox -perm -o+w | wc -l)" == "0" ]]; then
RC='\e[0;31m' # Red Color
NC='\e[0m' # No Color
echo -e "${RC} Potentially dangerous files: ${NC}"
find /opt/firefox -perm -o+w
echo -e "${RC} Warning! ${NC}"
echo -e "${RC} Found writable files. ${NC}"
exit 1
fi
# Remove superfluous file
rm ./firefox*tar.bz2
# Info.
[ -d "/opt/firefox" ] && echo "--> Portable.Firefox installed now, check."
[ -d "/opt/firefox" ] || echo "--> Installation failed. Path /opt/firefox/ does not exist"
}
#=================================================================================}
#======================{
uninstall_app_f() {
if uname -a | grep -qi ubuntu ; then
sudo bash -c 'rm -rfv /opt/firefox ; rm -rfv /usr/share/applications/portablefirefox.desktop ; update-desktop-database /usr/share/applications'
else
su root -c 'rm -rfv /opt/firefox ; rm -rfv /usr/share/applications/portablefirefox.desktop ; update-desktop-database /usr/share/applications'
fi
[ -d "/opt/firefox" ] || echo "--> Removal /opt/firefox/ completed successfully"
}
#======================}
###################{
case $1 in
"--install")
install_app_f
;;
"--uninstall")
uninstall_app_f
;;
"--help")
echo "Usage: [SCRIPT NAME] [OPTION]"
echo " "
echo " without option will also install portable.firefox"
echo " --install install or reinstall portable.firefox"
echo " --uninstall remove portable.firefox"
echo " --help display this help and exit"
echo " --version output version information and exit"
echo " "
echo -e "WARNING: $WARNING"
;;
"--version")
echo "Script Version: $VERSION"
echo "Licence: $LICENCE"
echo "Trademarks: $TRADEMARKS"
;;
*)
install_app_f
;;
esac
###################}