Bob Mottram 8 vuotta sitten
vanhempi
commit
c92d203a94
1 muutettua tiedostoa jossa 23 lisäystä ja 14 poistoa
  1. 23
    14
      src/freedombone-utils-onion

+ 23
- 14
src/freedombone-utils-onion Näytä tiedosto

28
 # You should have received a copy of the GNU Affero General Public License
28
 # You should have received a copy of the GNU Affero General Public License
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
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
     onion_service_name="$1"
42
     onion_service_name="$1"
33
 
43
 
34
     sleep_ctr=0
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
         sleep 1
46
         sleep 1
37
         sleep_ctr=$((sleep_ctr + 1))
47
         sleep_ctr=$((sleep_ctr + 1))
38
         if [ $sleep_ctr -gt 10 ]; then
48
         if [ $sleep_ctr -gt 10 ]; then
39
             break
49
             break
40
         fi
50
         fi
41
     done
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
         # reload and try a second time
60
         # reload and try a second time
45
         systemctl reload tor
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
     fi
63
     fi
55
 }
64
 }
56
 
65
 
68
             fi
77
             fi
69
         fi
78
         fi
70
     fi
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
         shred -zu /var/lib/tor/hidden_service_${onion_service_name}/*
81
         shred -zu /var/lib/tor/hidden_service_${onion_service_name}/*
73
         rm -rf /var/lib/tor/hidden_service_${onion_service_name}
82
         rm -rf /var/lib/tor/hidden_service_${onion_service_name}
74
     fi
83
     fi
80
     onion_service_port_from=$2
89
     onion_service_port_from=$2
81
     onion_service_port_to=$3
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
         echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
93
         echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname)
85
         return
94
         return
86
     fi
95
     fi
99
     function_check wait_for_onion_service
108
     function_check wait_for_onion_service
100
     wait_for_onion_service ${onion_service_name}
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
         echo $"${onion_service_name} onion site hostname not found"
112
         echo $"${onion_service_name} onion site hostname not found"
104
         exit 76362
113
         exit 76362
105
     fi
114
     fi