Browse Source

using new helpers and script formatting

master
Keoma Brun 3 years ago
parent
commit
7cbd23c1ec
8 changed files with 313 additions and 174 deletions
  1. +17
    -3
      manifest.json
  2. +9
    -3
      scripts/_common.sh
  3. +15
    -1
      scripts/backup
  4. +175
    -106
      scripts/install
  5. +4
    -12
      scripts/prerequisites
  6. +37
    -18
      scripts/remove
  7. +19
    -3
      scripts/restore
  8. +37
    -28
      scripts/upgrade

+ 17
- 3
manifest.json View File

@@ -1,21 +1,32 @@
{
"name": "Wifi Hotspot",
"id": "hotspot",
"packaging_format": 1,
"description": {
"en": "Wifi Hotspot",
"fr": "Hotspot Wifi"
},
"license": "AGPL-3",
"developer": {
"url": "https://github.com/labriqueinternet/hotspot_ynh",
"version": "1.1.0",
"license": "AGPL-3.0",
"maintainer": {
"name": "Julien Vaubourg",
"email": "julien@vaubourg.com",
"url": "http://julien.vaubourg.com"
},
"multi_instance": "false",
"requirements": {
"yunohost": ">= 2.2.0",
"moulinette": ">= 2.4.0"
},
"multi_instance": false,
"services": [
"php5-fpm"
],
"arguments": {
"install" : [
{
"name": "domain",
"type": "domain",
"ask": {
"en": "Choose a domain for the web administration",
"fr": "Choisissez un domaine pour l'administration web"
@@ -24,6 +35,7 @@
},
{
"name": "path",
"type": "path",
"ask": {
"en": "Choose a path for the web administration",
"fr": "Choisissez un chemin pour l'administration web"
@@ -42,6 +54,7 @@
},
{
"name": "wifi_passphrase",
"type": "password",
"ask": {
"en": "Choose a wifi password (at least 8 characters for WPA2)",
"fr": "Choisissez un mot de passe wifi (au minimum 8 caractères pour le WPA2)"
@@ -50,6 +63,7 @@
},
{
"name": "firmware_nonfree",
"choice": ["yes", "no"],
"ask": {
"en": "Install non-free firmwares - in addition to the free ones - for the wifi dongle (yes/no)",
"fr": "Installer des firmwares non-libres (en plus des libres) pour la clé USB wifi (yes/no)"


scripts/helpers → scripts/_common.sh View File

@@ -1,12 +1,18 @@
#!/bin/bash

source /usr/share/yunohost/helpers
#
# Common variables
#

pkg_dependencies="php5-fpm sipcalc hostapd iptables iw dnsmasq"
nonfree_packages="firmware-linux-free firmware-linux-nonfree firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware zd1211-firmware"
free_packages="firmware-linux-free"

#
# 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
@@ -24,7 +30,7 @@ function ynh_systemctl()
# Save and release the lock...
cp $LOCKFILE $LOCKFILE.bkp.$$
rm $LOCKFILE
# Wait for the end of the action
wait $SYSCTLACTION


+ 15
- 1
scripts/backup View File

@@ -2,4 +2,18 @@

# nothing to do...

exit 0
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

+ 175
- 106
scripts/install View File

@@ -1,75 +1,130 @@
#!/bin/bash

# Wifi Hotspot app for YunoHost
# Wifi Hotspot app for YunoHost
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
# Contribute at https://github.com/labriqueinternet/hotspot_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/>.

# This is an upgrade?
upgrade=$([ "${HOTSPOT_UPGRADE}" == 1 ] && echo true || echo false)
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

# Retrieve arguments
domain=${1}
url_path=${2}
wifi_ssid=${3}
wifi_passphrase=${4}
firmware_nonfree=${5}
source _common.sh
source /usr/share/yunohost/helpers

if ! $upgrade; then
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

source ./helpers
source ./prerequisites
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

# Check arguments
if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then
echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2
exit 1
fi
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then
echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2
exit 1
fi
echo "${wifi_passphrase}" | grep -qP '[^[:print:]]'
if [ $? -eq 0 ]; then
echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2
exit 1
fi
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================

# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
wifi_ssid=$YNH_APP_ARG_WIFI_SSID
wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE
firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE

app=$YNH_APP_INSTANCE_NAME

#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================

# Check destination directory
final_path="/var/www/$app"
test ! -e "$final_path" || ynh_die "This path already contains a folder"

# Normalize the url path syntax
path_url=$(ynh_normalize_url_path "$path_url")

# Check web path availability
ynh_webpath_available "$domain" "$path_url"
# Register (book) web path
ynh_webpath_register "$app" "$domain" "$path_url"

#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================

ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" final_path "$final_path"
ynh_app_setting_set "$app" wifi_ssid "$wifi_ssid"
ynh_app_setting_set "$app" wifi_passphrase "$wifi_passphrase"
ynh_app_setting_set "$app" firmware_nonfree "$firmware_nonfree"

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================

ynh_install_app_dependencies "$pkg_dependencies"

#=================================================
# SPECIFIC SETUP
#=================================================
# RUN PREREQUISITES
#=================================================

source ./prerequisites

#=================================================
# CHECK PARAMETERS
#=================================================

# Check arguments
if [[ -z $wifi_ssid || -z $wifi_passphrase ]]; then
ynh_die "Your Wifi Hotspot needs a name and a password"
fi

# Check passphrase length
wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
if [[ $wifi_passphrase_length -lt 8 || $wifi_passphrase_length -gt 63 ]]; then
ynh_die "Your password must from 8 to 63 characters (WPA2 passphrase)"
fi

# Check no special characters are present in the passphrase
if [[ $wifi_passphrase =~ [^[:print:]] ]]; then
ynh_die "Only printable ASCII characters are permitted in your password (WPA2 passphrase)"
fi
# Check domain/path availability
ynh_webpath_register hotspot $domain $url_path || exit 1

# Install packages
packages='php5-fpm sipcalc hostapd iptables iw dnsmasq'
#=================================================
# INSTALL NONFREE FIRWARE IF REQUESTED
#=================================================

export DEBIAN_FRONTEND=noninteractive

# Packaged USB Wireless Device firmwares
# Based on https://wiki.debian.org/WiFi#USB_Devices
if [ "${firmware_nonfree}" == yes ]; then
if [[ $firmware_nonfree == yes ]]; then
# check if non-free is set on sources.list
if ! grep -q non-free /etc/apt/sources.list ; then
sudo sed '/debian/{s/main/& non-free/}' -i /etc/apt/sources.list
fi

packages="$packages firmware-linux-free firmware-linux-nonfree firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware zd1211-firmware"
packages=$nonfree_packages
else
packages="$packages firmware-linux-free"
packages=$free_packages

# Extract from http://packages.trisquel.info/toutatis-updates/open-ath9k-htc-firmware
# https://www.fsf.org/news/ryf-certification-thinkpenguin-usb-with-atheros-chip
@@ -80,66 +135,76 @@ fi

sudo apt-get --assume-yes --force-yes install ${packages}

if [ $? -ne 0 ]; then
if [[ $? -ne 0 ]]; then
sudo apt-get update
sudo apt-get --assume-yes --force-yes install ${packages}
fi

if ! $upgrade; then
# Compute extra arguments
if [ -z "${ip6_net}" ]; then
ip6_net=none
ip6_addr=none
if [ -e /tmp/.ynh-vpnclient-started ]; then
vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1)
vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1)
if [[ "${vpnclient_ip6_net}" =~ :: && "${vpnclient_ip6_addr}" =~ :: ]]; then
ip6_net=${vpnclient_ip6_net}
ip6_addr=${vpnclient_ip6_addr}
fi
#=================================================
# CHECK PARAMETERS
#=================================================
if [[ ! -v ip6_net ]]; then # if ip6_net not set
ip6_net=none
ip6_addr=none
if [[ -e /tmp/.ynh-vpnclient-started ]]; then
vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1)
vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1)
if [[ $vpnclient_ip6_net =~ :: && $vpnclient_ip6_addr =~ :: ]]; then
ip6_net=${vpnclient_ip6_net}
ip6_addr=${vpnclient_ip6_addr}
fi
fi
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')
# Save arguments

if [ -z "${wifi_device}" ]; then
sudo yunohost app setting hotspot service_enabled -v 0
wifi_device=none
else
sudo yunohost app setting hotspot service_enabled -v 1
fi
fi

sudo yunohost app setting hotspot multissid -v 1
sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}"
sudo yunohost app setting hotspot wifi_secure -v 1
sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}"
sudo yunohost app setting hotspot wifi_device -v "${wifi_device}"
sudo yunohost app setting hotspot wifi_channel -v 6
sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}"
sudo yunohost app setting hotspot ip6_firewall -v 1
sudo yunohost app setting hotspot ip6_net -v "${ip6_net}"
sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8
sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12
sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188
sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12
sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242
sudo yunohost app setting hotspot vpnclient -v no
wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }')

# Save arguments

if [[ -z $wifi_device ]]; then
ynh_app_setting_set $app service_enabled -v 0
wifi_device=none
else
ynh_app_setting_set $app service_enabled -v 1
fi

# Install custom scripts
#=================================================
# SAVE SETTINGS
#=================================================

ynh_app_setting_set $app multissid -v 1
ynh_app_setting_set $app wifi_ssid -v "${wifi_ssid}"
ynh_app_setting_set $app wifi_secure -v 1
ynh_app_setting_set $app wifi_passphrase -v "${wifi_passphrase}"
ynh_app_setting_set $app wifi_device -v "${wifi_device}"
ynh_app_setting_set $app wifi_channel -v 6
ynh_app_setting_set $app ip6_addr -v "${ip6_addr}"
ynh_app_setting_set $app ip6_firewall -v 1
ynh_app_setting_set $app ip6_net -v "${ip6_net}"
ynh_app_setting_set $app ip6_dns0 -v 2001:913::8
ynh_app_setting_set $app ip6_dns1 -v 2001:910:800::12
ynh_app_setting_set $app ip4_dns0 -v 80.67.188.188
ynh_app_setting_set $app ip4_dns1 -v 80.67.169.12
ynh_app_setting_set $app ip4_nat_prefix -v 10.0.242
ynh_app_setting_set $app vpnclient -v no


#=================================================
# INSTALL CUSTOM SCRIPTS
#=================================================

sudo install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/

# Copy confs
#=================================================
# COPY CONFIGS
#=================================================

sudo mkdir -pm 0755 /var/log/nginx/
sudo mkdir -pm 0755 /etc/dnsmasq.dhcpd/
sudo chown root: /etc/dnsmasq.dhcpd/
@@ -150,7 +215,10 @@ sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dn
sudo install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
sudo install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf

# Copy web sources
#=================================================
# COPY WEB SOURCES
#=================================================

sudo mkdir -pm 0755 /var/www/wifiadmin/
sudo cp -a ../sources/* /var/www/wifiadmin/

@@ -158,12 +226,15 @@ sudo chown -R root: /var/www/wifiadmin/
sudo chmod -R 0644 /var/www/wifiadmin/*
sudo find /var/www/wifiadmin/ -type d -exec chmod +x {} \;

# Fix confs
#=================================================
# FIX CONFIGS
#=================================================

## hostapd
sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd

## nginx
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
sudo sed "s|<TPL:NGINX_LOCATION>|${path_url}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"
sudo sed 's|<TPL:PHP_NAME>|wifiadmin|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf"

@@ -174,44 +245,42 @@ sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf
sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf

# Fix sources
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/wifiadmin/config.php
sudo sed "s|<TPL:NGINX_LOCATION>|${path_url}|g" -i /var/www/wifiadmin/config.php

# Copy init script
sudo install -o root -g root -m 0755 ../conf/ynh-hotspot /usr/local/bin/
sudo install -o root -g root -m 0644 ../conf/ynh-hotspot.service /etc/systemd/system/

# Update firewall for DHCP
sudo yunohost firewall allow --no-upnp --ipv6 UDP 547
sudo yunohost firewall allow --no-upnp UDP 67
yunohost firewall allow --no-upnp --ipv6 UDP 547
yunohost firewall allow --no-upnp UDP 67

# Set default inits
# The boot order of these services are important, so they are disabled by default
# and the ynh-hotspot service handles them.
sudo systemctl disable hostapd
sudo systemctl stop hostapd
sudo systemctl enable php5-fpm
sudo systemctl restart php5-fpm
sudo systemctl reload nginx
systemctl disable hostapd
systemctl stop hostapd
systemctl enable php5-fpm
systemctl restart php5-fpm
systemctl reload nginx

# Remove IPv6 address set if there is a VPN installed
if [ "${ip6_addr}" != none ]; then
if [[ $ip6_addr != none ]]; then
sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"
if [ "$?" -eq 0 ]; then
if [[ "$?" -eq 0 ]]; then
sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
fi
fi

sudo systemctl enable ynh-hotspot
sudo yunohost service add ynh-hotspot
systemctl enable ynh-hotspot
yunohost service add ynh-hotspot

if [ "${wifi_device}" == none ]; then
if [[ $wifi_device == none ]]; then
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
fi

if ! $upgrade; then
ynh_systemctl start ynh-hotspot
fi

sudo yunohost app ssowatconf
# start the app
ynh_systemctl start ynh-hotspot

exit 0
# Reload SSOwat config
yunohost app ssowatconf

+ 4
- 12
scripts/prerequisites View File

@@ -1,16 +1,8 @@
# Source me

# Check YunoHost version (dnsmasq)
ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g')
# Check if dnsmasq is active
systemctl is-active dnsmasq &> /dev/null

if [ "${ynh_version}" -lt 220 ]; then
echo "ERROR: You need a YunoHost version equals or greater than 2.2.0" >&2
exit 1
fi

sudo systemctl is-active dnsmasq &> /dev/null

if [ $? -ne 0 ]; then
echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)" >&2
exit 1
if [[ $? -ne 0 ]]; then
ynh_die "You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
fi

+ 37
- 18
scripts/remove View File

@@ -1,31 +1,44 @@
#!/bin/bash

# Wifi Hotspot app for YunoHost
# Wifi Hotspot app for YunoHost
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
# Contribute at https://github.com/labriqueinternet/hotspot_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/>.

source ./helpers
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

# Retrieve arguments
domain=$(sudo yunohost app setting hotspot domain)
source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# LOAD SETTINGS
#=================================================

app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get $app domain)
firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)

# The End
ynh_systemctl stop ynh-hotspot
sudo systemctl disable ynh-hotspot
sudo yunohost service remove ynh-hotspot
systemctl stop ynh-hotspot
systemctl disable ynh-hotspot
yunohost service remove ynh-hotspot
sudo rm -f /etc/systemd/system/ynh-hotspot.service /usr/local/bin/ynh-hotspot
sudo rm -f /tmp/.ynh-hotspot-*

@@ -39,17 +52,23 @@ sudo rm -f /etc/hostapd/hostapd.conf{.tpl?,}
sudo rm -f /etc/nginx/conf.d/${domain}.d/wifiadmin.conf
sudo rm -f /etc/php5/fpm/pool.d/wifiadmin.conf

# Remove free firmwares
if ! dpkg -l firmware-atheros &> /dev/null; then
sudo rm -f /lib/firmware/htc_7010.fw
sudo rm -f /lib/firmware/htc_9271.fw
# Remove packages
if [[ $firmware_nonfree == yes ]]; then
packages=$nonfree_packages
else
packages=$free_packages

# Remove free firmwares
if ! dpkg -l firmware-atheros &> /dev/null; then
sudo rm -f /lib/firmware/htc_7010.fw
sudo rm -f /lib/firmware/htc_9271.fw
fi
fi
sudo apt-get --assume-yes --force-yes remove ${packages}

# Restart services
sudo systemctl restart php5-fpm
sudo systemctl reload nginx
systemctl restart php5-fpm
systemctl reload nginx

# Remove sources
sudo rm -rf /var/www/wifiadmin/

exit 0

+ 19
- 3
scripts/restore View File

@@ -1,5 +1,23 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

#=================================================

gitcommit=$(sudo grep revision /etc/yunohost/apps/hotspot/status.json | sed 's/.*"revision": "\([^"]\+\)".*/\1/')
tmpdir=$(mktemp -dp /tmp/ hotspot-restore-XXXXX)

@@ -7,8 +25,6 @@ git clone https://github.com/labriqueinternet/hotspot_ynh.git "${tmpdir}/"
git --work-tree "${tmpdir}/" --git-dir "${tmpdir}/.git/" reset --hard "${gitcommit}"

cd "${tmpdir}/scripts/"
bash ./upgrade
bash ./upgrade

sudo rm -r "${tmpdir}/"

exit 0

+ 37
- 28
scripts/upgrade View File

@@ -1,46 +1,55 @@
#!/bin/bash

ynh_setting() {
app=${1}
setting=${2}
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$//
}
source _common.sh
source /usr/share/yunohost/helpers

domain=$(ynh_setting hotspot domain)
path=$(ynh_setting hotspot path)
wifi_ssid=$(ynh_setting hotspot wifi_ssid)
wifi_passphrase=$(ynh_setting hotspot wifi_passphrase)
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================

source ./helpers
source ./prerequisites
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors

if dpkg -l firmware-linux-nonfree &> /dev/null; then
firmware_nonfree=yes
else
firmware_nonfree=no
fi
#=================================================
# LOAD SETTINGS
#=================================================

app=$YNH_APP_INSTANCE_NAME

domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
wifi_ssid=$(ynh_app_setting_get $app wifi_ssid)
wifi_passphrase=$(ynh_app_setting_get $app wifi_passphrase)
firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)
final_path=$(ynh_app_setting_get $app final_path)
multissid=$(ynh_app_setting_get $app multissid)

