consistent license, various updates
[buildscripts] / tor-browser
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -eE -o pipefail
17 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
18
19
20 # stable version is shown on:
21 # https://dist.torproject.org/torbrowser/
22 # except sometimes you get a new stable before it's
23 # officially released, which is ok by me. for example,
24 # right now, it has 6.5.2, but stable is 6.5.1.
25 # we exclude verions with letters, as that seems to
26 # be a relatively reliable indication of alpha/beta releases.
27
28 vers=($(curl -s https://dist.torproject.org/torbrowser/ \
29 | sed -rn 's#.*href="([0-9]+\.[0-9]+[.0-9]*)/.*#\1#p' \
30 | sort -Vr))
31
32
33
34 # by default it has perms for just 1 non-root user, which is ok for now.
35
36 cd /a/opt
37
38 ver=${vers[0]}
39 dl() {
40 f=tor-browser-linux64-${ver}_en-US.tar.xz
41 if [[ -e $f ]]; then
42 timestamp=$(stat -c %Y $f)
43 else
44 timestamp=0
45 fi
46 echo wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f
47 wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f || ret=$?
48 }
49 dl
50 # 8 is return code for 404. for a new release, they might not have released to linux yet.
51 if [[ $ret == 8 ]]; then
52 ver=${vers[1]}
53 dl
54 fi
55
56 new_timestamp=$(stat -c %Y $f)
57 if [[ $timestamp != $new_timestamp || ! -e /a/opt/tor-browser_en-US/Browser/start-tor-browser ]]; then
58 # not already installed
59 rm -rf tor-browser_en-US
60 ex $f
61 fi
62
63 for x in tor-*.tar.xz; do
64 # cleanup old tarballs
65 [[ -e $x ]] || break
66 [[ $x != $f ]] || continue
67 command rm -f $x
68 done
69 s lnf /a/opt/tor-browser_en-US/Browser/start-tor-browser /usr/local/bin