Option to disable wifi
This commit is contained in:
parent
14cc474649
commit
91871787cd
|
@ -44,6 +44,7 @@ WIFI_HOTSPOT='no'
|
|||
WIFI_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf
|
||||
WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
|
||||
NETWORKS_INTERACTIVE=
|
||||
WIFI_DISABLE=
|
||||
|
||||
function wifi_get_psk {
|
||||
ssid=$1
|
||||
|
@ -261,51 +262,59 @@ function networks_from_file {
|
|||
}
|
||||
|
||||
function create_networks_interactive {
|
||||
if [ -f $WIFI_NETWORKS_FILE ]; then
|
||||
rm $WIFI_NETWORKS_FILE
|
||||
fi
|
||||
if [ -f $WIFI_NETWORKS_FILE ]; then
|
||||
rm $WIFI_NETWORKS_FILE
|
||||
fi
|
||||
|
||||
wifi_ctr=0
|
||||
wifi_networks_done=
|
||||
wifi_ctr=0
|
||||
wifi_networks_done=
|
||||
while [ ! $wifi_networks_done ]
|
||||
do
|
||||
data=$(tempfile 2>/dev/null)
|
||||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --backtitle $"Freedombone Configuration" \
|
||||
--title $"Wifi Settings ${wifi_ctr}" \
|
||||
--form $"\nIf you wish to use wifi and have a Free Software compatible adapter (eg. Atheros) rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 4 \
|
||||
$"SSID:" 1 1 "$WIFI_SSID" 1 16 30 30 \
|
||||
$"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
|
||||
$"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
|
||||
2> $data
|
||||
sel=$?
|
||||
case $sel in
|
||||
1) return;;
|
||||
255) return;;
|
||||
esac
|
||||
WIFI_SSID=$(cat $data | sed -n 1p)
|
||||
WIFI_TYPE=$(cat $data | sed -n 2p)
|
||||
WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
|
||||
data=$(tempfile 2>/dev/null)
|
||||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --backtitle $"Freedombone Configuration" \
|
||||
--title $"Wifi Settings ${wifi_ctr}" \
|
||||
--form $"\nIf you wish to use wifi and have a Free Software compatible adapter (eg. Atheros) rather than wired ethernet then enter the details below, otherwise just select Ok:" 15 55 4 \
|
||||
$"SSID:" 1 1 "$WIFI_SSID" 1 16 30 30 \
|
||||
$"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
|
||||
$"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
|
||||
2> $data
|
||||
sel=$?
|
||||
case $sel in
|
||||
1) return;;
|
||||
255) return;;
|
||||
esac
|
||||
WIFI_SSID=$(cat $data | sed -n 1p)
|
||||
WIFI_TYPE=$(cat $data | sed -n 2p)
|
||||
WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
|
||||
|
||||
# if these fields are empty then there are no more wifi networks
|
||||
if [ ${#WIFI_SSID} -lt 2 ]; then
|
||||
wifi_networks_done='yes'
|
||||
continue
|
||||
fi
|
||||
if [ ${#WIFI_TYPE} -lt 2 ]; then
|
||||
wifi_networks_done='yes'
|
||||
continue
|
||||
fi
|
||||
|
||||
# update the wifi networks file
|
||||
echo '' >> $WIFI_NETWORKS_FILE
|
||||
echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
|
||||
echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
|
||||
if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
|
||||
echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
|
||||
fi
|
||||
wifi_ctr=$((wifi_ctr + 1))
|
||||
done
|
||||
# if these fields are empty then there are no more wifi networks
|
||||
if [ ${#WIFI_SSID} -lt 2 ]; then
|
||||
wifi_networks_done='yes'
|
||||
continue
|
||||
fi
|
||||
if [ ${#WIFI_TYPE} -lt 2 ]; then
|
||||
wifi_networks_done='yes'
|
||||
continue
|
||||
fi
|
||||
|
||||
# update the wifi networks file
|
||||
echo '' >> $WIFI_NETWORKS_FILE
|
||||
echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
|
||||
echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
|
||||
if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
|
||||
echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
|
||||
fi
|
||||
wifi_ctr=$((wifi_ctr + 1))
|
||||
done
|
||||
}
|
||||
|
||||
function disable {
|
||||
hotspot_off
|
||||
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
|
||||
systemctl restart network-manager
|
||||
}
|
||||
|
||||
function show_help {
|
||||
|
@ -322,6 +331,7 @@ function show_help {
|
|||
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
|
||||
}
|
||||
|
@ -360,9 +370,13 @@ do
|
|||
;;
|
||||
--networksinteractive)
|
||||
shift
|
||||
NETWORKS_INTERACTIVE='yes'
|
||||
NETWORKS_INTERACTIVE='yes'
|
||||
WIFI_NETWORKS_FILE=${1}
|
||||
;;
|
||||
--disable)
|
||||
shift
|
||||
WIFI_DISABLE=${1}
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
|
@ -370,47 +384,52 @@ do
|
|||
shift
|
||||
done
|
||||
|
||||
if [[ $WIFI_DISABLE == $'yes' || $WIFI_DISABLE == $'y' ]]; then
|
||||
disable
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $NETWORKS_INTERACTIVE ]; then
|
||||
create_networks_interactive
|
||||
exit 0
|
||||
create_networks_interactive
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -f $WIFI_NETWORKS_FILE ]; then
|
||||
networks_from_file
|
||||
exit 0
|
||||
networks_from_file
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! $WIFI_SSID ]; then
|
||||
echo $'No SSID given'
|
||||
exit 1
|
||||
echo $'No SSID given'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $WIFI_HOTSPOT != 'no' ]]; then
|
||||
hotspot_on
|
||||
exit 0
|
||||
hotspot_on
|
||||
exit 0
|
||||
else
|
||||
hotspot_off
|
||||
hotspot_off
|
||||
fi
|
||||
|
||||
if [[ $WIFI_TYPE != 'none' ]]; then
|
||||
if [ ! $WIFI_PASSPHRASE ]; then
|
||||
echo $'No wifi passphrase was given'
|
||||
exit 2
|
||||
fi
|
||||
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
|
||||
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' ]]; then
|
||||
wifi_none "$WIFI_SSID"
|
||||
exit 0
|
||||
wifi_none "$WIFI_SSID"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue