overdue commit lots of changes
[buildscripts] / tor-browser
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23
24 if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi
25
26
27 # stable version is shown on:
28 # https://dist.torproject.org/torbrowser/
29 # except sometimes you get a new stable before it's
30 # officially released, which is ok by me. for example,
31 # right now, it has 6.5.2, but stable is 6.5.1.
32 # we exclude verions with letters, as that seems to
33 # be a relatively reliable indication of alpha/beta releases.
34
35 # Their server has failed a few times on me, so do some retrying.
36 for (( i=0; i <= 6 ; i++ )); do
37 c=$(curl -s https://dist.torproject.org/torbrowser/) && break
38 sleep 15
39 done
40 if [[ ! $c ]]; then
41 echo "$0: error: failed to curl tor directory listing" >&2
42 exit 1
43 fi
44 vers=($(printf "%s\n" "$c" | sed -rn 's#.*href="([0-9]+\.[0-9]+[.0-9]*)/.*#\1#p' | sort -Vr))
45
46 # by default it has perms for just 1 non-root user, which is ok for now.
47
48 cd /a/opt
49
50 dl() {
51 f=tor-browser-linux64-${ver}_ALL.tar.xz
52 if [[ -e $f ]]; then
53 timestamp=$(stat -c %Y $f)
54 else
55 timestamp=0
56 fi
57 ret=0
58 echo wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f
59 wget -nv -N https://www.torproject.org/dist/torbrowser/$ver/$f || ret=$?
60 }
61
62 # some releases are for specific non-gnu oses
63 for ((i=0; i<${#vers[@]}; i++)); do
64 ver=${vers[i]}
65 dl
66 # 8 is return code for 404.
67 if [[ $ret != 8 ]]; then
68 break
69 fi
70 done
71
72 new_timestamp=$(stat -c %Y $f)
73 if [[ $timestamp != $new_timestamp || ! -e /a/opt/tor-browser/Browser/start-tor-browser ]]; then
74 # not already installed
75 rm -rf tor-browser
76 tar Jxf $f
77
78
79
80 ## begin handlers customization
81 ## the default file doesn't exist anymore. i customized it to open magnet links,
82 ## it might work with removing the default stuff and keeping the magnet link part,
83 ## but I'd have to test and I don't care that much.
84 # dest=/a/opt/tor-browser/Browser/TorBrowser/Data/Browser/profile.default/handlers.json
85 # orig=/p/c/tor-handlers-orig.json
86 # src=/p/c/tor-handlers.json
87 # if ! diff -q $src $dest &>/dev/null; then
88 # echo "Error: handlers file changed. adjust based on upstream"
89 # exit 1
90 # fi
91 # cp $src $dest
92 ## end handlers customization
93
94 cp /p/c/tor-user.js /a/opt/tor-browser/Browser/TorBrowser/Data/Browser/profile.default/user.js
95
96 fi
97
98 for x in tor-*.tar.xz; do
99 # cleanup old tarballs
100 [[ -e $x ]] || break
101 [[ $x != $f ]] || continue
102 command rm -f $x
103 done