From c92d203a94165cada669095c2ac47ab68ff9a284 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 18 Oct 2016 09:45:25 +0100 Subject: [PATCH] Tidying --- src/freedombone-utils-onion | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/freedombone-utils-onion b/src/freedombone-utils-onion index e6ae2750..74a5dc33 100755 --- a/src/freedombone-utils-onion +++ b/src/freedombone-utils-onion @@ -28,29 +28,38 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -function wait_for_onion_service { +function onion_service_exists { + onion_service_name="$1" + + if [ -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then + echo "1" + else + echo "0" + fi +} + +function wait_for_onion_service_base { onion_service_name="$1" sleep_ctr=0 - while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do + while [ $(onion_service_exists ${onion_service_name}) == "0" ]; do sleep 1 sleep_ctr=$((sleep_ctr + 1)) if [ $sleep_ctr -gt 10 ]; then break fi done +} - if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then +function wait_for_onion_service { + onion_service_name="$1" + + wait_for_onion_service_base ${onion_service_name} + + if [ $(onion_service_exists ${onion_service_name}) == "0" ]; then # reload and try a second time systemctl reload tor - sleep_ctr=0 - while [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; do - sleep 1 - sleep_ctr=$((sleep_ctr + 1)) - if [ $sleep_ctr -gt 10 ]; then - break - fi - done + wait_for_onion_service_base ${onion_service_name} fi } @@ -68,7 +77,7 @@ function remove_onion_service { fi fi fi - if [ -d /var/lib/tor/hidden_service_${onion_service_name} ]; then + if [ $(onion_service_exists ${onion_service_name}) == "1" ]; then shred -zu /var/lib/tor/hidden_service_${onion_service_name}/* rm -rf /var/lib/tor/hidden_service_${onion_service_name} fi @@ -80,7 +89,7 @@ function add_onion_service { onion_service_port_from=$2 onion_service_port_to=$3 - if [ -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then + if [ $(onion_service_exists ${onion_service_name}) == "1" ]; then echo $(cat /var/lib/tor/hidden_service_${onion_service_name}/hostname) return fi @@ -99,7 +108,7 @@ function add_onion_service { function_check wait_for_onion_service wait_for_onion_service ${onion_service_name} - if [ ! -f /var/lib/tor/hidden_service_${onion_service_name}/hostname ]; then + if [ $(onion_service_exists ${onion_service_name}) == "0" ]; then echo $"${onion_service_name} onion site hostname not found" exit 76362 fi