Impemented Wifi switching

pull/51/head
davecrump 2016-12-06 12:08:30 +00:00
rodzic bf8fd00428
commit 217486330b
12 zmienionych plików z 261 dodań i 24 usunięć

16
scripts/configs/button.bashrc 100644 → 100755
Wyświetl plik

@ -102,11 +102,21 @@ if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
## Uncomment to enable tidy shutdown by hardware button
## Tidy shutdown by hardware button
## Button to 3.3v on physical pin 15. LED to indicate still running on pin 13
## See https://github.com/philcrump/pi-sdn
## sudo pi-sdn 3 2 &
## Calls .pi-sdn if present and runs "sudo pi-sdn 3 2 &"
if [ -f ~/.pi-sdn ]; then
. ~/.pi-sdn
fi
./rpidatv/scripts/rpibutton.sh
## Facility to Disable WiFi
## Calls .wifi_off if present and runs "sudo ifconfig wlan0 down"
if [ -f ~/.wifi_off ]; then
. ~/.wifi_off
fi
./rpidatv/scripts/rpibutton.sh

15
scripts/configs/console.bashrc 100644 → 100755
Wyświetl plik

@ -113,9 +113,20 @@ if ! shopt -oq posix; then
fi
#con2fbmap 1 1
## Uncomment to enable tidy shutdown by hardware button
## Tidy shutdown by hardware button
## Button to 3.3v on physical pin 15. LED to indicate still running on pin 13
## See https://github.com/philcrump/pi-sdn
## sudo pi-sdn 3 2 &
## Calls .pi-sdn if present and runs "sudo pi-sdn 3 2 &"
if [ -f ~/.pi-sdn ]; then
. ~/.pi-sdn
fi
## Facility to Disable WiFi
## Calls .wifi_off if present and runs "sudo ifconfig wlan0 down"
if [ -f ~/.wifi_off ]; then
. ~/.wifi_off
fi
./rpidatv/scripts/menu.sh menu

16
scripts/configs/console_tx.bashrc 100644 → 100755
Wyświetl plik

@ -113,9 +113,21 @@ if ! shopt -oq posix; then
fi
#con2fbmap 1 1
## Uncomment to enable tidy shutdown by hardware button
## Tidy shutdown by hardware button
## Button to 3.3v on physical pin 15. LED to indicate still running on pin 13
## See https://github.com/philcrump/pi-sdn
## sudo pi-sdn 3 2 &
## Calls .pi-sdn if present and runs "sudo pi-sdn 3 2 &"
if [ -f ~/.pi-sdn ]; then
. ~/.pi-sdn
fi
## Facility to Disable WiFi
## Calls .wifi_off if present and runs "sudo ifconfig wlan0 down"
if [ -f ~/.wifi_off ]; then
. ~/.wifi_off
fi
./rpidatv/scripts/menu.sh

15
scripts/configs/display.bashrc 100644 → 100755
Wyświetl plik

@ -102,10 +102,21 @@ if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
## Uncomment to enable tidy shutdown by hardware button
## Tidy shutdown by hardware button
## Button to 3.3v on physical pin 15. LED to indicate still running on pin 13
## See https://github.com/philcrump/pi-sdn
## sudo pi-sdn 3 2 &
## Calls .pi-sdn if present and runs "sudo pi-sdn 3 2 &"
if [ -f ~/.pi-sdn ]; then
. ~/.pi-sdn
fi
## Facility to Disable WiFi
## Calls .wifi_off if present and runs "sudo ifconfig wlan0 down"
if [ -f ~/.wifi_off ]; then
. ~/.wifi_off
fi
sudo killall fbcp
fbcp &

Wyświetl plik

@ -102,10 +102,21 @@ if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
## Uncomment to enable tidy shutdown by hardware button
## Tidy shutdown by hardware button
## Button to 3.3v on physical pin 15. LED to indicate still running on pin 13
## See https://github.com/philcrump/pi-sdn
## sudo pi-sdn 3 2 &
## Calls .pi-sdn if present and runs "sudo pi-sdn 3 2 &"
if [ -f ~/.pi-sdn ]; then
. ~/.pi-sdn
fi
## Facility to Disable WiFi
## Calls .wifi_off if present and runs "sudo ifconfig wlan0 down"
if [ -f ~/.wifi_off ]; then
. ~/.wifi_off
fi
sudo killall fbcp
fbcp &

