|
@@ -28,29 +28,38 @@
|
28
|
28
|
# You should have received a copy of the GNU Affero General Public License
|
29
|
29
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
30
|
30
|
|
31
|
|
-function wait_for_onion_service {
|
|
31
|
+function onion_service_exists {
|
|
32
|
+ onion_service_name="$1"
|
|
33
|
+
|
|
34
|
+ if [ -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
35
|
+ echo "1"
|
|
36
|
+ else
|
|
37
|
+ echo "0"
|
|
38
|
+ fi
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+function wait_for_onion_service_base {
|
32
|
42
|
onion_service_name="$1"
|
33
|
43
|
|
34
|
44
|
sleep_ctr=0
|
35
|
|
- while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
|
|
45
|
+ while [ $(onion_service_exists ${onion_service_name}) == "0" ]; do
|
36
|
46
|
sleep 1
|
37
|
47
|
sleep_ctr=$((sleep_ctr + 1))
|
38
|
48
|
if [ $sleep_ctr -gt 10 ]; then
|
39
|
49
|
break
|
40
|
50
|
fi
|
41
|
51
|
done
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+function wait_for_onion_service {
|
|
55
|
+ onion_service_name="$1"
|
42
|
56
|
|
43
|
|
- if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
57
|
+ wait_for_onion_service_base ${onion_service_name}
|
|
58
|
+
|
|
59
|
+ if [ $(onion_service_exists ${onion_service_name}) == "0" ]; then
|
44
|
60
|
# reload and try a second time
|
45
|
61
|
systemctl reload tor
|
46
|
|
- sleep_ctr=0
|
47
|
|
- while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
|
48
|
|
- sleep 1
|
49
|
|
- sleep_ctr=$((sleep_ctr + 1))
|
50
|
|
- if [ $sleep_ctr -gt 10 ]; then
|
51
|
|
- break
|
52
|
|
- fi
|
53
|
|
- done
|
|
62
|
+ wait_for_onion_service_base ${onion_service_name}
|
54
|
63
|
fi
|
55
|
64
|
}
|
56
|
65
|
|
|
@@ -68,7 +77,7 @@ function remove_onion_service {
|
68
|
77
|
fi
|
69
|
78
|
fi
|
70
|
79
|
fi
|
71
|
|
- if [ -d /var/lib/tor/hidden_service_${onion_service_name} ]; then
|
|
80
|
+ if [ $(onion_service_exists ${onion_service_name}) == "1" ]; then
|
72
|
81
|
shred -zu /var/lib/tor/hidden_service_${onion_service_name}/*
|
73
|
82
|
rm -rf /var/lib/tor/hidden_service_${onion_service_name}
|
74
|
83
|
fi
|
|
@@ -80,7 +89,7 @@ function add_onion_service {
|
80
|
89
|
onion_service_port_from=$2
|
81
|
90
|
onion_service_port_to=$3
|
82
|
91
|
|
83
|
|
- if [ -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
92
|
+ if [ $(onion_service_exists ${onion_service_name}) == "1" ]; then
|
84
|
93
|
echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
|
85
|
94
|
return
|
86
|
95
|
fi
|
|
@@ -99,7 +108,7 @@ function add_onion_service {
|
99
|
108
|
function_check wait_for_onion_service
|
100
|
109
|
wait_for_onion_service ${onion_service_name}
|
101
|
110
|
|
102
|
|
- if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
|
|
111
|
+ if [ $(onion_service_exists ${onion_service_name}) == "0" ]; then
|
103
|
112
|
echo $"${onion_service_name} onion site hostname not found"
|
104
|
113
|
exit 76362
|
105
|
114
|
fi
|