1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

Apply 'shfmt -bn -i 4 -w' on ynh-hotspot

This commit is contained in:
Alexandre Aubin 2021-11-16 00:20:13 +01:00
parent 3100538cbc
commit 7da1dc5461

View file

@ -46,14 +46,14 @@ is_ip4nataddr_set() {
local i=${1} local i=${1}
dev=$(devfromid "${i}") dev=$(devfromid "${i}")
ip address show dev "${dev}" 2> /dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24" ip address show dev "${dev}" 2>/dev/null | grep -q "${ip4_nat_prefix[${i}]}.1/24"
} }
is_ip6addr_set() { is_ip6addr_set() {
local i=${1} local i=${1}
dev=$(devfromid "${i}") dev=$(devfromid "${i}")
ip address show dev "${dev}" 2> /dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64" ip address show dev "${dev}" 2>/dev/null | grep -q "$(ip6addrfromdelegatedprefix $i)/64"
} }
is_ip6firewall_set() { is_ip6firewall_set() {
@ -83,14 +83,14 @@ is_dhcpd4_running() {
} }
is_hostapd_running() { is_hostapd_running() {
systemctl is-active hostapd &> /dev/null systemctl is-active hostapd &>/dev/null
} }
is_running() { is_running() {
for i in $(seq 0 $((${multissid} - 1))); do for i in $(seq 0 $((${multissid} - 1))); do
( has_ip6delegatedprefix ${i} && is_ip6addr_set ${i}\ (has_ip6delegatedprefix ${i} && is_ip6addr_set ${i} \
&& ( [ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i} || [ "${ip6_firewall[${i}]}" -eq 0 ] )\ && ([ "${ip6_firewall[${i}]}" -eq 1 ] && is_ip6firewall_set ${i} || [ "${ip6_firewall[${i}]}" -eq 0 ]) \
&& is_dhcpd6_running ${i} || ! has_ip6delegatedprefix ${i} )\ && is_dhcpd6_running ${i} || ! has_ip6delegatedprefix ${i}) \
&& is_ip4nataddr_set ${i} && is_dhcpd4_running ${i} && is_ip4nataddr_set ${i} && is_dhcpd4_running ${i}
if [ ! $? -eq 0 ]; then if [ ! $? -eq 0 ]; then
@ -98,7 +98,7 @@ is_running() {
fi fi
done done
is_hostapd_running && is_forwarding_set && ( [ -z "${new_gateway_interface}" ] || is_nat_set "${new_gateway_interface}" ) is_hostapd_running && is_forwarding_set && ([ -z "${new_gateway_interface}" ] || is_nat_set "${new_gateway_interface}")
} }
## Setters ## Setters
@ -120,7 +120,7 @@ set_ip6addr() {
local i=${1} local i=${1}
local dev=$(devfromid "${i}") local dev=$(devfromid "${i}")
ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &> /dev/null ip address delete "$(ip6addrfromdelegatedprefix $i)/64" dev tun0 &>/dev/null
ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}" ip address add "$(ip6addrfromdelegatedprefix $i)/64" dev "${dev}"
} }
@ -134,8 +134,8 @@ set_ip6firewall() {
} }
set_forwarding() { set_forwarding() {
sysctl -w net.ipv6.conf.all.forwarding=1 > /dev/null sysctl -w net.ipv6.conf.all.forwarding=1 >/dev/null
sysctl -w net.ipv4.conf.all.forwarding=1 > /dev/null sysctl -w net.ipv4.conf.all.forwarding=1 >/dev/null
} }
start_dhcpd6() { start_dhcpd6() {
@ -187,7 +187,7 @@ configure_hostapd() {
sed "s|__SEC_COMMENT__|${sec_comment}|g" -i /etc/hostapd/hostapd.conf.tmp sed "s|__SEC_COMMENT__|${sec_comment}|g" -i /etc/hostapd/hostapd.conf.tmp
sed "s|__BSS_COMMENT__|${bss_comment}|g" -i /etc/hostapd/hostapd.conf.tmp sed "s|__BSS_COMMENT__|${bss_comment}|g" -i /etc/hostapd/hostapd.conf.tmp
cat /etc/hostapd/hostapd.conf.tmp >> /etc/hostapd/hostapd.conf cat /etc/hostapd/hostapd.conf.tmp >>/etc/hostapd/hostapd.conf
rm /etc/hostapd/hostapd.conf.tmp rm /etc/hostapd/hostapd.conf.tmp
done done
} }
@ -224,8 +224,8 @@ unset_ip6firewall() {
} }
unset_forwarding() { unset_forwarding() {
sysctl -w net.ipv6.conf.all.forwarding=0 > /dev/null sysctl -w net.ipv6.conf.all.forwarding=0 >/dev/null
sysctl -w net.ipv4.conf.all.forwarding=0 > /dev/null sysctl -w net.ipv4.conf.all.forwarding=0 >/dev/null
} }
stop_dhcpd6() { stop_dhcpd6() {
@ -303,19 +303,18 @@ if [ "$1" != restart ]; then
wifi_channel=$(ynh_setting_get hotspot wifi_channel) wifi_channel=$(ynh_setting_get hotspot wifi_channel)
multissid=$(ynh_setting_get hotspot multissid) multissid=$(ynh_setting_get hotspot multissid)
IFS='|' read -a wifi_ssid <<< "$(ynh_setting_get hotspot wifi_ssid)" IFS='|' read -a wifi_ssid <<<"$(ynh_setting_get hotspot wifi_ssid)"
IFS='|' read -a wifi_secure <<< "$(ynh_setting_get hotspot wifi_secure)" IFS='|' read -a wifi_secure <<<"$(ynh_setting_get hotspot wifi_secure)"
IFS='|' read -a wifi_passphrase <<< "$(ynh_setting_get hotspot wifi_passphrase)" IFS='|' read -a wifi_passphrase <<<"$(ynh_setting_get hotspot wifi_passphrase)"
IFS='|' read -a ip6_firewall <<< "$(ynh_setting_get hotspot ip6_firewall)" IFS='|' read -a ip6_firewall <<<"$(ynh_setting_get hotspot ip6_firewall)"
IFS='|' read -a ip6_net <<< "$(ynh_setting_get hotspot ip6_net)" IFS='|' read -a ip6_net <<<"$(ynh_setting_get hotspot ip6_net)"
IFS='|' read -a dns <<< "$(ynh_setting_get hotspot dns)" IFS='|' read -a dns <<<"$(ynh_setting_get hotspot dns)"
IFS='|' read -a ip4_nat_prefix <<< "$(ynh_setting_get hotspot ip4_nat_prefix)" IFS='|' read -a ip4_nat_prefix <<<"$(ynh_setting_get hotspot ip4_nat_prefix)"
for i in $(seq 0 $((${multissid} - 1))); do for i in $(seq 0 $((${multissid} - 1))); do
ip6_dns[${i}]="" ip6_dns[${i}]=""
ip4_dns[${i}]="" ip4_dns[${i}]=""
for ip in $(echo "${dns[${i}]}" | tr ',' ' '); do for ip in $(echo "${dns[${i}]}" | tr ',' ' '); do
if [[ "$ip" == *":"* ]] if [[ "$ip" == *":"* ]]; then
then
ip6_dns[${i}]+="[$ip]," ip6_dns[${i}]+="[$ip],"
else else
ip4_dns[${i}]+="$ip," ip4_dns[${i}]+="$ip,"
@ -330,7 +329,7 @@ if [ "$1" != restart ]; then
new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }')
# 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_gateway_interface=tun0 new_gateway_interface=tun0
fi fi
@ -341,7 +340,7 @@ fi
# Script # Script
case "$1" in case "$1" in
start) start)
if is_running; then if is_running; then
echo "Already started" echo "Already started"
exit 0 exit 0
@ -359,8 +358,7 @@ case "$1" in
touch /tmp/.ynh-hotspot-started touch /tmp/.ynh-hotspot-started
# Check old state of the ipv4 NAT settings # Check old state of the ipv4 NAT settings
if [ ! -z "${old_gateway_interface}" -a "${new_gateway_interface}" != "${old_gateway_interface}" ]\ if [ ! -z "${old_gateway_interface}" -a "${new_gateway_interface}" != "${old_gateway_interface}" ] && is_nat_set "${old_gateway_interface}"; then
&& is_nat_set "${old_gateway_interface}"; then
unset_nat "${old_gateway_interface}" unset_nat "${old_gateway_interface}"
fi fi
@ -383,18 +381,17 @@ case "$1" in
configure_hostapd configure_hostapd
echo "Starting hostapd..." echo "Starting hostapd..."
if ! systemctl start hostapd if ! systemctl start hostapd; then
journalctl -u hostapd -n 100 --no-hostname --no-pager journalctl -u hostapd -n 100 --no-hostname --no-pager
exit 1 exit 1
fi fi
sleep 1 sleep 1
i=0; i=0
while ! ip link show dev hotspot1 &> /dev/null; do while ! ip link show dev hotspot1 &>/dev/null; do
sleep 1 sleep 1
if [ ${i} -gt 20 ] if [ ${i} -gt 20 ]; then
then
echo "Failed to see hotspot interface showing up in 'ip a'" echo "Failed to see hotspot interface showing up in 'ip a'"
stop_hostapd stop_hostapd
exit 1 exit 1
@ -441,7 +438,7 @@ case "$1" in
# Update dynamic settings # Update dynamic settings
ynh_setting_set hotspot gateway_interface "${new_gateway_interface}" ynh_setting_set hotspot gateway_interface "${new_gateway_interface}"
;; ;;
stop) stop)
echo "[hotspot] Stopping..." echo "[hotspot] Stopping..."
rm -f /tmp/.ynh-hotspot-started rm -f /tmp/.ynh-hotspot-started
@ -492,11 +489,11 @@ case "$1" in
ynh-vpnclient start ynh-vpnclient start
fi fi
;; ;;
restart) restart)
$0 stop $0 stop
$0 start $0 start
;; ;;
status) status)
exitcode=0 exitcode=0
if [ "${service_enabled}" != "enabled" ]; then if [ "${service_enabled}" != "enabled" ]; then
@ -586,7 +583,7 @@ case "$1" in
exit ${exitcode} exit ${exitcode}
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart|status}" echo "Usage: $0 {start|stop|restart|status}"
exit 1 exit 1
;; ;;