From b6ec9f041f8991fe8a64290f548c7e1cdcb84ec9 Mon Sep 17 00:00:00 2001 From: Matthias Strubel Date: Fri, 17 Mar 2017 22:39:32 +0100 Subject: [PATCH] Feature: Add scripts for on the fly client mode Closes: #171 --- .../piratebox/rpi/bin/do_switch_client.sh | 14 ++++++++++ piratebox/piratebox/rpi/bin/run_client.sh | 27 +++++++++++++++++++ .../piratebox/rpi/bin/switch_to_client.sh | 6 +++++ piratebox/piratebox/rpi/bin/wifi_detect.sh | 6 ++--- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100755 piratebox/piratebox/rpi/bin/do_switch_client.sh create mode 100755 piratebox/piratebox/rpi/bin/run_client.sh create mode 100755 piratebox/piratebox/rpi/bin/switch_to_client.sh diff --git a/piratebox/piratebox/rpi/bin/do_switch_client.sh b/piratebox/piratebox/rpi/bin/do_switch_client.sh new file mode 100755 index 0000000..9234778 --- /dev/null +++ b/piratebox/piratebox/rpi/bin/do_switch_client.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Wrapper script for the steps to enable wifi client + +systemctl stop piratebox +if /opt/piratebox/rpi/run_client.sh ; then + echo "Started Wifi client sucessfully!" + exit 0 +else + echo "Error while starting wifi client, restarting piratebox" + systemctl start piratebox + exit 1 +fi +exit 1 diff --git a/piratebox/piratebox/rpi/bin/run_client.sh b/piratebox/piratebox/rpi/bin/run_client.sh new file mode 100755 index 0000000..11e69ab --- /dev/null +++ b/piratebox/piratebox/rpi/bin/run_client.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Runs with wpa_supplicant & wifi device from boot folder. + +## Default +WIFI_DEVICE="wlan0" + +WIFI_CONFIG_PATH="/boot/wifi_card.conf" +WPA_SUPPLICANT="/boot/wpa_supplicant.conf" + +# Try to get wifi device +if test -e "${WIFI_CONFIG_PATH}" ; then + echo "Found wifi card config" + WIFI_DEVICE=$( head -n 1 "${WIFI_CONFIG_PATH}" | tr -d '\n' ) +fi + +# Try to connect to Wifi if wpa_supplicant.conf is available. +if [ -f "${WPA_SUPPLICANT}" ]; then + echo "Found wpa_supplicant conf, trying to connect..." + wpa_supplicant -i"${WIFI_DEVICE}" -c "${WPA_SUPPLICANT}" -B -D wext + dhcpcd "${WIFI_DEVICE}" + exit 0 +else + echo "Wifi configuration not found" + exit 1 +fi +exit 1 diff --git a/piratebox/piratebox/rpi/bin/switch_to_client.sh b/piratebox/piratebox/rpi/bin/switch_to_client.sh new file mode 100755 index 0000000..a2bee92 --- /dev/null +++ b/piratebox/piratebox/rpi/bin/switch_to_client.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# User friendly way to switch to client +# Adds "nohup" option... + +nohup /opt/piratebox/rpi/bin/do_switch_client.sh diff --git a/piratebox/piratebox/rpi/bin/wifi_detect.sh b/piratebox/piratebox/rpi/bin/wifi_detect.sh index 3a5f42b..68e3c5a 100755 --- a/piratebox/piratebox/rpi/bin/wifi_detect.sh +++ b/piratebox/piratebox/rpi/bin/wifi_detect.sh @@ -74,9 +74,9 @@ echo "Could not find an AP enabled WiFi card..." # Try to connect to Wifi if wpa_supplicant.conf is available. if [ -f /boot/wpa_supplicant.conf ]; then - echo "Found wpa_supplicant conf, trying to connect..." - wpa_supplicant -i"${WIFI_DEVICE}" -c /boot/wpa_supplicant.conf -B -D wext - dhcpcd "${WIFI_DEVICE}" + /opt/piratebox/rpi/bin/run_client.sh + exit 1 + # Exit =! 0 will result in not starting piratebox service fi exit 1