diff --git a/scripts/helpers b/scripts/helpers new file mode 100644 index 0000000..f91730f --- /dev/null +++ b/scripts/helpers @@ -0,0 +1,39 @@ +#!/bin/bash + +source /usr/share/yunohost/helpers + +# +# Helper to start/stop/.. a systemd service from a yunohost context, +# *and* the systemd service itself needs to be able to run yunohost +# commands. +# +# Hence the need to release the lock during the operation +# +# usage : ynh_systemctl yolo restart +# +function ynh_systemctl() +{ + local ACTION="$1" + local SERVICE="$2" + local LOCKFILE="/var/run/moulinette_yunohost.lock" + + # Launch the action + sudo systemctl "$ACTION" "$SERVICE" & + local SYSCTLACTION=$! + + # Save and release the lock... + cp $LOCKFILE $LOCKFILE.bkp.$$ + rm $LOCKFILE + + # Wait for the end of the action + wait $SYSCTLACTION + + # Make sure the lock is released... + while [ -f $LOCKFILE ] + do + sleep 0.1 + done + + # Restore the old lock + mv $LOCKFILE.bkp.$$ $LOCKFILE +} diff --git a/scripts/install b/scripts/install index d5082d3..3d8e28a 100644 --- a/scripts/install +++ b/scripts/install @@ -29,6 +29,7 @@ firmware_nonfree=${5} if ! $upgrade; then + source ./helpers source ./prerequisites # Check arguments @@ -52,10 +53,7 @@ if ! $upgrade; then fi # Check domain/path availability -sudo yunohost app checkurl ${domain}${url_path} -a hotspot -if [ ! $? -eq 0 ]; then - exit 1 -fi +ynh_webpath_register hotspot $domain $url_path || exit 1 # Install packages packages='php5-fpm sipcalc hostapd iptables iw dnsmasq' @@ -211,7 +209,7 @@ if [ "${wifi_device}" == none ]; then fi if ! $upgrade; then - sudo systemctl start ynh-hotspot + ynh_systemctl start ynh-hotspot fi sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index bd5ffd8..9d7681d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,11 +17,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +source ./helpers + # Retrieve arguments domain=$(sudo yunohost app setting hotspot domain) # The End -sudo systemctl stop ynh-hotspot +ynh_systemctl stop ynh-hotspot sudo systemctl disable ynh-hotspot sudo yunohost service remove ynh-hotspot sudo rm -f /etc/systemd/system/ynh-hotspot.service /usr/local/bin/ynh-hotspot diff --git a/scripts/upgrade b/scripts/upgrade index 2f6aa8f..5174922 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,6 +12,7 @@ path=$(ynh_setting hotspot path) wifi_ssid=$(ynh_setting hotspot wifi_ssid) wifi_passphrase=$(ynh_setting hotspot wifi_passphrase) +source ./helpers source ./prerequisites if dpkg -l firmware-linux-nonfree &> /dev/null; then @@ -40,6 +41,6 @@ if [ -z "$(ynh_setting hotspot ip6_firewall)" ]; then sudo yunohost app setting hotspot ip6_firewall -v "${ip6_firewall}" fi -sudo systemctl start ynh-hotspot +ynh_systemctl start ynh-hotspot exit 0