tmpdir=$(mktemp -dp /tmp/ hotspot-upgrade-XXXXX)
sudo cp -a /etc/yunohost/apps/hotspot/settings.yml "${tmpdir}/"
#=================================================
# CHECK THE PATH
#=================================================

export HOTSPOT_UPGRADE=1
sudo bash /etc/yunohost/apps/hotspot/scripts/remove &> /dev/null
bash ./install "${domain}" "${path}" "${wifi_ssid}" "${wifi_passphrase}" "${firmware_nonfree}"
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)

sudo cp -a "${tmpdir}/settings.yml" /etc/yunohost/apps/hotspot/
sudo rm -r "${tmpdir}/"
#=================================================
# SPECIFIC UPGRADE
#=================================================

source ./prerequisites

# Changes

if [ -z "$(ynh_setting hotspot ip6_firewall)" ]; then
multissid=$(ynh_setting hotspot multissid)
if [[ -z $(ynh_app_setting_get $app ip6_firewall) ]]; then
ip6_firewall=$(printf '1|%.0s' $(seq "${multissid}"))
ip6_firewall=$(echo "${ip6_firewall%?}")

sudo yunohost app setting hotspot ip6_firewall -v "${ip6_firewall}"
ynh_app_setting_set "${app}" ip6_firewall -v "${ip6_firewall}"
fi

ynh_systemctl start ynh-hotspot

exit 0

Loading…
Cancel
Save