freedombone/src/freedombone-wifi

195 lines
4.9 KiB
Plaintext
Raw Normal View History

2016-04-20 13:17:44 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Wifi configuration tools
# License
# =======
#
# Copyright (C) 2016 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-wifi
export TEXTDOMAINDIR="/usr/share/locale"
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
2016-04-20 15:53:49 +02:00
WIFI_INTERFACE=wlan0
2016-10-21 11:03:33 +02:00
wifi_interface_specified=
2016-04-20 13:17:44 +02:00
WIFI_TYPE='wpa2-psk'
WIFI_SSID=
WIFI_PASSPHRASE=
2016-04-21 13:24:20 +02:00
WIFI_HOTSPOT='no'
2016-04-26 20:50:01 +02:00
WIFI_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf
2016-04-26 23:38:03 +02:00
WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
NETWORKS_INTERACTIVE=
2016-04-27 18:41:19 +02:00
WIFI_DISABLE=
2016-04-20 13:17:44 +02:00
2016-10-21 11:03:33 +02:00
IFACE=
IFACE_SECONDARY=
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-config
2016-10-21 11:24:07 +02:00
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
2016-04-26 23:38:03 +02:00
2016-04-20 13:17:44 +02:00
function show_help {
echo ''
echo $"${PROJECT_NAME}-wifi -i [interface] -t [type] -s [ssid] -p [passphrase]"
echo ''
echo $'Wifi configuration tool'
echo ''
echo $' --help Show help'
echo $' -i --interface [wlan0|wlan1...] Device name'
echo $' -t --type [wpa2-psk|none|open] Security type'
echo $' -s --ssid [id] Set SSID'
echo $' -p --passphrase [text] Set passphrase'
echo $' --hotspot [yes|no] Create a hotspot'
2016-04-26 23:38:03 +02:00
echo $' --networks [filename] File containing wifi networks'
echo $' --createnetworks [filename] Create file containing wifi networks'
2016-04-27 18:41:19 +02:00
echo $' --disable [yes/no] Disable wifi'
echo ''
exit 0
2016-04-20 13:17:44 +02:00
}
while [[ $# > 1 ]]
do
key="$1"
case $key in
--help)
show_help
;;
-i|--if|--interface)
shift
WIFI_INTERFACE=${1}
2016-10-21 11:03:33 +02:00
wifi_interface_specified=1
write_config_param "WIFI_INTERFACE" "$WIFI_INTERFACE"
2016-10-21 17:05:39 +02:00
ifdown --force $WIFI_INTERFACE
ifup $WIFI_INTERFACE
;;
-t|--type)
shift
WIFI_TYPE=${1}
;;
-s|--ssid)
shift
WIFI_SSID=${1}
;;
-p|--pass|--passphrase)
shift
WIFI_PASSPHRASE=${1}
;;
2016-04-27 20:48:36 +02:00
--hotspot)
shift
WIFI_HOTSPOT=${1}
;;
--networks)
shift
WIFI_NETWORKS_FILE=${1}
;;
2016-04-26 23:38:03 +02:00
--networksinteractive)
shift
2016-04-27 18:41:19 +02:00
NETWORKS_INTERACTIVE='yes'
2016-04-26 23:38:03 +02:00
WIFI_NETWORKS_FILE=${1}
;;
2016-04-27 18:41:19 +02:00
--disable)
shift
WIFI_DISABLE=${1}
2016-04-27 20:15:11 +02:00
if [[ $WIFI_DISABLE == $'yes' || $WIFI_DISABLE == $'y' ]]; then
WIFI_DISABLE='yes'
else
WIFI_DISABLE='no'
2016-05-04 16:59:36 +02:00
fi
2016-04-27 18:41:19 +02:00
;;
*)
# unknown option
;;
esac
shift
2016-04-20 13:17:44 +02:00
done
2016-10-21 11:03:33 +02:00
if [ $NETWORKS_INTERACTIVE ]; then
create_networks_interactive
exit 0
fi
2016-10-21 16:20:38 +02:00
if [ ! $wifi_interface_specified ]; then
2016-10-21 11:03:33 +02:00
update_wifi_adaptors
if [ ! $IFACE ]; then
echo $'No wifi adaptors were found'
exit 872356
fi
WIFI_INTERFACE=$IFACE
2016-10-21 16:18:59 +02:00
echo "Adaptor: $WIFI_INTERFACE"
write_config_param "WIFI_INTERFACE" "$WIFI_INTERFACE"
2016-10-21 17:05:39 +02:00
ifdown --force $WIFI_INTERFACE
ifup $WIFI_INTERFACE
2016-04-26 23:38:03 +02:00
fi
2016-10-21 11:11:23 +02:00
if [ $WIFI_DISABLE ]; then
disable_wifi $WIFI_DISABLE
remove_config_param "WIFI_INTERFACE"
2016-10-21 11:11:23 +02:00
exit 0
fi
if [ -f $WIFI_NETWORKS_FILE ]; then
2016-04-27 18:41:19 +02:00
networks_from_file
exit 0
2016-04-26 20:50:01 +02:00
fi
2016-04-20 13:17:44 +02:00
if [ ! $WIFI_SSID ]; then
2016-04-27 18:41:19 +02:00
echo $'No SSID given'
exit 1
2016-04-20 13:17:44 +02:00
fi
2016-04-21 13:24:20 +02:00
if [[ $WIFI_HOTSPOT != 'no' ]]; then
2016-04-27 18:41:19 +02:00
hotspot_on
exit 0
2016-04-21 13:24:20 +02:00
else
2016-04-27 18:41:19 +02:00
hotspot_off
2016-04-21 13:24:20 +02:00
fi
if [[ "$WIFI_TYPE" != 'none' && "$WIFI_TYPE" != 'open' ]]; then
2016-04-27 18:41:19 +02:00
if [ ! $WIFI_PASSPHRASE ]; then
echo $'No wifi passphrase was given'
exit 2
fi
2016-04-20 13:17:44 +02:00
fi
if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then
2016-04-27 18:41:19 +02:00
if [ ! -d /etc/wpa_supplicant ]; then
echo $'wpasupplicant package is not installed'
exit 3
fi
wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
exit 0
2016-04-20 13:17:44 +02:00
fi
if [[ "$WIFI_TYPE" == 'none' || "$WIFI_TYPE" == 'open' ]]; then
2016-04-27 18:41:19 +02:00
wifi_none "$WIFI_SSID"
exit 0
2016-04-20 13:17:44 +02:00
fi
exit 0