diff --git a/hostapd.conf b/hostapd.conf index 4ef2281..8c6e7c7 100644 --- a/hostapd.conf +++ b/hostapd.conf @@ -1,10 +1,5 @@ interface=wlan0 -#driver= -#driver= -#driver= - -# YOUR BRIDGE NAME -#bridge=br0 +#driver # YOUR COUNTRY HERE country_code=FR @@ -17,7 +12,7 @@ ssid=testspot22 hw_mode=g # CHANGE CHANNEL EVENTUALLY -channel= 2 +channel=2 wme_enabled=0 macaddr_acl=0 @@ -31,4 +26,4 @@ wpa_passphrase=testcode wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP -rsn_pairwise=CCMP +rsn_pairwise=CCMP \ No newline at end of file diff --git a/install_pispot.sh b/install_pispot.sh index 9bb9c44..466d57f 100755 --- a/install_pispot.sh +++ b/install_pispot.sh @@ -15,66 +15,13 @@ DEFT='\e[00m' RED='\e[00;31m' YELLOW='\e[00;33m' -function checkfileExists { -#echo $1 -if [ -f $1*.deb ]; then - #echo "File not found!" - return 1 -else - #echo "fILE FOUND" - return 0 -fi -} - -function checkInternet { -wget -q --tries=3 --timeout=5 http://google.com > /dev/null -if [[ ! $? -eq 1 ]]; then - return 0 -fi -} - #check current user privileges (( `id -u` )) && echo -e "${RED}This script MUST be ran with root privileges, try prefixing with sudo. i.e sudo $0" && exit 1 clear #check for hostapd - -function installPackage { -echo -e "${DEFT}First, lets see if the "$1" packages are installed...\n" - -dpkg -l $1 | grep ^ii > /dev/null 2>&1 -INSTALLED=$? - -if [ $INSTALLED == '0' ]; then - echo -e "${GREEN}$1 is installed...moving on\n" - else - echo -e "${RED}"$1" is not installed...will install now\n" - echo $1* - if checkfileExists $1*;then - echo -e "${DEFT}Installing locally" - dpkg -i $1* - else - echo -e "${DEFT}No local copy found...trying for install from the repo's" - - if checkInternet; then - echo -e "${RED}Internet not reachable" - exit 1 - else - echo "Installing from repos" - apt-get install $1* - fi -fi -fi - -} - -if [[ `cat /etc/*-release | grep jessie` ]] -then - - installPackage req_files/isc-dhcp-server_4.3.1-6_armhf.deb -else - installPackage req_files/isc-dhcp-server_4.2.2.dfsg.1-5+deb70u6_armhf.deb -fi +apt-get update +apt-get install isc-dhcp-server isc-dhcp-common hostapd libnl-dev #installed, so now for configuration diff --git a/req_files/isc-dhcp-server_4.2.2.dfsg.1-5+deb70u6_armhf.deb b/req_files/isc-dhcp-server_4.2.2.dfsg.1-5+deb70u6_armhf.deb deleted file mode 100644 index 546b547..0000000 Binary files a/req_files/isc-dhcp-server_4.2.2.dfsg.1-5+deb70u6_armhf.deb and /dev/null differ diff --git a/req_files/isc-dhcp-server_4.3.1-6_armhf.deb b/req_files/isc-dhcp-server_4.3.1-6_armhf.deb deleted file mode 100644 index 77f9baa..0000000 Binary files a/req_files/isc-dhcp-server_4.3.1-6_armhf.deb and /dev/null differ diff --git a/start_pispot.sh b/start_pispot.sh index 9eb852e..6857e7c 100755 --- a/start_pispot.sh +++ b/start_pispot.sh @@ -1,54 +1,48 @@ #!/bin/bash -#Pi SSID Scanner -# Part of PiSpot: https://github.com/heeed/hotpi +#Pi SSID Scanner +# Part of PiSpot: https://github.com/heeed/hotpi # based on code by Lasse Christiansen http://lcdev.dk - getSSIDdetails(){ echo "pispot: extracting login details">/dev/kmsg OLDIFS=$IFS - ssid=${ssid[@]} - IFS=',' read req_ssid req_psk comment <<<"$ssid" + ssid=${ssid[@]} + IFS=',' read req_ssid req_psk comment <<<"$ssid" } getSSID() { - if [ ! -f $1 ]; then echo "pispot: SSID's not found...exiting">/dev/kmsg - exit 1 - else - i=0 - while read line # Read a line - do - ssids[i]=$line # Put it into the array - i=$(($i + 1)) - done < $1 + exit 1 + else + i=0 + while read line # Read a line + do + ssids[i]=$line # Put it into the array + i=$(($i + 1)) + done < $1 fi } getHotspotSSID(){ - - if [ ! -f $1 ]; then - echo "pispot: SSID's not found...exiting">/dev/kmsg - exit 1 - else - while read line + if [ ! -f $1 ]; then + echo "pispot: SSID's not found...exiting">/dev/kmsg + exit 1 + else + while read line do if [[ $line =~ $'\r' ]]; then - line2=$(echo $line | sed $'s/\r//') + line2=$(echo $line | sed $'s/\r//') line=$line2 - fi - - OLDIFS=$IFS - IFS=',' read hotspot_SSID hotspot_IP hotspot_PSK <<< "$line" + fi + OLDIFS=$IFS + IFS=',' read hotspot_SSID hotspot_IP hotspot_PSK <<< "$line" done < $1 - fi + fi } - wlanDHCP(){ - echo "pispot: swapping in $1 interfaces file">/dev/kmsg IP4_INT=wlan0 IP4_CONF_TYPE=dhcp @@ -59,11 +53,9 @@ wlanDHCP(){ auto lo iface lo inet loopback - allow-hotplug eth0 iface eth0 inet dhcp - auto $IP4_INT iface $IP4_INT inet $IP4_CONF_TYPE wpa-ssid $req_ssid @@ -74,25 +66,24 @@ wpa-psk $req_psk wlanStatic(){ + IP4_INT=wlan0 + IP4_CONF_TYPE=static + IP4_ADDRESS=$hotspot_IP + IP4_NETMASK=255.255.255.0 -IP4_INT=wlan0 -IP4_CONF_TYPE=static -IP4_ADDRESS=$hotspot_IP -IP4_NETMASK=255.255.255.0 - -IP4_NETWORK=${IP4_ADDRESS%?}0 -IP4_BROADCAST=${IP4_ADDRESS%?}255 -IP4_GATEWAY=$hotspot_IP + IP4_NETWORK=${IP4_ADDRESS%?}0 + IP4_BROADCAST=${IP4_ADDRESS%?}255 + IP4_GATEWAY=$hotspot_IP -mv /etc/network/interfaces /etc/network/interfaces.bak + mv /etc/network/interfaces /etc/network/interfaces.bak -echo " + echo " auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet dhcp - + auto $IP4_INT iface $IP4_INT inet $IP4_CONF_TYPE address $IP4_ADDRESS @@ -103,43 +94,44 @@ gateway $IP4_GATEWAY } createAdHocNetwork(){ - + usblist=`lsusb` getHotspotSSID "/boot/hotspot.txt" - echo "pispot: creating hotspot">/dev/kmsg - sed -i '/driver/c#driver=' /etc/hostapd/hostapd.conf - sed -i '/ssid=/cssid='$hotspot_SSID'' /etc/hostapd/hostapd.conf - sed -i '/wpa_passphrase=/cwpa_passphrase='$hotspot_PSK'' /etc/hostapd/hostapd.conf - - sed -i '/subnet /,$d' /etc/dhcp/dhcpd.conf + if [[ $usblist == *148f:5370* ]];then + sed -i '/driver/cdriver=nl80211' /etc/hostapd/hostapd.conf + else + sed -i '/driver/c#driver=' /etc/hostapd/hostapd.conf + fi + sed -i '/ssid=/cssid='$hotspot_SSID'' /etc/hostapd/hostapd.conf + sed -i '/wpa_passphrase=/cwpa_passphrase='$hotspot_PSK'' /etc/hostapd/hostapd.conf + sed -i '/subnet /,$d' /etc/dhcp/dhcpd.conf echo 'subnet '${hotspot_IP%?}0 ' netmask 255.255.255.0 { - range '${hotspot_IP%?}5' '${hotspot_IP%?}100'; -}' >> /etc/dhcp/dhcpd.conf + range '${hotspot_IP%?}5' '${hotspot_IP%?}100'; +}' >> /etc/dhcp/dhcpd.conf rm /usr/sbin/hostapd - usblist=`lsusb` killall hostapd - - if [[ $usblist == *0bda:8191* ]]||[[ $usblist == *0bda:8176* ]];then - echo "pispot: rtl8188CUS detected, using alternative hostapd">/dev/kmsg - ln -s /usr/sbin/hostapd8 /usr/sbin/hostapd - else - echo "pispot: Repository hostapd to be used" > /dev/kmsg - ln -s /usr/sbin/hostapd.other /usr/sbin/hostapd - fi - + + if [[ $usblist == *0bda:8191* ]]||[[ $usblist == *0bda:8176* ]];then + echo "pispot: rtl8188CUS detected, using alternative hostapd">/dev/kmsg + ln -s /usr/sbin/hostapd8 /usr/sbin/hostapd + else + echo "pispot: Repository hostapd to be used" > /dev/kmsg + ln -s /usr/sbin/hostapd.other /usr/sbin/hostapd + fi + wlanStatic ifdown wlan0 ifup wlan0 ifdown eth0 ifup eth0 -echo -e "networks up and down\n" -echo -e "starting dhcpd \n" + echo -e "networks up and down\n" + echo -e "starting dhcpd \n" /etc/init.d/isc-dhcp-server start -echo -e "dhcp started\n" -echo -e "hostapd coming up\n" + echo -e "dhcp started\n" + echo -e "hostapd coming up\n" /usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -echo -e "hostapd up\n" + echo -e "hostapd up\n" } @@ -151,41 +143,40 @@ rm /var/lib/dhcp/dhcpd.leases~ needHotspot=1 for ssid in "${ssids[@]}" do - getSSIDdetails $ssid - echo "pispot; looking for $req_ssid">/dev/kmsg - if iwlist wlan0 scan | grep $req_ssid > /dev/null - then - ifdown --force wlan0 - wlanDHCP $req_ssid > /dev/null - ifup wlan0 - if dhclient -1 wlan0 > /dev/null - then - echo "pispot: Connected to hotspot: $req_ssid" > /dev/kmsg - needHotspot=0 - break - else - echo "pispot: $req_ssid Hotspot not found" > /dev/kmsg - wpa_cli terminate - break - fi - fi + getSSIDdetails $ssid + echo "pispot; looking for $req_ssid">/dev/kmsg + if iwlist wlan0 scan | grep $req_ssid > /dev/null + then + ifdown --force wlan0 + wlanDHCP $req_ssid > /dev/null + ifup wlan0 + if dhclient -1 wlan0 > /dev/null + then + echo "pispot: Connected to hotspot: $req_ssid" > /dev/kmsg + needHotspot=0 + break + else + echo "pispot: $req_ssid Hotspot not found" > /dev/kmsg + wpa_cli terminate + break + fi + fi done if [[ `cat /etc/*-release | grep jessie` ]] -then +then systemctl disable avahi-daemon.service fi if [[ "$needHotspot" -eq 1 ]] then - echo "pispot: no known wireless networks found,,,starting a hotspot">/dev/kmsg - if createAdHocNetwork; then - echo "pispot: hotspot created" > /dev/kmsg - /etc/init.d/isc-dhcp-server start - else - echo "pispot: hotspot failed" > /dev/kmsg - fi + echo "pispot: no known wireless networks found,,,starting a hotspot">/dev/kmsg + if createAdHocNetwork; then + echo "pispot: hotspot created" > /dev/kmsg + /etc/init.d/isc-dhcp-server start + else + echo "pispot: hotspot failed" > /dev/kmsg + fi fi -exit 0 - +exit 0 \ No newline at end of file diff --git a/uninstall_pispot.sh b/uninstall_pispot.sh index 2ffb089..74fc39f 100755 --- a/uninstall_pispot.sh +++ b/uninstall_pispot.sh @@ -16,7 +16,7 @@ cp /usr/share/pispot/backup/dhclient.conf /etc/dhcp/dhclient.conf rm -rf /etc/hostapd sed -i '/start_pispot.sh/d' /etc/rc.local -apt-get purge -y hostapd isc-dhcp-server +apt-get remove --purge -y hostapd isc-dhcp-server isc-dhcp-common libnl-dev if [[ `cat /etc/*-release | grep jessie` ]] then