mirror of
https://github.com/YunoHost-Apps/hotspot_ynh.git
synced 2024-09-03 19:25:53 +02:00
systemd: migrate the SySv init script to a simple bash script
This commit is contained in:
parent
b986073e20
commit
78b5bb43f4
2 changed files with 23 additions and 31 deletions
|
@ -1,28 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
### BEGIN INIT INFO
|
#
|
||||||
# Provides: ynh-hotspot
|
# Wifi Hotspot app for YunoHost
|
||||||
# Required-Start: $network $remote_fs $syslog yunohost-api
|
|
||||||
# Required-Stop: $network $remote_fs $syslog
|
|
||||||
# Default-Start: 2 3 4 5
|
|
||||||
# Default-Stop: 0 1 6
|
|
||||||
# Short-Description: Set prerequisites for wifi hotspot.
|
|
||||||
# Description: Set prerequisites for wifi hotspot.
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
# Wifi Hotspot app for YunoHost
|
|
||||||
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
||||||
# Contribute at https://github.com/jvaubourg/hotspot_ynh
|
# Contribute at https://github.com/jvaubourg/hotspot_ynh
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# 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
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU Affero General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
@ -201,7 +192,7 @@ start_hostapd() {
|
||||||
sed "s|<TPL:WIFI_INTERFACE>|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp
|
sed "s|<TPL:WIFI_INTERFACE>|hotspot${i}|g" -i /etc/hostapd/hostapd.conf.tmp
|
||||||
sed "s|<TPL:WIFI_SSID>|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
|
sed "s|<TPL:WIFI_SSID>|${ynh_wifi_ssid[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
|
||||||
sed "s|<TPL:WIFI_PASSPHRASE>|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
|
sed "s|<TPL:WIFI_PASSPHRASE>|${ynh_wifi_passphrase[${i}]}|g" -i /etc/hostapd/hostapd.conf.tmp
|
||||||
|
|
||||||
if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then
|
if [ "${ynh_wifi_secure[${i}]}" -eq 1 ]; then
|
||||||
sed "s|<TPL:SEC_COMMENT>||g" -i /etc/hostapd/hostapd.conf.tmp
|
sed "s|<TPL:SEC_COMMENT>||g" -i /etc/hostapd/hostapd.conf.tmp
|
||||||
else
|
else
|
||||||
|
@ -285,7 +276,7 @@ moulinette_get() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${value}"
|
echo "${value}"
|
||||||
}
|
}
|
||||||
|
|
||||||
moulinette_vpnclient_get() {
|
moulinette_vpnclient_get() {
|
||||||
var=${1}
|
var=${1}
|
||||||
|
@ -319,11 +310,11 @@ if [ "$1" != restart ]; then
|
||||||
touch /tmp/.ynh-hotspot-boot
|
touch /tmp/.ynh-hotspot-boot
|
||||||
systemctl restart php5-fpm --quiet
|
systemctl restart php5-fpm --quiet
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
|
||||||
echo -n "Retrieving Yunohost settings... "
|
echo -n "Retrieving Yunohost settings... "
|
||||||
|
|
||||||
ynh_service_enabled=$(moulinette_get service_enabled)
|
ynh_service_enabled=$(moulinette_get service_enabled)
|
||||||
ynh_wifi_device=$(moulinette_get wifi_device)
|
ynh_wifi_device=$(moulinette_get wifi_device)
|
||||||
ynh_wifi_channel=$(moulinette_get wifi_channel)
|
ynh_wifi_channel=$(moulinette_get wifi_channel)
|
||||||
|
@ -342,23 +333,23 @@ if [ "$1" != restart ]; then
|
||||||
|
|
||||||
old_internet_device=$(moulinette_get internet_device)
|
old_internet_device=$(moulinette_get internet_device)
|
||||||
new_internet_device=$(ip route | awk '/default via/ { print $NF; }')
|
new_internet_device=$(ip route | awk '/default via/ { print $NF; }')
|
||||||
|
|
||||||
# Switch the NAT interface if there is a VPN
|
# Switch the NAT interface if there is a VPN
|
||||||
ip link show dev tun0 &> /dev/null
|
ip link show dev tun0 &> /dev/null
|
||||||
if [ "$?" -eq 0 ]; then
|
if [ "$?" -eq 0 ]; then
|
||||||
new_internet_device=tun0
|
new_internet_device=tun0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
|
||||||
# Check IPv6 delegated prefix from vpnclient
|
# Check IPv6 delegated prefix from vpnclient
|
||||||
# vpnclient_ip6_net=$(moulinette_vpnclient_get ip6_net)
|
# vpnclient_ip6_net=$(moulinette_vpnclient_get ip6_net)
|
||||||
#
|
#
|
||||||
# if [ ! -z "${vpnclient_ip6_addr}" ]; then
|
# if [ ! -z "${vpnclient_ip6_addr}" ]; then
|
||||||
# if [ "${ynh_ip6_net}" == none ]; then
|
# if [ "${ynh_ip6_net}" == none ]; then
|
||||||
# ynh_ip6_net=$vpnclient_ip6_net
|
# ynh_ip6_net=$vpnclient_ip6_net
|
||||||
# ynh_ip6_addr=$(moulinette_vpnclient_get ip6_addr)
|
# ynh_ip6_addr=$(moulinette_vpnclient_get ip6_addr)
|
||||||
#
|
#
|
||||||
# moulinette_set ip6_net "${ynh_ip6_net}"
|
# moulinette_set ip6_net "${ynh_ip6_net}"
|
||||||
# moulinette_set ip6_addr "${ynh_ip6_addr}"
|
# moulinette_set ip6_addr "${ynh_ip6_addr}"
|
||||||
# else
|
# else
|
||||||
|
@ -432,13 +423,13 @@ case "$1" in
|
||||||
echo "hotspot${i}: Set IPv4 NAT address"
|
echo "hotspot${i}: Set IPv4 NAT address"
|
||||||
set_ip4nataddr ${i}
|
set_ip4nataddr ${i}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set the ipv6 address
|
# Set the ipv6 address
|
||||||
if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then
|
if has_ip6delegatedprefix ${i} && ! is_ip6addr_set ${i}; then
|
||||||
echo "hotspot${i}: Set IPv6 address"
|
echo "hotspot${i}: Set IPv6 address"
|
||||||
set_ip6addr ${i}
|
set_ip6addr ${i}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run DHCPv6 server
|
# Run DHCPv6 server
|
||||||
if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then
|
if has_ip6delegatedprefix ${i} && ! is_dhcpd6_running ${i}; then
|
||||||
echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)"
|
echo "hotspot${i}: Start the NDP and DHCPv6 server (dnsmasq)"
|
||||||
|
@ -480,8 +471,8 @@ case "$1" in
|
||||||
if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then
|
if has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}; then
|
||||||
echo "hotspot${i}: Unset IPv6 address"
|
echo "hotspot${i}: Unset IPv6 address"
|
||||||
unset_ip6addr ${i}
|
unset_ip6addr ${i}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_dhcpd6_running ${i}; then
|
if is_dhcpd6_running ${i}; then
|
||||||
echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)"
|
echo "hotspot${i}: Stop the NDP and DHCPv6 server (dnsmasq)"
|
||||||
stop_dhcpd6 ${i}
|
stop_dhcpd6 ${i}
|
||||||
|
@ -541,7 +532,7 @@ case "$1" in
|
||||||
if has_ip6delegatedprefix ${i}; then
|
if has_ip6delegatedprefix ${i}; then
|
||||||
echo "[INFO] hotspot${i}: IPv6 delegated prefix found"
|
echo "[INFO] hotspot${i}: IPv6 delegated prefix found"
|
||||||
echo "[INFO] hotspot${i}: IPv6 address computed from the delegated prefix: ${ynh_ip6_addr}"
|
echo "[INFO] hotspot${i}: IPv6 address computed from the delegated prefix: ${ynh_ip6_addr}"
|
||||||
|
|
||||||
if is_ip6addr_set ${i}; then
|
if is_ip6addr_set ${i}; then
|
||||||
echo "[OK] hotspot${i}: IPv6 address set"
|
echo "[OK] hotspot${i}: IPv6 address set"
|
||||||
else
|
else
|
||||||
|
@ -558,14 +549,14 @@ case "$1" in
|
||||||
else
|
else
|
||||||
echo "[INFO] hotspot${i}: No IPv6 delegated prefix found"
|
echo "[INFO] hotspot${i}: No IPv6 delegated prefix found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_dhcpd4_running ${i}; then
|
if is_dhcpd4_running ${i}; then
|
||||||
echo "[OK] hotspot${i}: DHCPv4 server (dnsmasq) is running"
|
echo "[OK] hotspot${i}: DHCPv4 server (dnsmasq) is running"
|
||||||
else
|
else
|
||||||
echo "[ERR] hotspot${i}: NDP and DHCPv4 (dnsmasq) is not running"
|
echo "[ERR] hotspot${i}: NDP and DHCPv4 (dnsmasq) is not running"
|
||||||
exitcode=1
|
exitcode=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_ip4nataddr_set ${i}; then
|
if is_ip4nataddr_set ${i}; then
|
||||||
echo "[OK] hotspot${i}: IPv4 NAT address set"
|
echo "[OK] hotspot${i}: IPv4 NAT address set"
|
||||||
else
|
else
|
|
@ -152,6 +152,7 @@ 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/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_expanded /usr/local/bin/
|
||||||
sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
|
sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
|
||||||
|
sudo install -o root -g root -m 0755 ../conf/ynh-hotspot /usr/local/bin/
|
||||||
|
|
||||||
# Copy confs
|
# Copy confs
|
||||||
sudo mkdir -pm 0755 /var/log/nginx/
|
sudo mkdir -pm 0755 /var/log/nginx/
|
||||||
|
|
Loading…
Add table
Reference in a new issue