16
scripts/configs/prompt.bashrc 100644 → 100755
Wyświetl plik

@ -112,7 +112,19 @@ if ! shopt -oq posix; then
fi
fi
## Uncomment to enable tidy shutdown by hardware button
## Tidy shutdown by hardware button
## Button to 3.3v on physical pin 15. LED to indicate still running on pin 13
## See https://github.com/philcrump/pi-sdn
## sudo pi-sdn 3 2 &
## Calls .pi-sdn if present and runs "sudo pi-sdn 3 2 &"
if [ -f ~/.pi-sdn ]; then
. ~/.pi-sdn
fi
## Facility to Disable WiFi
## Calls .wifi_off if present and runs "sudo ifconfig wlan0 down"
if [ -f ~/.wifi_off ]; then
. ~/.wifi_off
fi

Wyświetl plik

@ -0,0 +1,6 @@
## called by .bashrc at log-on to diable wifi
## If this file is not in ~, then wifi is allowed to start
sudo ifconfig wlan0 down
## Only way to restart wifi is to reboot

Wyświetl plik

@ -0,0 +1,4 @@
##STARTNW
## No network loaded
##ENDNW

Wyświetl plik

@ -0,0 +1,4 @@
network={
ssid="PixienetG"
psk=b7a2fc71b648e214d337ca533c8c506167fc8f463477c50df379067cc3341912
}

Wyświetl plik

@ -578,7 +578,7 @@ do_freq_setup()
FREQ_OUTPUT=$(get_config_var freqoutput $CONFIGFILE)
FREQ=$(whiptail --inputbox "$StrOutputRFFreqContext" 8 78 $FREQ_OUTPUT --title "$StrOutputRFFreqTitle" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
set_config_var freqoutput "$FREQ" $CONFIGFILE
set_config_var freqoutput "$FREQ" $CONFIGFILE
fi
}
@ -850,18 +850,62 @@ CURRENTIP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '(
whiptail --title "IP" --msgbox "$CURRENTIP" 8 78
}
do_WiFi_setup()
{
$PATHSCRIPT"/wifisetup.sh"
}
do_WiFi_Off()
{
sudo ifconfig wlan0 down ## Disable it now
cp $PATHCONFIGS"/text.wifi_off" /home/pi/.wifi_off ## Disable at start-up
}
do_Enable_DigiThin()
{
exit
}
do_Exit()
{
exit
}
do_Reboot()
{
sudo reboot now
}
do_Shutdown()
{
sudo shutdown now
}
do_system_setup()
{
menuchoice=$(whiptail --title "$StrSystemTitle" --menu "$StrSystemContext" 16 78 5 \
"1 Autostart" "$StrAutostartMenu" \
"2 Display" "$StrDisplayMenu" \
"3 IP" "$StrIPMenu" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_autostart_setup ;;
2\ *) do_display_setup ;;
3\ *) do_IP_setup ;;
esac
menuchoice=$(whiptail --title "$StrSystemTitle" --menu "$StrSystemContext" 16 78 9 \
"1 Autostart" "$StrAutostartMenu" \
"2 Display" "$StrDisplayMenu" \
"3 IP" "$StrIPMenu" \
"4 WiFi Set-up" "SSID and password" \
"5 WiFi Off" "Turn the WiFi Off" \
"6 Enable DigiThin" "Not Implemented Yet" \
"7 Exit Menu" "Go to Command Line" \
"8 Reboot" "Reboot the Raspberry Pi" \
"9 ShutDown" "Shutdown for Safe Power Off" \
3>&2 2>&1 1>&3)
case "$menuchoice" in
1\ *) do_autostart_setup ;;
2\ *) do_display_setup ;;
3\ *) do_IP_setup ;;
4\ *) do_WiFi_setup ;;
5\ *) do_WiFi_Off ;;
6\ *) do_Enable_DigiThin ;;
7\ *) do_Exit ;;
8\ *) do_Reboot ;;
9\ *) do_Shutdown ;;
esac
}
do_language_setup()

