|
@@ -1,13 +1,21 @@
|
|
|
#!/bin/bash
|
|
|
-### BEGIN INIT INFO
|
|
|
-# Provides: ynh-torclient
|
|
|
-# Required-Start: $network $remote_fs $syslog ynh-hotspot
|
|
|
-# Required-Stop: $network $remote_fs $syslog ynh-hotspot
|
|
|
-# Default-Start: 2 3 4 5
|
|
|
-# Default-Stop: 0 1 6
|
|
|
-# Short-Description: Set prerequisites for wifi torclient.
|
|
|
-# Description: Set prerequisites for wifi torclient.
|
|
|
-### END INIT INFO
|
|
|
+
|
|
|
+# TOR Client app for YunoHost
|
|
|
+# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
|
|
+# Contribute at https://github.com/jvaubourg/torclient_ynh
|
|
|
+#
|
|
|
+# This program is free software: you can redistribute it and/or modify
|
|
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
+# (at your option) any later version.
|
|
|
+#
|
|
|
+# This program is distributed in the hope that it will be useful,
|
|
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+# GNU Affero General Public License for more details.
|
|
|
+#
|
|
|
+# 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/>.
|
|
|
|
|
|
# Functions
|
|
|
## State functions
|
|
@@ -25,7 +33,7 @@ is_nat_set() {
|
|
|
}
|
|
|
|
|
|
is_tor_running() {
|
|
|
- service tor status &> /dev/null
|
|
|
+ systemctl is-active tor &> /dev/null
|
|
|
}
|
|
|
|
|
|
is_running() {
|
|
@@ -50,7 +58,7 @@ unset_nat() {
|
|
|
}
|
|
|
|
|
|
stop_tor() {
|
|
|
- service tor stop &> /dev/null
|
|
|
+ systemctl stop tor
|
|
|
}
|
|
|
|
|
|
start_tor() {
|
|
@@ -58,20 +66,24 @@ start_tor() {
|
|
|
|
|
|
sed "s|<TPL:TOR_NETWORK>|${ynh_wifi_prefix}|g" -i /etc/tor/torrc
|
|
|
|
|
|
- service tor start
|
|
|
+ systemctl start tor
|
|
|
}
|
|
|
|
|
|
## Tools
|
|
|
|
|
|
moulinette_get() {
|
|
|
var=${1}
|
|
|
+ gotcha=0
|
|
|
|
|
|
- value=$(yunohost app setting torclient "${var}")
|
|
|
+ while [ "${gotcha}" -eq 0 ]; do
|
|
|
+ value=$(yunohost app setting torclient "${var}")
|
|
|
|
|
|
- if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
- echo "${value}" >&2
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+ if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
+ sleep $(($((RANDOM%5)) + 1))
|
|
|
+ else
|
|
|
+ gotcha=1
|
|
|
+ fi
|
|
|
+ done
|
|
|
|
|
|
echo "${value}"
|
|
|
}
|
|
@@ -90,16 +102,20 @@ moulinette_set() {
|
|
|
|
|
|
moulinette_hotspot_get() {
|
|
|
var=${1}
|
|
|
+ gotcha=0
|
|
|
|
|
|
- value=$(yunohost app setting hotspot "${var}")
|
|
|
+ while [ "${gotcha}" -eq 0 ]; do
|
|
|
+ value=$(yunohost app setting hotspot "${var}")
|
|
|
|
|
|
- if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
- echo "${value}" >&2
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+ if [[ "${value}" =~ "An instance is already running" ]]; then
|
|
|
+ sleep $(($((RANDOM%5)) + 1))
|
|
|
+ else
|
|
|
+ gotcha=1
|
|
|
+ fi
|
|
|
+ done
|
|
|
|
|
|
echo "${value}"
|
|
|
-}
|
|
|
+}
|
|
|
|
|
|
do_start() {
|
|
|
if is_running; then
|
|
@@ -171,33 +187,46 @@ do_status() {
|
|
|
exit ${exitcode}
|
|
|
}
|
|
|
|
|
|
-# Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
|
|
|
-if [ ! -e /tmp/.ynh-torclient-boot ]; then
|
|
|
- touch /tmp/.ynh-torclient-boot
|
|
|
- service php5-fpm restart
|
|
|
-fi
|
|
|
+if [ "$1" != restart ]; then
|
|
|
|
|
|
-# Variables
|
|
|
+ # Restart php5-fpm at the first start (it needs to be restarted after the slapd start)
|
|
|
+ if [ ! -e /tmp/.ynh-torclient-boot ]; then
|
|
|
+ touch /tmp/.ynh-torclient-boot
|
|
|
+ systemctl restart php5-fpm
|
|
|
+ fi
|
|
|
|
|
|
-echo -n "Retrieving Yunohost settings... "
|
|
|
+ ynh_wifi_device_id=$(moulinette_get wifi_device_id)
|
|
|
|
|
|
-ynh_service_enabled=$(moulinette_get service_enabled)
|
|
|
-ynh_wifi_device_id=$(moulinette_get wifi_device_id)
|
|
|
+ if [[ ! "${1}" =~ stop ]]; then
|
|
|
+ exitcode=0
|
|
|
|
|
|
-if [ "${ynh_wifi_device_id}" -eq 0 ]; then
|
|
|
- ynh_wifi_device=$(moulinette_hotspot_get wifi_device)
|
|
|
-else
|
|
|
- ynh_wifi_device="hotspot${ynh_wifi_device_id}"
|
|
|
-fi
|
|
|
+ if [ "${ynh_wifi_device_id}" -eq -1 ]; then
|
|
|
+ echo "[WARN] You need to select an associated wifi hotspot (you can do it through the web admin)"
|
|
|
+ exitcode=1
|
|
|
+ fi
|
|
|
|
|
|
-echo OK
|
|
|
+ [ "${exitcode}" -ne 0 ] && exit ${exitcode}
|
|
|
+ fi
|
|
|
|
|
|
-IFS='|' read -a ynh_wifi_ssid <<< "$(moulinette_hotspot_get wifi_ssid)"
|
|
|
-IFS='|' read -a ynh_wifi_prefix <<< "$(moulinette_hotspot_get ip4_nat_prefix)"
|
|
|
-ynh_wifi_prefix=${ynh_wifi_prefix[$ynh_wifi_device_id]}
|
|
|
-ynh_wifi_ssid=${ynh_wifi_ssid[$ynh_wifi_device_id]}
|
|
|
+ # Variables
|
|
|
+
|
|
|
+ echo -n "Retrieving Yunohost settings... "
|
|
|
+
|
|
|
+ ynh_service_enabled=$(moulinette_get service_enabled)
|
|
|
+
|
|
|
+ if [ "${ynh_wifi_device_id}" -eq 0 ]; then
|
|
|
+ ynh_wifi_device=$(moulinette_hotspot_get wifi_device)
|
|
|
+ else
|
|
|
+ ynh_wifi_device="hotspot${ynh_wifi_device_id}"
|
|
|
+ fi
|
|
|
|
|
|
-#echo "Torclient will be active on $ynh_wifi_device device and $ynh_wifi_ssid SSID with $ynh_wifi_prefix prefix"
|
|
|
+ echo OK
|
|
|
+
|
|
|
+ IFS='|' read -a ynh_wifi_ssid <<< "$(moulinette_hotspot_get wifi_ssid)"
|
|
|
+ IFS='|' read -a ynh_wifi_prefix <<< "$(moulinette_hotspot_get ip4_nat_prefix)"
|
|
|
+ ynh_wifi_prefix=${ynh_wifi_prefix[$ynh_wifi_device_id]}
|
|
|
+ ynh_wifi_ssid=${ynh_wifi_ssid[$ynh_wifi_device_id]}
|
|
|
+fi
|
|
|
|
|
|
case "$1" in
|
|
|
start)
|