ソースを参照

Wait for onion service as its own function

Bob Mottram 9 年 前
コミット
2352457d84
共有1 個のファイルを変更した16 個の追加38 個の削除を含む
  1. 16
    38
      src/freedombone

+ 16
- 38
src/freedombone ファイルの表示

@@ -1263,6 +1263,18 @@ function set_default_onion_domains {
1263 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 1278
 function add_onion_service {
1267 1279
     onion_service_name="$1"
1268 1280
     onion_service_port_from=$2
@@ -1278,16 +1290,7 @@ function add_onion_service {
1278 1290
     fi
1279 1291
 
1280 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 1295
     if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
1293 1296
         echo $"${onion_service_name} onion site hostname not found"
@@ -4275,16 +4278,7 @@ function configure_email {
4275 4278
     fi
4276 4279
 
4277 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 4283
     if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then
4290 4284
         echo $"${onion_service_name} onion site hostname not found"
@@ -6720,15 +6714,7 @@ quit" > $INSTALL_DIR/batch.sql
6720 6714
     fi
6721 6715
 
6722 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 6719
     GIT_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_gogs/hostname)
6734 6720
 
@@ -7134,15 +7120,7 @@ function install_xmpp {
7134 7120
     fi
7135 7121
 
7136 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 7125
     if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
7148 7126
         echo $'XMPP onion site hostname not found'