Browse Source

Wait for onion service as its own function

Bob Mottram 9 years ago
parent
commit
2352457d84
1 changed files with 16 additions and 38 deletions
  1. 16
    38
      src/freedombone

+ 16
- 38
src/freedombone View File

1263
     fi
1263
     fi
1264
 }
1264
 }
1265
 
1265
 
1266
+function wait_for_onion_service {
1267
+    onion_service_name="$1"
1268
+    sleep_ctr=0
1269
+    while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
1270
+        sleep 1
1271
+        sleep_ctr=$((sleep_ctr + 1))
1272
+        if [ $sleep_ctr -gt 20 ]; then
1273
+            break
1274
+        fi
1275
+    done
1276
+}
1277
+
1266
 function add_onion_service {
1278
 function add_onion_service {
1267
     onion_service_name="$1"
1279
     onion_service_name="$1"
1268
     onion_service_port_from=$2
1280
     onion_service_port_from=$2
1278
     fi
1290
     fi
1279
 
1291
 
1280
     systemctl restart tor
1292
     systemctl restart tor
1281
-
1282
-    # wait for the new service to appear
1283
-    sleep_ctr=0
1284
-    while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
1285
-        sleep 1
1286
-        sleep_ctr=$((sleep_ctr + 1))
1287
-        if [ $sleep_ctr -gt 10 ]; then
1288
-            break
1289
-        fi
1290
-    done
1293
+    wait_for_onion_service ${onion_service_name}
1291
 
1294
 
1292
     if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
1295
     if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
1293
         echo $"${onion_service_name} onion site hostname not found"
1296
         echo $"${onion_service_name} onion site hostname not found"
4275
     fi
4278
     fi
4276
 
4279
 
4277
     systemctl restart tor
4280
     systemctl restart tor
4278
-
4279
-    # wait for the new service to appear
4280
-    sleep_ctr=0
4281
-    while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do
4282
-        sleep 1
4283
-        sleep_ctr=$((sleep_ctr + 1))
4284
-        if [ $sleep_ctr -gt 10 ]; then
4285
-            break
4286
-        fi
4287
-    done
4281
+    wait_for_onion_service ${onion_service_name}
4288
 
4282
 
4289
     if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
4283
     if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
4290
         echo $"${onion_service_name} onion site hostname not found"
4284
         echo $"${onion_service_name} onion site hostname not found"
6720
     fi
6714
     fi
6721
 
6715
 
6722
     systemctl restart tor
6716
     systemctl restart tor
6723
-
6724
-    sleep_ctr=0
6725
-    while [ ! -f /var/lib/tor/hidden_service_gogs/hostname ]; do
6726
-        sleep 1
6727
-        sleep_ctr=$((sleep_ctr + 1))
6728
-        if [ $sleep_ctr -gt 10 ]; then
6729
-            break
6730
-        fi
6731
-    done
6717
+    wait_for_onion_service 'gogs'
6732
 
6718
 
6733
     GIT_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_gogs/hostname)
6719
     GIT_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_gogs/hostname)
6734
 
6720
 
7134
     fi
7120
     fi
7135
 
7121
 
7136
     systemctl restart tor
7122
     systemctl restart tor
7137
-
7138
-    sleep_ctr=0
7139
-    while [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; do
7140
-        sleep 1
7141
-        sleep_ctr=$((sleep_ctr + 1))
7142
-        if [ $sleep_ctr -gt 10 ]; then
7143
-            break
7144
-        fi
7145
-    done
7123
+    wait_for_onion_service 'xmpp'
7146
 
7124
 
7147
     if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
7125
     if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
7148
         echo $'XMPP onion site hostname not found'
7126
         echo $'XMPP onion site hostname not found'