This commit is contained in:
Bob Mottram 2016-04-21 12:24:20 +01:00
parent 3b263e4074
commit af37d67bb2
2 changed files with 121 additions and 5 deletions

View File

@ -64,11 +64,15 @@ WIFI_INTERFACE=wlan0
WIFI_SSID=
WIFI_TYPE='wpa2-psk'
WIFI_PASSPHRASE=
WIFI_HOTSPOT='no'
USB_DRIVE=sdb
# get default USB from config file
CONFIGURATION_FILE=/root/${PROJECT_NAME}.cfg
if [ -f $CONFIGURATION_FILE ]; then
if grep -q "WIFI_HOTSPOT=" $CONFIGURATION_FILE; then
WIFI_HOTSPOT=$(cat $CONFIGURATION_FILE | grep "WIFI_HOTSPOT=" | awk -F '=' '{print $2}')
fi
if grep -q "WIFI_INTERFACE=" $CONFIGURATION_FILE; then
WIFI_INTERFACE=$(cat $CONFIGURATION_FILE | grep "WIFI_INTERFACE=" | awk -F '=' '{print $2}')
fi
@ -1672,6 +1676,7 @@ Enter a static local IP address for this system.\n\nIt will typically be 192.168
}
function wifi_settings {
PREV_WIFI_HOTSPOT=$WIFI_HOTSPOT
PREV_WIFI_INTERFACE=$WIFI_INTERFACE
PREV_WIFI_SSID=$WIFI_SSID
PREV_WIFI_TYPE=$WIFI_TYPE
@ -1681,11 +1686,12 @@ function wifi_settings {
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Wifi Settings" \
--form $"\nIf you wish to use wifi rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 5 \
--form $"\nIf you wish to use wifi rather than wired ethernet then enter the details below, otherwise just select Ok:" 16 55 6 \
$"Interface:" 1 1 "$WIFI_INTERFACE" 1 16 16 15 \
$"SSID:" 2 1 "$WIFI_SSID" 2 16 30 30 \
$"Type:" 3 1 "$WIFI_TYPE" 3 16 16 15 \
$"Passphrase:" 4 1 "$WIFI_PASSPHRASE" 4 16 30 30 \
$"Hotspot:" 5 1 "$WIFI_HOTSPOT" 5 16 16 15 \
2> $data
sel=$?
case $sel in
@ -1696,6 +1702,7 @@ function wifi_settings {
NEW_WIFI_SSID=$(cat $data | sed -n 2p)
NEW_WIFI_TYPE=$(cat $data | sed -n 3p)
NEW_WIFI_PASSPHRASE=$(cat $data | sed -n 4p)
NEW_WIFI_HOTSPOT=$(cat $data | sed -n 5p)
if [[ $NEW_WIFI_TYPE != 'none' && $NEW_WIFI_TYPE != 'wpa2-psk' ]]; then
return
@ -1707,10 +1714,17 @@ function wifi_settings {
fi
if [ ${#NEW_WIFI_PASSPHRASE} -lt 2 ]; then
return
fi
${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE -p $NEW_WIFI_PASSPHRASE
fi
HOTSPOT='no'
if [[ $NEW_WIFI_HOTSPOT == $'Y' || $NEW_WIFI_HOTSPOT == $'yes' || $NEW_WIFI_HOTSPOT == $'y' ]]; then
apt-get -y install hostapd bridge-utils
HOTSPOT='yes'
fi
${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE -p $NEW_WIFI_PASSPHRASE --hotspot $HOTSPOT
else
${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE
${PROJECT_NAME}-wifi -i $NEW_WIFI_INTERFACE -s $NEW_WIFI_SSID -t $NEW_WIFI_TYPE --hotspot $HOTSPOT
fi
if [[ $PREV_WIFI_INTERFACE != $NEW_WIFI_INTERFACE || $PREV_WIFI_SSID != $NEW_WIFI_SSID || $PREV_WIFI_TYPE != $NEW_WIFI_TYPE || $PREV_WIFI_PASSPHRASE != $NEW_WIFI_PASSPHRASE ]]; then
@ -1750,8 +1764,13 @@ function wifi_settings {
else
sed -i "s|WIFI_PASSPHRASE=.*|WIFI_PASSPHRASE=$WIFI_PASSPHRASE|g" $CONFIGURATION_FILE
fi
if ! grep -q "WIFI_HOTSPOT=" $CONFIGURATION_FILE; then
echo "WIFI_HOTSPOT=$WIFI_HOTSPOT" >> $CONFIGURATION_FILE
else
sed -i "s|WIFI_HOTSPOT=.*|WIFI_HOTSPOT=$WIFI_HOTSPOT|g" $CONFIGURATION_FILE
fi
systemctl restart networking
systemctl restart network-manager
fi
}

View File

@ -40,6 +40,7 @@ WIFI_INTERFACE=wlan0
WIFI_TYPE='wpa2-psk'
WIFI_SSID=
WIFI_PASSPHRASE=
WIFI_HOTSPOT='no'
function wifi_get_psk {
ssid=$1
@ -49,6 +50,90 @@ function wifi_get_psk {
echo $psk
}
function hotspot_off {
if [ ! -f /etc/hostapd/hostapd.conf ]; then
return
fi
systemctl stop hostapd
rm /etc/hostapd/hostapd.conf
if [ -f /etc/network/interfaces_old ]; then
cp /etc/network/interfaces_old /etc/network/interfaces
else
echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
fi
systemctl restart network-manager
}
function hotspot_on {
if [ ! -f /etc/default/hostapd ]; then
echo $'/etc/default/hostapd was not found'
exit 67241
fi
if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
echo $'Wifi hotspot passphrase is too short'
exit 25719
fi
sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
echo '' >> /etc/hostapd/hostapd.conf
echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
echo '' >> /etc/hostapd/hostapd.conf
echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
echo "country_code=UK" >> /etc/hostapd/hostapd.conf
echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
echo 'channel=6' >> /etc/hostapd/hostapd.conf
echo 'wpa=2' >> /etc/hostapd/hostapd.conf
echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
echo '' >> /etc/hostapd/hostapd.conf
echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
echo '' >> /etc/hostapd/hostapd.conf
echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
echo '' >> /etc/hostapd/hostapd.conf
echo '## Shared Key Authentication ##'
echo 'auth_algs=1'
echo '' >> /etc/hostapd/hostapd.conf
echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
if ! grep -q "# Hotspot" /etc/network/interfaces; then
cp /etc/network/interfaces /etc/network/interfaces_old
fi
echo '# Hotspot' > /etc/network/interfaces
echo 'auto lo br0' >> /etc/network/interfaces
echo 'iface lo inet loopback' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
echo 'allow-hotplug eth0' >> /etc/network/interfaces
echo 'iface eth0 inet manual' >> /etc/network/interfaces
echo '' >> /etc/network/interfaces
echo '# Setup bridge' >> /etc/network/interfaces
echo 'iface br0 inet static' >> /etc/network/interfaces
echo " bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
systemctl restart network-manager
systemctl restart hostapd
}
function wifi_wpa2_psk {
ssid=$1
passphrase=$2
@ -77,6 +162,7 @@ function show_help {
echo $' -t --type [wpa2-psk|none] Security type'
echo $' -s --ssid [id] Set SSID'
echo $' -p --passphrase [text] Set passphrase'
echo $' --hotspot [yes|no] Create a hotspot'
echo ''
exit 0
}
@ -105,6 +191,10 @@ do
shift
WIFI_PASSPHRASE=${1}
;;
--hostpot)
shift
WIFI_HOTSPOT=${1}
;;
*)
# unknown option
;;
@ -117,6 +207,13 @@ if [ ! $WIFI_SSID ]; then
exit 1
fi
if [[ $WIFI_HOTSPOT != 'no' ]]; then
hotspot_on
exit 0
else
hotspot_off
fi
if [[ $WIFI_TYPE != 'none' ]]; then
if [ ! $WIFI_PASSPHRASE ]; then
echo $'No wifi passphrase was given'