catchup with lots of updates
[buildscripts] / tor-browser
1 #!/bin/bash
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 if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi
17
18
19 # stable version is shown on:
20 # https://dist.torproject.org/torbrowser/
21 # except sometimes you get a new stable before it's
22 # officially released, which is ok by me. for example,
23 # right now, it has 6.5.2, but stable is 6.5.1.
24 # we exclude verions with letters, as that seems to
25 # be a relatively reliable indication of alpha/beta releases.
26
27 # Their server has failed a few times on me, so do some retrying.
28 for (( i=0; i <= 6 ; i++ )); do
29 c=$(curl -s https://dist.torproject.org/torbrowser/) && break
30 sleep 15
31 done
32 if [[ ! $c ]]; then
33 echo "$0: error: failed to curl tor directory listing" >&2
34 exit 1
35 fi
36 vers=($(printf "%s\n" "$c" | sed -rn 's#.*href="([0-9]+\.[0-9]+[.0-9]*)/.*#\1#p' | sort -Vr))
37
38 # by default it has perms for just 1 non-root user, which is ok for now.
39
40 cd /a/opt
41
42 dl() {
43 f=tor-browser-linux64-${ver}_ALL.tar.xz
44 if [[ -e $f ]]; then
45 timestamp=$(stat -c %Y $f)
46 else
47 timestamp=0
48 fi
49 ret=0
50 echo wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f
51 wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f || ret=$?
52 }
53
54 # some releases are for specific non-gnu oses
55 for ((i=0; i<${#vers[@]}; i++)); do
56 ver=${vers[i]}
57 dl
58 # 8 is return code for 404.
59 if [[ $ret != 8 ]]; then
60 break
61 fi
62 done
63
64 new_timestamp=$(stat -c %Y $f)
65 if [[ $timestamp != $new_timestamp || ! -e /a/opt/tor-browser/Browser/start-tor-browser ]]; then
66 # not already installed
67 rm -rf tor-browser
68 tar Jxf $f
69
70
71
72 ## begin handlers customization
73 ## the default file doesn't exist anymore. i customized it to open magnet links,
74 ## it might work with removing the default stuff and keeping the magnet link part,
75 ## but I'd have to test and I don't care that much.
76 # dest=/a/opt/tor-browser/Browser/TorBrowser/Data/Browser/profile.default/handlers.json
77 # orig=/p/c/tor-handlers-orig.json
78 # src=/p/c/tor-handlers.json
79 # if ! diff -q $src $dest &>/dev/null; then
80 # echo "Error: handlers file changed. adjust based on upstream"
81 # exit 1
82 # fi
83 # cp $src $dest
84 ## end handlers customization
85
86 cp /p/c/tor-user.js /a/opt/tor-browser/Browser/TorBrowser/Data/Browser/profile.default/user.js
87
88 fi
89
90 for x in tor-*.tar.xz; do
91 # cleanup old tarballs
92 [[ -e $x ]] || break
93 [[ $x != $f ]] || continue
94 command rm -f $x
95 done