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