#!/bin/bash # # .---. . . # | | | # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-' # ' ' --' --' -' - -' ' ' -' -' -' ' - --' # # Freedom in the Cloud # # Wifi configuration tools # License # ======= # # Copyright (C) 2016 Bob Mottram # # 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 . 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 WIFI_INTERFACE=wlan0 wifi_interface_specified= WIFI_TYPE='wpa2-psk' WIFI_SSID= WIFI_PASSPHRASE= WIFI_HOTSPOT='no' WIFI_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg NETWORKS_INTERACTIVE= WIFI_DISABLE= IFACE= IFACE_SECONDARY= source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-config source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi 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' echo $' --networks [filename] File containing wifi networks' echo $' --createnetworks [filename] Create file containing wifi networks' echo $' --disable [yes/no] Disable wifi' echo '' exit 0 } while [[ $# > 1 ]] do key="$1" case $key in --help) show_help ;; -i|--if|--interface) shift WIFI_INTERFACE=${1} wifi_interface_specified=1 write_config_param "WIFI_INTERFACE" "$WIFI_INTERFACE" ifconfig $WIFI_INTERFACE down ifconfig $WIFI_INTERFACE up ;; -t|--type) shift WIFI_TYPE=${1} ;; -s|--ssid) shift WIFI_SSID=${1} ;; -p|--pass|--passphrase) shift WIFI_PASSPHRASE=${1} ;; --hotspot) shift WIFI_HOTSPOT=${1} ;; --networks) shift WIFI_NETWORKS_FILE=${1} ;; --networksinteractive) shift NETWORKS_INTERACTIVE='yes' WIFI_NETWORKS_FILE=${1} ;; --disable) shift WIFI_DISABLE=${1} if [[ $WIFI_DISABLE == $'yes' || $WIFI_DISABLE == $'y' ]]; then WIFI_DISABLE='yes' else WIFI_DISABLE='no' fi ;; *) # unknown option ;; esac shift done if [ $NETWORKS_INTERACTIVE ]; then create_networks_interactive exit 0 fi if [ ! $wifi_interface_specified= ]; then update_wifi_adaptors if [ ! $IFACE ]; then echo $'No wifi adaptors were found' exit 872356 fi WIFI_INTERFACE=$IFACE write_config_param "WIFI_INTERFACE" "$WIFI_INTERFACE" ifconfig $WIFI_INTERFACE down ifconfig $WIFI_INTERFACE up fi if [ $WIFI_DISABLE ]; then disable_wifi $WIFI_DISABLE remove_config_param "WIFI_INTERFACE" exit 0 fi if [ -f $WIFI_NETWORKS_FILE ]; then networks_from_file exit 0 fi if [ ! $WIFI_SSID ]; then echo $'No SSID given' exit 1 fi if [[ $WIFI_HOTSPOT != 'no' ]]; then hotspot_on exit 0 else hotspot_off fi if [[ "$WIFI_TYPE" != 'none' && "$WIFI_TYPE" != 'open' ]]; then if [ ! $WIFI_PASSPHRASE ]; then echo $'No wifi passphrase was given' exit 2 fi fi if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then if [ ! -d /etc/wpa_supplicant ]; then echo $'wpasupplicant package is not installed' exit 3 fi wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE" exit 0 fi if [[ "$WIFI_TYPE" == 'none' || "$WIFI_TYPE" == 'open' ]]; then wifi_none "$WIFI_SSID" exit 0 fi exit 0