-
Notifications
You must be signed in to change notification settings - Fork 7
/
update_tor.sh
executable file
·85 lines (73 loc) · 1.92 KB
/
update_tor.sh
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
#!/bin/bash
# SPDX-License-Identifier: GPL-3.0-or-later
# set -x
# update Tor and restart Tor relay(s) under Gentoo Linux (OpenRC)
function restart() {
export GRACEFUL_TIMEOUT=20
# shellcheck disable=SC2011
ls /etc/init.d/tor{,?} |
xargs -n 1 basename |
while read -r service; do
echo
echo "----------------------------"
date
echo " $service"
echo
if ! rc-service $service status; then
echo -e "\n skipped"
else
if ! rc-service $service restart; then
if pid=$(cat /run/tor/$service.pid); then
if kill -0 $pid; then
echo " kill pid $pid"
kill -9 $pid
sleep 1
else
rm /run/tor/$service.pid
echo " stale pid $pid"
fi
fi
if ! rc-service $service zap start; then
echo "zap start failed"
fi
fi
fi
echo
done
}
#######################################################################
set -eu
export LANG=C.utf8
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export GIT_PAGER="cat"
if [[ ! -d ~/tor ]]; then
cd ~
git clone https://git.torproject.org/tor.git/
# any parameter forces a rebuild
elif [[ $# -eq 0 ]]; then
tmpfile=$(mktemp /tmp/$(basename $0)_XXXXXX.tmp)
cd ~/tor
git pull &>$tmpfile
range=$(grep -e "^Updating .*\.\..*$" $tmpfile | cut -f 2 -d ' ' -s)
if [[ -n $range ]]; then
cat $tmpfile
echo
git log $range
echo
rm $tmpfile
else
rm $tmpfile
# detect the need of a rebuild if e.g. libevent was updated and tor therefore refuses even to start
# plus: if git pull succeeded but a subsequent emerge failed, then this would give a version versus commit id mismatch
if tor --version | grep -q $(git show --quiet --oneline 'HEAD' | cut -f 1 -d ' '); then
exit 0
fi
fi
fi
echo
date
emerge -1 net-vpn/tor
restart
echo
date
echo " all work done"