From 6a08924dd19d4370bfe54d9d9a44c17487e9f2e1 Mon Sep 17 00:00:00 2001 From: Federico Frigo Date: Tue, 19 Oct 2021 20:23:19 +0200 Subject: [PATCH] servicestart.sh fixes --- installers/servicestart.sh | 57 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/installers/servicestart.sh b/installers/servicestart.sh index c4bc1eb3..0c3cc557 100755 --- a/installers/servicestart.sh +++ b/installers/servicestart.sh @@ -33,6 +33,35 @@ while [[ $# -gt 0 ]]; do done set -- "${positional[@]}" +HOSTAPD_CONF="/etc/hostapd/hostapd.conf" + +new_country_code=$(curl -s -H "Authorization: Bearer 9da1eb466ed052" https://ipinfo.io/json | jq -r ".country // empty") +old_country_code=$(grep ^country_code $HOSTAPD_CONF | cut -d "=" -f 2) + +if [[ ! -z "$new_country_code" ]] && [[ "$old_country_code" != "$new_country_code" ]]; then + sudo sed -i "s/country_code=$old_country_code/country_code=$new_country_code/" /etc/hostapd/hostapd.conf + echo "Updated country code: $new_country_code" +fi + +old_ssid=$(grep ^ssid $HOSTAPD_CONF | cut -d "=" -f 2) +rpi_serial=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2) +new_ssid="isobox-$rpi_serial" + +if [[ "$old_ssid" != "$new_ssid" ]]; then + sed -i "s/ssid=$old_ssid/ssid=$new_ssid/" $HOSTAPD_CONF + echo "Updated ssid: $new_ssid" +fi + +old_hostname=$(hostname) +new_hostname="isobox-$rpi_serial" + +if [[ "$old_hostname" != "$new_hostname" ]]; then + echo $new_hostname >/etc/hostname + sed -i "s/$old_hostname/$new_hostname/" /etc/hosts + hostname $new_hostname + echo "Updated hostname: $new_hostname" +fi + echo "Stopping network services..." if [ $OPENVPNENABLED -eq 1 ]; then systemctl stop openvpn-client@client @@ -47,34 +76,6 @@ if [ "${action}" = "stop" ]; then exit 0 fi -HOSTAPD_CONF="/etc/hostapd/hostapd.conf" - -old_ssid=$(grep ^ssid $HOSTAPD_CONF | cut -d "=" -f 2) -rpi_serial=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2) -new_ssid="isobox-$rpi_serial" - -if [[ "$old_ssid" != "$new_ssid" ]]; then - sed -i "s/$old_ssid/$new_ssid/" $HOSTAPD_CONF - echo "Updated ssid: $new_ssid" -fi - -new_country_code=$(curl -s -H "Authorization: Bearer 9da1eb466ed052" https://ipinfo.io/json | jq -r ".country // empty") -old_country_code=$(grep ^country_code $HOSTAPD_CONF | cut -d "=" -f 2) - -if [[ ! -z "$new_country_code" ]] && [[ "$old_country_code" != "$new_country_code" ]]; then - sed -i "s/$old_country_code/$new_country_code/" $HOSTAPD_CONF - echo "Updated country code: $new_country_code" -fi - -old_hostname=$(hostname) -new_hostname=$(isobox-$rpi_serial) - -if [[ "$old_hostname" != "$new_hostname" ]]; then - echo $new_hostname >/etc/hostname - sed -i "s/$old_hostname/$new_hostname/" /etc/hosts - hostname $new_hostname -fi - if [ -f "$DAEMONPATH" ] && [ ! -z "$interface" ]; then echo "Changing RaspAP Daemon --interface to $interface" sed -i "s/\(--interface \)[[:alnum:]]*/\1$interface/" "$DAEMONPATH"