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_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf
|
||||||
WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
|
WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
|
||||||
NETWORKS_INTERACTIVE=
|
NETWORKS_INTERACTIVE=
|
||||||
|
WIFI_DISABLE=
|
||||||
|
|
||||||
function wifi_get_psk {
|
function wifi_get_psk {
|
||||||
ssid=$1
|
ssid=$1
|
||||||
|
@ -261,51 +262,59 @@ function networks_from_file {
|
||||||
}
|
}
|
||||||
|
|
||||||
function create_networks_interactive {
|
function create_networks_interactive {
|
||||||
if [ -f $WIFI_NETWORKS_FILE ]; then
|
if [ -f $WIFI_NETWORKS_FILE ]; then
|
||||||
rm $WIFI_NETWORKS_FILE
|
rm $WIFI_NETWORKS_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wifi_ctr=0
|
wifi_ctr=0
|
||||||
wifi_networks_done=
|
wifi_networks_done=
|
||||||
while [ ! $wifi_networks_done ]
|
while [ ! $wifi_networks_done ]
|
||||||
do
|
do
|
||||||
data=$(tempfile 2>/dev/null)
|
data=$(tempfile 2>/dev/null)
|
||||||
trap "rm -f $data" 0 1 2 5 15
|
trap "rm -f $data" 0 1 2 5 15
|
||||||
dialog --backtitle $"Freedombone Configuration" \
|
dialog --backtitle $"Freedombone Configuration" \
|
||||||
--title $"Wifi Settings ${wifi_ctr}" \
|
--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 \
|
--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 \
|
$"SSID:" 1 1 "$WIFI_SSID" 1 16 30 30 \
|
||||||
$"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
|
$"Type:" 2 1 "$WIFI_TYPE" 2 16 10 10 \
|
||||||
$"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
|
$"Passphrase:" 3 1 "$WIFI_PASSPHRASE" 3 16 30 30 \
|
||||||
2> $data
|
2> $data
|
||||||
sel=$?
|
sel=$?
|
||||||
case $sel in
|
case $sel in
|
||||||
1) return;;
|
1) return;;
|
||||||
255) return;;
|
255) return;;
|
||||||
esac
|
esac
|
||||||
WIFI_SSID=$(cat $data | sed -n 1p)
|
WIFI_SSID=$(cat $data | sed -n 1p)
|
||||||
WIFI_TYPE=$(cat $data | sed -n 2p)
|
WIFI_TYPE=$(cat $data | sed -n 2p)
|
||||||
WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
|
WIFI_PASSPHRASE=$(cat $data | sed -n 3p)
|
||||||
|
|
||||||
# if these fields are empty then there are no more wifi networks
|
# if these fields are empty then there are no more wifi networks
|
||||||
if [ ${#WIFI_SSID} -lt 2 ]; then
|
if [ ${#WIFI_SSID} -lt 2 ]; then
|
||||||
wifi_networks_done='yes'
|
wifi_networks_done='yes'
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if [ ${#WIFI_TYPE} -lt 2 ]; then
|
if [ ${#WIFI_TYPE} -lt 2 ]; then
|
||||||
wifi_networks_done='yes'
|
wifi_networks_done='yes'
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# update the wifi networks file
|
# update the wifi networks file
|
||||||
echo '' >> $WIFI_NETWORKS_FILE
|
echo '' >> $WIFI_NETWORKS_FILE
|
||||||
echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
|
echo "$WIFI_SSID" >> $WIFI_NETWORKS_FILE
|
||||||
echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
|
echo "$WIFI_TYPE" >> $WIFI_NETWORKS_FILE
|
||||||
if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
|
if [ ${#WIFI_PASSPHRASE} -gt 1 ]; then
|
||||||
echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
|
echo "$WIFI_PASSPHRASE" >> $WIFI_NETWORKS_FILE
|
||||||
fi
|
fi
|
||||||
wifi_ctr=$((wifi_ctr + 1))
|
wifi_ctr=$((wifi_ctr + 1))
|
||||||
done
|
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 {
|
function show_help {
|
||||||
|
@ -322,6 +331,7 @@ function show_help {
|
||||||
echo $' --hotspot [yes|no] Create a hotspot'
|
echo $' --hotspot [yes|no] Create a hotspot'
|
||||||
echo $' --networks [filename] File containing wifi networks'
|
echo $' --networks [filename] File containing wifi networks'
|
||||||
echo $' --createnetworks [filename] Create file containing wifi networks'
|
echo $' --createnetworks [filename] Create file containing wifi networks'
|
||||||
|
echo $' --disable [yes/no] Disable wifi'
|
||||||
echo ''
|
echo ''
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
@ -360,9 +370,13 @@ do
|
||||||
;;
|
;;
|
||||||
--networksinteractive)
|
--networksinteractive)
|
||||||
shift
|
shift
|
||||||
NETWORKS_INTERACTIVE='yes'
|
NETWORKS_INTERACTIVE='yes'
|
||||||
WIFI_NETWORKS_FILE=${1}
|
WIFI_NETWORKS_FILE=${1}
|
||||||
;;
|
;;
|
||||||
|
--disable)
|
||||||
|
shift
|
||||||
|
WIFI_DISABLE=${1}
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
# unknown option
|
# unknown option
|
||||||
;;
|
;;
|
||||||
|
@ -370,47 +384,52 @@ do
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ $WIFI_DISABLE == $'yes' || $WIFI_DISABLE == $'y' ]]; then
|
||||||
|
disable
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $NETWORKS_INTERACTIVE ]; then
|
if [ $NETWORKS_INTERACTIVE ]; then
|
||||||
create_networks_interactive
|
create_networks_interactive
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f $WIFI_NETWORKS_FILE ]; then
|
if [ -f $WIFI_NETWORKS_FILE ]; then
|
||||||
networks_from_file
|
networks_from_file
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! $WIFI_SSID ]; then
|
if [ ! $WIFI_SSID ]; then
|
||||||
echo $'No SSID given'
|
echo $'No SSID given'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $WIFI_HOTSPOT != 'no' ]]; then
|
if [[ $WIFI_HOTSPOT != 'no' ]]; then
|
||||||
hotspot_on
|
hotspot_on
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
hotspot_off
|
hotspot_off
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $WIFI_TYPE != 'none' ]]; then
|
if [[ $WIFI_TYPE != 'none' ]]; then
|
||||||
if [ ! $WIFI_PASSPHRASE ]; then
|
if [ ! $WIFI_PASSPHRASE ]; then
|
||||||
echo $'No wifi passphrase was given'
|
echo $'No wifi passphrase was given'
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then
|
if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then
|
||||||
if [ ! -d /etc/wpa_supplicant ]; then
|
if [ ! -d /etc/wpa_supplicant ]; then
|
||||||
echo $'wpasupplicant package is not installed'
|
echo $'wpasupplicant package is not installed'
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
|
wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $WIFI_TYPE == 'none' ]]; then
|
if [[ $WIFI_TYPE == 'none' ]]; then
|
||||||
wifi_none "$WIFI_SSID"
|
wifi_none "$WIFI_SSID"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue