This commit is contained in:
Bob Mottram 2016-10-18 09:45:25 +01:00
parent 24b51ca457
commit c92d203a94
1 changed files with 23 additions and 14 deletions

View File

@ -28,29 +28,38 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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