Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # rc.local
- #
- # This script is executed at the end of each multiuser runlevel.
- # Make sure that the script will "exit 0" on success or any other
- # value on error.
- #
- # In order to enable or disable this script just change the execution
- # bits.
- #
- # By default this script does nothing.
- # Print the IP address
- _IP=$(hostname -I) || true
- if [ "$_IP" ]; then
- printf "My IP address is %s\n" "$_IP"
- fi
- # RPi Network Conf Bootstrapper
- createAdHocNetwork(){
- echo "Starting AP Mode"
- echo "Downing wlan0"
- sudo ifconfig wlan0 down
- sleep 1
- echo "Stopping wpa_supplicant"
- sudo killall -9 wpa_supplicant
- sleep 1
- echo "Starting hostapd"
- sudo /etc/init.d/hostapd start
- sleep 1
- echo "Configuring wlan0 IP"
- sudo ifconfig wlan0 10.10.10.1
- sleep 1
- echo "Starting dhcpd on wlan0"
- sudo /usr/sbin/dhcpd wlan0
- echo "Please connect to access point PiFi_Mini_AP"
- echo "Password is pifimini00"
- echo "Enjoy"
- ./etc/airplay_monitor.sh& #start script to monitor airplay and pause mpc when user is connected
- #Uncomment the line below if using an LCD and the PiFi LCD python scripts
- #python /etc/mpc_lcd_info.py& #start lcd script that displays mpd info
- echo "AP network created"
- echo "The server ip is 10.10.10.1"
- }
- echo "======================================================="
- echo "PiFi Network Conf Bootstrapper V0.2"
- echo "======================================================="
- echo "===Based on script by Lasse Christiansen at lcdev.dk==="
- echo "Scanning for known WiFi networks"
- connected=false
- for i in 1 # Initially was for i in 1 2 3 but found it took too long to failover to adhoc
- do
- if connected=false
- then
- echo "Starting supplicant for WPA/WPA2"
- wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1
- echo "Obtaining IP from DHCP"
- if dhclient -1 wlan0
- then
- echo "Connected to WiFi"
- connected=true
- iwconfig 2> /dev/null | grep ESSID > /etc/wpa_supplicant/my_current_ssid.txt
- cat /etc/wpa_supplicant/my_current_ssid.txt
- echo "My IP address is:"
- hostname -I
- ./etc/airplay_monitor.sh& #start script to monitor airplay and pause mpc when user is connected
- #Uncomment the next line if you're using an LCD, make sure you have created the python scripts first though
- #python /etc/mpc_lcd_info.py& #start lcd script that displays mpd info
- break
- else
- echo "DHCP server did not respond with an IP lease (DHCPOFFER)"
- wpa_cli terminate
- break
- fi
- else
- echo "No ssid's listed in your wpa_supplicant.conf files were in range"
- fi
- done
- if ! $connected; then
- createAdHocNetwork
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment