-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·108 lines (97 loc) · 2.67 KB
/
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
#!/bin/bash
# vim: sw=4 et
set -e
function ask_yn {
select yn in "Yes" "No"; do
case $yn in
Yes)
ask_yn_y_callback
break;;
No)
ask_yn_n_callback
break;;
esac
done
}
function reset-ask_yn {
function ask_yn_y_callback() { echo -n; }
function ask_yn_n_callback() { echo -n; }
}
reset-ask_yn
current_firefox_version=$(firefox --version)
# list options
echo "Options:"
for file in $(ls --color=never dist/* | sort --version-sort | tail -5); do
echo " - $(basename ${file})"
done
echo
echo -n "version [firefox.tar.bz2]: "; read version
version=$(echo $version | rev | cut -d . -f 3- | rev)
echo -n "installation target directory [~/bin]: "; read install_dir
if [ ! -d "$install_dir" ]; then
install_dir="$HOME/bin"
fi
# backup current firefox profiles
function ask_yn_y_callback() {
set -x
target_dir="/tmp/$UID/.mozilla/$current_firefox_version"
if [ -d "$target_dir" ]; then
rm -rf "$target_dir"
fi
mkdir -pv "$target_dir"
rsync -rav "$HOME/.mozilla/firefox" "$target_dir"
set +x
echo "firefox profiles backup location: \"$target_dir\""
}
if [ -d "$HOME/.mozilla/firefox" ]; then
echo "backup firefox profiles?"
ask_yn
reset-ask_yn
fi
# extract firefox
function ask_yn_y_callback() {
set -x
mkdir -pv ~/bin
cp -v "dist/${version}.tar.bz2" ~/bin/
pushd ~/bin
if [ -d "${version}" ]; then
rm -rf "${version}"
fi
mkdir -pv "${version}"
tar -xaf "${version}.tar.bz2" --directory "${install_dir}/${version}"
set +x
}
if [ -d "$HOME/.mozilla/firefox" ]; then
echo "extract firefox $version into \"$install_dir\"?"
ask_yn
reset-ask_yn
fi
# link firefox
function ask_yn_y_callback() {
set -x
pushd ~/bin
ln -sfv "${install_dir}/${version}/firefox/firefox" ./
cp -v "${install_dir}/${version}/firefox/browser/chrome/icons/default/default128.png" "firefox.png"
ls -lah --color=auto "${install_dir}/firefox"
popd
set +x
}
if [ -d "$HOME/.mozilla/firefox" ]; then
echo "link firefox into ~/bin?"
ask_yn
reset-ask_yn
fi
# install firefox desktop file into ~/.local/share/applications
function ask_yn_y_callback() {
set -x
mkdir -pv "$HOME/bin"
cp -v "./firefox.desktop" "/tmp/firefox.desktop.tmpl"
envsubst < "/tmp/firefox.desktop.tmpl" > "/tmp/firefox.desktop"
desktop-file-install --dir="$HOME/.local/share/applications" --rebuild-mime-info-cache "/tmp/firefox.desktop"
rm -v "/tmp/firefox.desktop.tmpl" "/tmp/firefox.desktop"
set +x
}
set +x
echo "install firefox desktop file into ~/.local/share/applications?"
ask_yn
reset-ask_yn