document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2. #
  3. # rc.local
  4. #
  5. # This script is executed at the end of each multiuser runlevel.
  6. # Make sure that the script will "exit 0" on success or any other
  7. # value on error.
  8. #
  9. # In order to enable or disable this script just change the execution
  10. # bits.
  11. #
  12. # By default this script does nothing.
  13.  
  14. # Print the IP address
  15. _IP=$(hostname -I) || true
  16. _wlanexist=$(ifconfig | grep wlan) || true
  17.  
  18. if [ "$_IP" ]; then
  19. printf "My IP address is %s\\n" "$_IP"
  20. fi
  21.  
  22. # RPi Network Conf Bootstrapper
  23.  
  24. createAdHocNetwork(){
  25. echo "Starting AP Mode"
  26. echo "Downing wlan0"
  27. sudo ifconfig wlan0 down
  28. sleep 1
  29. echo "Stopping wpa_supplicant"
  30. sudo killall -9 wpa_supplicant
  31. sleep 1
  32. echo "Starting hostapd"
  33. sudo /etc/init.d/hostapd start
  34. sleep 1
  35. echo "Configuring wlan0 IP"
  36. sudo ifconfig wlan0 10.10.10.1
  37. sleep 1
  38. echo "Starting dhcpd on wlan0"
  39. sudo /usr/sbin/dhcpd wlan0
  40. echo "Please connect to access point PiFi_Mini_AP"
  41. echo "Password is pifimini00"
  42. echo "Enjoy"
  43. ./etc/airplay_monitor.sh& #start script to monitor airplay and pause mpc when user is connected
  44. #Uncomment the line below if using an LCD and the PiFi LCD python scripts
  45. python /etc/mpc_lcd_info.py& #start lcd script that displays mpd info
  46. echo "AP network created"
  47. echo "The server ip is 10.10.10.1"
  48. }
  49.  
  50. echo "======================================================="
  51. echo "PiFi Network Conf Bootstrapper V0.3"
  52. echo "======================================================="
  53. echo "===Based on script by Lasse Christiansen at lcdev.dk==="
  54. echo "Checking if USB Wifi card is present"
  55. connected=false
  56. if [ "$_wlanexist" ]; then
  57. echo "USB Wifi is present, scanning for known WiFi networks"
  58. for i in 1 # Initially was for i in 1 2 3 but found it took too long to failover to adhoc
  59. do
  60. if connected=false
  61. then
  62. echo "Starting supplicant for WPA/WPA2"
  63. wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null 2>&1
  64. echo "Obtaining IP from DHCP"
  65. if dhclient -1 wlan0
  66. then
  67. echo "Connected to WiFi"
  68. connected=true
  69. iwconfig 2> /dev/null | grep ESSID > /etc/wpa_supplicant/my_current_ssid.txt
  70. cat /etc/wpa_supplicant/my_current_ssid.txt
  71. echo "My IP address is:"
  72. hostname -I
  73. ./etc/airplay_monitor.sh& #start script to monitor airplay and pause mpc when user is connected
  74. #Uncomment the next line if you're using an LCD, make sure you have created the python scripts first though
  75. python /etc/mpc_lcd_info.py& #start lcd script that displays mpd info
  76. break
  77. else
  78. echo "DHCP server did not respond with an IP lease (DHCPOFFER)"
  79. wpa_cli terminate
  80. break
  81. fi
  82. else
  83. echo "No ssid's listed in your wpa_supplicant.conf files were in range"
  84. fi
  85. done
  86. else
  87. echo "No wireless cards detected, trying wired connection"
  88. if dhclient -1 eth0
  89. then
  90. connected=true
  91. echo "Connected on ETH0"
  92. if [ "$_IP" ]; then
  93. printf "My IP address is %s\\n" "$_IP"
  94. else
  95. echo "Unable to obtain IP on ETH0"
  96. fi
  97. fi
  98. fi
  99.  
  100. if ! $connected; then
  101. if [ "$_wlanexist" ]; then
  102. createAdHocNetwork
  103. else
  104. echo "No wireless or wired connections could be established"
  105. sudo python /etc/no_connection_lcd.py&
  106. fi
  107. fi
  108.  
  109. exit 0
');