exit "${1:-0}"
}
-# This function produces the IWOURLINE for interfaces
-writeiwline() {
- IWOURLINE=""
- if [ -n "$NWID" ]; then
- IWOURLINE="$IWOURLINE wireless-nwid $NWID\n"
+check_for_blocked_devices() {
+ if ! command -v rfkill &>/dev/null ; then
+ echo "Warning: rfkill executable not present, skipping check for blocked devices."
+ return 0
fi
- if [ -n "$MODE" ]; then
- IWOURLINE="$IWOURLINE wireless-mode $MODE\n"
+ # if we detect any blocked devices (SOFT or HARD) then report
+ if rfkill | grep -w 'blocked' ; then
+ return 0
fi
- if [ -n "$CHANNEL" ]; then
- IWOURLINE="$IWOURLINE wireless-channel $CHANNEL\n"
- fi
+ return 1
+}
- if [ -n "$FREQ" ]; then
- IWOURLINE="$IWOURLINE wireless-freq $FREQ\n"
- fi
+# This function produces the IWOURLINE for interfaces
+writeiwline() {
+ IWOURLINE=""
if [ -n "$KEY" ]; then
if [ "$PUBKEY" -eq 1 ]; then
# Store the key in interfaces in wireless-key
- IWOURLINE="$IWOURLINE wireless-key $KEY\n"
+ IWOURLINE="$IWOURLINE\twireless-key $KEY\n"
else
# Store the key in /etc/network/wep.$DV which is root readable only
# Use pre-up in interfaces to read and set it
- echo "$KEY" > "/etc/network/wep.$DV" && chmod 600 "/etc/network/wep.$DV" && IWOURLINE="$IWOURLINE pre-up KEY=\$(cat /etc/network/wep.$DV) && iwconfig $DV key \$KEY\n"
+ echo "$KEY" > "/etc/network/wep.$DV" && chmod 600 "/etc/network/wep.$DV" && IWOURLINE="$IWOURLINE\tpre-up KEY=\$(cat /etc/network/wep.$DV) && iwconfig $DV key \$KEY\n"
fi
fi
for mod in /sys/module/rt2??0/ ; do
if [ -d "$mod" ]; then
- IWPREUPLINE="$IWPREUPLINE pre-up /sbin/ip link set $DV up\n"
+ IWPREUPLINE="$IWPREUPLINE\tpre-up /sbin/ip link set $DV up\n"
break
fi
done
- if [ -n "$IWCONFIG" ]; then
- IWPREUPLINE="$IWPREUPLINE iwconfig $IWCONFIG\n"
- fi
-
- if [ -n "$IWSPY" ]; then
- IWPREUPLINE="$IWPREUPLINE iwspy $IWSPY\n"
- fi
-
- if [ -n "$IWPRIV" ]; then
- IWPREUPLINE="$IWPREUPLINE iwpriv $IWPRIV\n"
- fi
-
# execute ESSID last, but make sure that it is written as first option
if [ -n "$ESSID" ]; then
- IWOURLINE="$IWOURLINE wireless-essid $ESSID\n"
+ IWOURLINE="$IWOURLINE\twireless-essid $ESSID\n"
fi
if [ "$WPAON" -gt 0 ]; then
- IWOURLINE="$IWOURLINE wpa-ssid $ESSID\n wpa-psk $WPASECRET\n"
+ IWOURLINE="$IWOURLINE\twpa-ssid $ESSID\n\twpa-psk $WPASECRET\n"
fi
IWOURLINE="$IWOURLINE $IWPREUPLINE"
if [ $iswireless -gt 0 ] && $DIALOG --yesno "$MESSAGE13" 8 45; then
WLDEVICECOUNT="$(LANG=C LC_MESSAGEWS=C iwconfig "$DV" 2>/dev/null | wc -l)"
ESSID=""
- NWID=""
- MODE=""
- CHANNEL=""
- FREQ=""
- SENS=""
- RATE=""
KEY=""
- RTS=""
- FRAG=""
- IWCONFIG=""
- IWSPY=""
- IWPRIV=""
if [ -f /etc/network/interfaces ]; then
awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
/essid/{if(found){for(i=NF;i>=2;i--)essid=$i "~" essid}}
- /nwid/{if(found){nwid=$NF}}
- /mode/{if(found){mode=$NF}}
- /channel/{if(found){channel=$NF}}
- /freq/{if(found){freq=$NF}}
- /sens/{if(found){sens=$NF}}
- /rate/{if(found){rate=$NF}}
- /rts/{if(found){rts=$NF}}
- /frag/{if(found){frag=$NF}}
- /iwconfig/{if(!/KEY/){if(found){iwconfig=$NF}}}
- /iwspy/{if(found){iwspy=$NF}}
- /iwpriv/{if(found){iwpriv=$NF}}
/wireless[-_]key/{if(found){gsub(/^\W*wireless[-_]key\W*/,"");key=$0}}
END{
if (!(length(essid))){essid="~~~"}
- if (!(length(nwid))){nwid="~~~"}
- if (!(length(mode))){mode="~~~"}
- if (!(length(channel))){channel="~~~"}
- if (!(length(freq))){freq="~~~"}
- if (!(length(sens))){sens="~~~"}
- if (!(length(rate))){rate="~~~"}
- if (!(length(rts))){rts="~~~"}
- if (!(length(frag))){frag="~~~"}
- if (!(length(iwconfig))){iwconfig="~~~"}
- if (!(length(iwspy))){iwspy="~~~"}
- if (!(length(iwpriv))){iwpriv="~~~"}
if (!(length(key))){key="~~~"}
- print essid" "nwid" "mode" "channel" "freq" "sens" "rate" "rts" "frag" "iwconfig" "iwspy" "iwpriv" "key
+ print essid" "key
}' /etc/network/interfaces >"$TMP"
- read -r ESSID NWID MODE CHANNEL FREQ SENS RATE RTS FRAG IWCONFIG IWSPY IWPRIV KEY<"$TMP"
+ read -r ESSID KEY<"$TMP"
[[ "$ESSID" =~ ^~~~$ ]] && ESSID=""
- [[ "$NWID" =~ ^~~~$ ]] && NWID=""
- [[ "$MODE" =~ ^~~~$ ]] && MODE=""
- [[ "$CHANNEL" =~ ^~~~$ ]] && CHANNEL=""
- [[ "$FREQ" =~ ^~~~$ ]] && FREQ=""
- [[ "$SENS" =~ ^~~~$ ]] && SENS=""
- [[ "$RATE" =~ ^~~~$ ]] && RATE=""
- [[ "$RTS" =~ ^~~~$ ]] && RTS=""
- [[ "$FRAG" =~ ^~~~$ ]] && FRAG=""
- [[ "$IWCONFIG" =~ ^~~~$ ]] && IWCONFIG=""
- [[ "$IWSPY" =~ ^~~~$ ]] && IWSPY=""
- [[ "$IWPRIV" =~ ^~~~$ ]] && IWPRIV=""
[[ "$KEY" =~ ^~~~$ ]] && KEY=""
# shellcheck disable=SC2088
PUBKEY=1
fi
- #echo "DEBUG:E:$ESSID N:$NWID M:$MODE C:$CHANNEL F:$FREQ S:$SENS R:$RATE K:$KEY R:$RTS F:$FRAG I:$IWCONFIG I:$IWSPY I:$IWPRIV"
+ #echo "DEBUG:E:$ESSID K:$KEY "
rm -f "$TMP"
fi
done
read -r ESSID <"$TMP" ; rm -f "$TMP"
- [ -z "$MODE" ] && MODE="Managed"
-
else
$DIALOG --inputbox "$MESSAGEW4 $DEVICENAME $MESSAGEW5" 15 50 "$ESSID" 2>"$TMP" || bailout 1
read -r ESSID <"$TMP" ; rm -f "$TMP"
[ -z "$ESSID" ] && ESSID="any"
-
- $DIALOG --inputbox "$MESSAGEW6 $DEVICENAME $MESSAGEW7" 15 50 "$NWID" 2>"$TMP" || bailout 1
- read -r NWID <"$TMP" ; rm -f "$TMP"
-
- $DIALOG --inputbox "$MESSAGEW8 $DEVICENAME $MESSAGEW9" 15 50 "$MODE" 2>"$TMP" || bailout 1
- read -r MODE <"$TMP" ; rm -f "$TMP"
- [ -z "$MODE" ] && MODE="Managed"
-
- $DIALOG --inputbox "$MESSAGEW10 $DEVICENAME $MESSAGEW11" 15 50 "$CHANNEL" 2>"$TMP" || bailout 1
- read -r CHANNEL <"$TMP" ; rm -f "$TMP"
-
- if [ -z "$CHANNEL" ]; then
- $DIALOG --inputbox "$MESSAGEW12 $DEVICENAME $MESSAGEW13" 15 50 "$FREQ" 2>"$TMP" || bailout 1
- read -r FREQ <"$TMP" ; rm -f "$TMP"
- fi
-
fi
WPAON=0
done
rm -f "$TMP"
-
- case $WPA_DEV in
- hostap)
- MODE="Managed"
- ;;
- esac
else
WPASECRET=""
fi
fi
fi
- $DIALOG --inputbox "$MESSAGEW16 $DEVICENAME $MESSAGEW17" 15 50 "$IWCONFIG" 2>"$TMP" || bailout 1
- read -r IWCONFIG <"$TMP" ; rm -f "$TMP"
-
- $DIALOG --inputbox "$MESSAGEW18 $DEVICENAME $MESSAGEW19" 15 50 "$IWSPY" 2>"$TMP" || bailout 1
- read -r IWSPY <"$TMP" ; rm -f "$TMP"
-
- $DIALOG --inputbox "$MESSAGEW20 $DEVICENAME $MESSAGEW21" 15 50 "$IWPRIV" 2>"$TMP" || bailout 1
- read -r IWPRIV <"$TMP" ; rm -f "$TMP"
+ unset IWOURLINE
+ if [ "$iswireless" = "1" ] ; then
+ writeiwline
+ fi
- writeiwline
fi # Setup wireless options?
# Configure VLAN on this interface?
{if(!(found+lastblank)){print}}
END{print "iface '"$DV"' inet dhcp";if("'"$PDV"'"!=""){print "\tvlan-raw-device '"$PDV"'"}}' \
/etc/network/interfaces >"$TMP"
- echo -e "$IWOURLINE" >> "$TMP"
+ case "$DV" in
+ "$WLAN")
+ # write wireless configuration only when we are dealing with a wireless device,
+ # it might be set from a previous configuration run of a wireless device
+ # while the currently configured network device isn't a wireless device
+ echo -e "$IWOURLINE" >> "$TMP"
+ ;;
+ esac
#echo -e "\n\n" >> $TMP
cat "$TMP" >/etc/network/interfaces
rm -f "$TMP"
$DIALOG --inputbox "$MESSAGE8 $DV" 10 45 "${BC:-${IP%.*}.255}" 2>"$TMP" || bailout 1
read -r BC <"$TMP" ; rm -f "$TMP"
- $DIALOG --inputbox "$MESSAGE9" 10 45 "${DG:-${IP%.*}.1}" 2>"$TMP"
+ # if we already have a default route, don't suggest to add another one as that might fail
+ __default_gw=""
+ if ! route -en | grep -q '^0.0.0.0' ; then
+ __default_gw="${DG:-${IP%.*}.1}"
+ fi
+ $DIALOG --inputbox "$MESSAGE9" 10 45 "${__default_gw}" 2>"$TMP"
read -r DG <"$TMP" ; rm -f "$TMP"
if [ -f "/etc/resolv.conf" ]; then
fi
if [ -w /etc/network/interfaces ]; then
+ case "$DV" in
+ "$WLAN")
+ ;;
+ *)
+ # ensure we don't leak the IWOURLINE into the
+ # following awk command line, if we are configuring
+ # a device without wireless capabilities
+ unset IWOURLINE
+ ;;
+ esac
+
awk '/iface/{if(/'"$DV"'/){found=1}else{found=0}}
{if(!found){print}}
END{print "\niface '"$DV"' inet static\n\taddress '"$IP"'\n\tnetmask '"$NM"'\n\tnetwork '"${IP%.*}.0"'";if("'"$BC"'"!=""){print "\tbroadcast '"$BC"'"};if("'"$DG"'"!=""){print "\tgateway '"$DG"'"};if("'"$NS"'"!=""){print "\tdns-nameservers '"$NS"'"};if("'"$PDV"'"!=""){print "\tvlan-raw-device '"$PDV"'"};if("'"$IWOURLINE"'"!=""){print "'"$IWOURLINE"'"};print "\n"}' \
MESSAGE16="Configure VLAN on this interface?"
MESSAGE17="Please enter VLAN id for"
MESSAGEW4="Enter the ESSID for"
-MESSAGEW5="\n\n\n(empty for 'any', not recommended !)\n"
-MESSAGEW6="Enter the NWID (cell identifier)\nfor"
-MESSAGEW7=", if needed\n\n\n"
-MESSAGEW8="Enter the mode for"
-MESSAGEW9="\n\n(Managed(=default), Ad-Hoc, Master,\nRepeater, Secondary, auto)\n"
-MESSAGEW10="Enter channel number for"
-MESSAGEW11="\n\n(0 bis 16, empty for auto or if you want to\n enter the frequency next)\n"
-MESSAGEW12="Enter the frequency for"
-MESSAGEW13="\n\n(e.g 2.412G, empty for auto)"
+MESSAGEW5="\n(empty for 'any', not recommended!)\n"
MESSAGEW14="Enter the encryption key\nfor"
MESSAGEW15="\n\n(empty for cleartext, not recommended !!)"
-MESSAGEW16="Enter additional parameters for\n'iwconfig"
-MESSAGEW17="' if needed, e.g.\n\n\nsens -80 rts 512 frag 512 rate 5.5M"
-MESSAGEW18="Enter additional parameters for\n'iwspy"
-MESSAGEW19="' if needed\n\n\n"
-MESSAGEW20="Enter additional parameters for\n'iwpriv"
-MESSAGEW21="' if needed\n\n\n"
MESSAGEW22="Enable WPA support?"
MESSAGEW23="Enter the WPA passphrase (passphrase must be 8..63 characters) for"
MESSAGEW25="Would you like to store your wep key in it's own private file ("
# first get the device
if [ "$count" -gt 1 ]; then
if "${INTERACTIVE}" ; then
+
+ # Unblock possibly locked devices?
+ if [ $iswireless -gt 0 ] && check_for_blocked_devices; then
+ RF_INFO=$(rfkill | sed 's/$/\\n/') # ensure we have a proper newline layout within dialog
+ if $DIALOG --yesno "Disabled wireless devices detected:\n\n${RF_INFO}\n\nPlease ensure that any possibly existing hardware switches are disabled.\nDo you want to unblock all of them?" 0 0; then
+ rfkill unblock all
+ fi
+ fi
+
rm -f "$TMP"
$DIALOG --menu "$MESSAGE1" 18 60 12 "${DEVICELIST[@]}" "${EXITMENU[@]}" 2>"$TMP" || bailout
read -r DV <"$TMP" ; rm -f "$TMP"