Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added wifi config #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions raspi-config
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,105 @@ do_advanced_menu() {
fi
}

do_wifi() {

wifidevice=wlan0
WPAFILE=/etc/wpa_supplicant/wpa_supplicant.conf

{
iwlist $wifidevice scan | grep 'ESSID' | sed -e 's/.*ESSID:"\([^"]\+\)".*/ \1/' > /tmp/ap_list.txt
} | whiptail --gauge "Scanning Wifi, please wait" 5 50 10

echo "whiptail --title \"Choose SSID, or enter manually\" \\" > /tmp/choose_ap.sh
echo "--radiolist \"Choose SSID\" \\" >> /tmp/choose_ap.sh

LINES=`wc -l < /tmp/ap_list.txt`
LINES=$((${LINES}+1))
echo "10 60 ${LINES} \\" >> /tmp/choose_ap.sh
for LINE in `cat /tmp/ap_list.txt`
do
echo "$LINE '' off \\" >> /tmp/choose_ap.sh
done
echo "Enter\ manually '' on 2>/tmp/ssid.ans" >>/tmp/choose_ap.sh

chmod 777 /tmp/choose_ap.sh
. /tmp/choose_ap.sh

if [ $? -ne 0 ]; then return 0; fi

SSID=`cat /tmp/ssid.ans`
if [ "$SSID" = "Enter manually" ]; then
SSID=$(whiptail --inputbox "SSID Name" 20 70 3>&1 1>&2 2>&3)
if [ -z $SSID ]; then return 0 ; fi
fi

ENCRYPTION=$(whiptail --title "Encryption" --menu "Encryption for network: $SSID " $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"1" "WPA/WPA2" \
"2" "WEP (hex)" \
"3" "WEP (ascii)" \
"4" "None" \
3>&1 1>&2 2>&3)

if [ $? -ne 0 ]; then return 0; fi

WPANEW=/tmp/wpanew.conf
WPATMP=/tmp/wpa.conf

case $ENCRYPTION in
'1')
PASSPHRASE=$(whiptail --inputbox "WPA Passphrase for $SSID" 20 70 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then return 0; fi
CRYPTPASS=$(wpa_passphrase $SSID $PASSPHRASE | grep -v "^#" | grep -v "#psk=")
PASSERROR="Passphrase must be 8..63 characters"
if [ "$CRYPTPASS" != "$PASSERROR" ]; then
echo "$CRYPTPASS" > $WPANEW
else
whiptail --msgbox "ERROR: $PASSERROR" 20 70 1
return 0;
fi
;;
'2')
PASSPHRASE=$(whiptail --inputbox "WEP key (Hex)" 20 70 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then return 0; fi

echo "network={
ssid=\"$SSID\"
key_mgmt=NONE
wep_key0=$PASSPHRASE
}" > $WPANEW
;;
'3')
PASSPHRASE=$(whiptail --inputbox "WEP key (ascii)" 20 70 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then return 0; fi

echo "network={
ssid=\"$SSID\"
key_mgmt=NONE
wep_key0=\"$PASSPHRASE\"
}" > $WPANEW
;;
'4')
echo "network={
ssid=\"$SSID\"
key_mgmt=NONE
}" > $WPANEW
;;
esac
# Remove previous matching SSID config first
perl -00 -pe "s/network=\{[^}]*ssid=\"$SSID\"*[^}]*\}//g" $WPAFILE > $WPATMP
# append /merge new config at end of config file
cat $WPATMP $WPANEW > $WPAFILE

whiptail --msgbox "Wifi settings updated for SSID: $SSID" 20 60 1

# connect right now ?
#wpa_supplicant -B -i$wifidevice -c $WPAFILE
#dhclient $wifidevice -1

}


# $1 is 0 to disable camera, 1 to enable it

#
# Interactive use loop
Expand All @@ -591,7 +690,8 @@ while true; do
"6 Add to Rastrack" "Add this Pi to the online Raspberry Pi Map (Rastrack)" \
"7 Overclock" "Configure overclocking for your Pi" \
"8 Advanced Options" "Configure advanced settings" \
"9 About raspi-config" "Information about this configuration tool" \
"9 Setup Wifi" "Configure Wifi settings" \
"10 About raspi-config" "Information about this configuration tool" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
Expand All @@ -606,7 +706,8 @@ while true; do
6\ *) do_rastrack ;;
7\ *) do_overclock ;;
8\ *) do_advanced_menu ;;
9\ *) do_about ;;
9\ *) do_wifi ;;
10\ *) do_about ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
else
Expand Down