diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh')
| -rwxr-xr-x | addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh b/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh new file mode 100755 index 00000000..00d9814f --- /dev/null +++ b/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +FORCE_HOST_AP="${1}" +WIRED_IP=$(python3 -c "import netifaces as ni; print(ni.ifaddresses('eth0').get(ni.AF_INET) and ni.ifaddresses('eth0')[ni.AF_INET][0]['addr'] or '')") +WIFI_NETWORK_FILE="/home/pi/wifi_network.txt" + + +ifconfig wlan0 down +ifconfig wlan0 up + +# wait for wlan0 to come up +sleep 5 + +# if there is no wired ip, attempt to start an AP through wireless interface +if [ -z "${WIRED_IP}" ] ; then + logger -t posbox_wireless_ap "No wired IP" + + if [ -f "${WIFI_NETWORK_FILE}" ] && [ -z "${FORCE_HOST_AP}" ] ; then + logger -t posbox_wireless_ap "Loading persistently saved setting" + /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh & + else + logger -t posbox_wireless_ap "Starting AP" + + SSID=$(grep -oP '(?<=ssid=).*' /etc/hostapd/hostapd.conf) + + if [ "${SSID}" = "IoTBox" ] + then + # override SSID to get a unique SSID + MAC=$(ip link show wlan0 | tail -n 1 | awk '{print $2}' | sed 's/\://g') + NEWSSID="${SSID}-${MAC}" + sed -ie "s/$(echo ${SSID})/$(echo ${NEWSSID})/g" /etc/hostapd/hostapd.conf + fi + + service hostapd restart + + ip addr add 10.11.12.1/24 dev wlan0 + + service dnsmasq restart + + service nginx stop + # We start nginx in another configuration than the default one with https + # as it needs to do redirect instead in case the IoT Box acts as an ap + nginx -c /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/nginx_ap.conf + + service odoo restart + fi +# wired +else + killall nginx + service nginx restart + service dnsmasq stop + service odoo restart +fi |