Wyświetl plik

@ -20,3 +20,4 @@ pidaudio=257
display=Waveshare
menulanguage=en
analogcamname=/dev/video0
startup=Prompt

Wyświetl plik

@ -0,0 +1,111 @@
#!/bin/bash
# Script used to set up WiFi from rpidatv menu
reset # Clear the screen
# Check that wifi has not been disabled
if [ -f ~/.wifi_off ]; then
printf "WiFi was disabled at start-up.\n"
printf "You cannot set up the WiFi until it is re-enabled.\n"
printf "Do you want to re-enable it and reboot imediately?\n"
read -n 1
printf "\n"
if [ "$REPLY" = "Y" ]; then
echo "rebooting"
rm ~/.wifi_off
sudo reboot now
else
if [ "$REPLY" = "y" ]; then
echo "rebooting"
rm ~/.wifi_off
sudo reboot now
else
exit
fi
fi
fi
## Wifi is enabled so
## List the available networks
printf "The following networks are available:\n"
printf "\n"
sudo iwlist wlan0 scan | grep 'ESSID'
printf "\n"
printf "Type the SSID of the network that you want to connect to (without qoutes) and press enter\n"
printf "\n"
read SSID
printf "\n"
printf "Type the network password and press enter\n"
printf "Characters will not be displayed\n"
printf "\n"
stty -echo
read PW
stty echo
printf "\nWorking....\n\n"
stty -echo
PSK_TEXT=$(wpa_passphrase "$SSID" "$PW" | grep 'psk=' | grep -v '#psk')
PATHCONFIGS="/home/pi/rpidatv/scripts/configs" ## Path to config files
## Build text for supplicant file
rm $PATHCONFIGS"/wpa_text.txt"
echo -e "network={" >> $PATHCONFIGS"/wpa_text.txt"
echo -e " ssid="\"""$SSID"\"" >> $PATHCONFIGS"/wpa_text.txt"
echo -e " "$PSK_TEXT >> $PATHCONFIGS"/wpa_text.txt"
echo -e "}" >> $PATHCONFIGS"/wpa_text.txt"
## Copy the existing wpa_supplicant file to work on
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf $PATHCONFIGS"/wpa_supcopy.txt"
sudo chown pi:pi $PATHCONFIGS"/wpa_supcopy.txt"
## Define the parameters for the replace script
lead='^##STARTNW' ## Marker for start of inserted text
tail='^##ENDNW' ## Marker for end of inserted text
CHANGEFILE=$PATHCONFIGS"/wpa_supcopy.txt" ## File requiring added text
APPENDFILE=$PATHCONFIGS"/wpa_markers.txt" ## File containing both markers
TRANSFILE=$PATHCONFIGS"/transfer.txt" ## File used for transfer
INSERTFILE=$PATHCONFIGS"/wpa_text.txt" ## File to be included
grep -q "$lead" "$CHANGEFILE" ## Is the first marker already present?
if [ $? -ne 0 ]; then
sudo bash -c 'cat '$APPENDFILE' >> '$CHANGEFILE' ' ## If not append the markers
fi
## Replace whatever is between the markers with the insert text
sed -e "/$lead/,/$tail/{ /$lead/{p; r $INSERTFILE
}; /$tail/p; d }" $CHANGEFILE >> $TRANSFILE
sudo cp "$TRANSFILE" "$CHANGEFILE" ## Copy from the transfer file
rm $TRANSFILE ## Delete the transfer file
## Give the file root ownership and copy it back over the original
sudo chown root:root $PATHCONFIGS"/wpa_supcopy.txt"
sudo cp $PATHCONFIGS"/wpa_supcopy.txt" /etc/wpa_supplicant/wpa_supplicant.conf
sudo rm $PATHCONFIGS"/wpa_supcopy.txt"
stty echo
##bring wifi down and up again
sudo ifdown wlan0
sudo ifup wlan0
printf "WiFi Configured\n"
sleep 1
exit