-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtbupdate
executable file
·192 lines (176 loc) · 4.08 KB
/
tbupdate
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
#!/bin/bash
#####
# tbupdate - a simple way to update vanilla thunderbird in linux
#
# thunderbird will install to a folder named "thunderbird" in tbdir
# you may change this, if you want thunderbird installed somewhere else.
# You will probably want to add $tbdir/thunderbird to your $PATH, so
# you can launch thunderbird from the commandline. I prefer $tbdir to
# be /opt/mozilla, but I leave that decision to you.
##########
tbdir="/opt/mozilla"
##########
showhelp()
{
echo "
To download the latest vanilla thunderbird:
$0 -v
To download the latest beta:
$0 -b
To download both:
$0 -a
Mix and match:
$0 -vb
"
}
versionsort()
{
local sortedversions="$(echo -e "$1\n$2" | sort -V)"
#echo $sortedversions
latestversion="$(echo "$sortedversions" | tail -1)"
}
gettburl()
{
bits="$(uname -m)"
[[ "$bits" == "x86_64" ]] && os="linux64" || os="linux"
lang="$(echo "$LANG" | sed -e 's/\..*$//' -e 's/_/-/')"
if [[ "$edition" == "nightly" ]]
then
destdir="$tbdir/nightly"
tburl="https://download.mozilla.org/?product=thunderbird-nightly-latest-ssl&os=$os&lang=$lang"
elif [[ "$edition" == "beta" ]]
then
destdir="$tbdir/beta"
tburl="https://download.mozilla.org/?product=thunderbird-beta-latest-ssl&os=$os&lang=$lang"
elif [[ "$edition" == "developer" ]]
then
destdir="$tbdir/devedition"
tburl="https://download.mozilla.org/?product=thunderbird-devedition-latest-ssl&os=$os&lang=$lang"
elif [[ "$edition" == "vanilla" ]]
then
destdir="$tbdir/vanilla"
tburl="https://download.mozilla.org/?product=thunderbird-latest-ssl&os=$os&lang=$lang"
fi
}
gettbversion()
{
if [[ "$edition" == "nightly" ]]
then
tbversion=$(curl -s -L -I "$tburl" \
| grep Location \
| cut -d '/' -f 8 \
| cut -d '.' -f 1-2 \
| sed 's/thunderbird-//')
else
tbversion=$(curl -s -L -I "$tburl" \
| grep -o '/releases/[^/]*' \
| cut -d '/' -f 3)
fi
#echo $tbversion
local localthunderbird="$destdir"/thunderbird/thunderbird
if [[ -e "$localthunderbird" ]]
then
systbversion="$(cat "$destdir"/tb_version.txt)"
else
# if thunderbird hasn't been installed yet,
# set the system thunderbird version to zero.
systbversion=0
fi
}
ckdirperms(){
local dir=$1
if [[ "$(id -u)" == "$(stat -c '%u' "$dir")" ]]
then
if [[ "$(stat -c "%a" "$dir")" -ge 700 ]]
then
return 0
fi
fi
return 1
}
mkdestdir(){
local dir=$1
local parentdir=$(dirname "$dir")
if [[ -d "$parentdir" ]]
then
if ckdirperms "$parentdir"
then
if [[ -d "$dir" ]]
then
if ckdirperms "$dir"
then
return 0
else
echo " You don't have permission to write to $dir"
fi
else
mkdir -p "$dir"
return 0
fi
else
echo " You don't have permission to write to $parentdir"
fi
else
if mkdestdir "$parentdir"
then
mkdir -p "$dir"
return 0
else
echo "Could not create $parentdir"
fi
fi
return 1
}
updatetb(){
echo "checking for updates for $edition thunderbird ..."
versionsort "$systbversion" "$tbversion"
if [[ "$systbversion" != "$latestversion" ]]
then
if mkdestdir "$destdir"
then
echo "updating $edition thunderbird to version $latestversion ..."
rm -rf "$destdir"/thunderbird
if (curl --progress-bar -L "$tburl") | (cd "$destdir" && tar xjpf -)
then
echo "thunderbird updated!"
echo "$tbversion" > "$destdir"/tb_version.txt
else
echo "there was a problem :-("
fi
else
echo " There is an update available: $latestversion"
echo " Please rerun this command as root to update thunderbird."
fi
else
echo " No updates needed"
fi
}
tbupdate(){
edition=$1
gettburl
gettbversion
updatetb
}
while getopts ":ndbva" opt; do
case $opt in
b)
tbupdate "beta"
;;
v)
tbupdate "vanilla"
;;
a)
for edition in "vanilla" "beta"; do
tbupdate "$edition"
done
;;
*)
showhelp
exit 0
;;
esac
done
if [[ $# -eq 0 ]]
then
showhelp
fi