Advertisement
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
- _wlanexist=$(ifconfig | grep wlan) || 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.3"
- echo "======================================================="
- echo "===Based on script by Lasse Christiansen at lcdev.dk==="
- echo "Checking if USB Wifi card is present"
- connected=false
- if [ "$_wlanexist" ]; then
- echo "USB Wifi is present, scanning for known WiFi networks"
- 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
- else
- echo "No wireless cards detected, trying wired connection"
- if dhclient -1 eth0
- then
- connected=true
- echo "Connected on ETH0"
- if [ "$_IP" ]; then
- printf "My IP address is %s\n" "$_IP"
- else
- echo "Unable to obtain IP on ETH0"
- fi
- fi
- fi
- if ! $connected; then
- if [ "$_wlanexist" ]; then
- createAdHocNetwork
- else
- echo "No wireless or wired connections could be established"
- sudo python /etc/no_connection_lcd.py&
- fi
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement