minor fixes
[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 vers=($(curl -s https://dist.torproject.org/torbrowser/ \
28 | sed -rn 's#.*href="([0-9]+\.[0-9]+[.0-9]*)/.*#\1#p' \
29 | sort -Vr))
30
31
32
33 # by default it has perms for just 1 non-root user, which is ok for now.
34
35 cd /a/opt
36
37 ver=${vers[0]}
38 dl() {
39 f=tor-browser-linux64-${ver}_en-US.tar.xz
40 if [[ -e $f ]]; then
41 timestamp=$(stat -c %Y $f)
42 else
43 timestamp=0
44 fi
45 echo wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f
46 wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f || ret=$?
47 }
48 dl
49 # 8 is return code for 404. for a new release, they might not have released to linux yet.
50 if [[ $ret == 8 ]]; then
51 ver=${vers[1]}
52 dl
53 fi
54
55 new_timestamp=$(stat -c %Y $f)
56 if [[ $timestamp != $new_timestamp || ! -e /a/opt/tor-browser_en-US/Browser/start-tor-browser ]]; then
57 # not already installed
58 rm -rf tor-browser_en-US
59 tar Jxf $f
60
61 ## begin handlers customization
62 dest=/a/opt/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default/handlers.json
63 orig=/p/c/tor-handlers-orig.json
64 src=/p/c/tor-handlers.json
65 if diff -q $src $dest; then
66 echo "Error: handlers file changed. adjust based on upstream"
67 exit 1
68 fi
69 cp $src $dest
70 ## end handlers customization
71
72 cp /p/c/tor-user.js /a/opt/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default/user.js
73
74 fi
75
76 for x in tor-*.tar.xz; do
77 # cleanup old tarballs
78 [[ -e $x ]] || break
79 [[ $x != $f ]] || continue
80 command rm -f $x
81 done