|  | @@ -40,6 +40,7 @@ WIFI_INTERFACE=wlan0
 | 
	
		
			
			| 40 | 40 |  WIFI_TYPE='wpa2-psk'
 | 
	
		
			
			| 41 | 41 |  WIFI_SSID=
 | 
	
		
			
			| 42 | 42 |  WIFI_PASSPHRASE=
 | 
	
		
			
			|  | 43 | +WIFI_HOTSPOT='no'
 | 
	
		
			
			| 43 | 44 |  
 | 
	
		
			
			| 44 | 45 |  function wifi_get_psk {
 | 
	
		
			
			| 45 | 46 |      ssid=$1
 | 
	
	
		
			
			|  | @@ -49,6 +50,90 @@ function wifi_get_psk {
 | 
	
		
			
			| 49 | 50 |      echo $psk
 | 
	
		
			
			| 50 | 51 |  }
 | 
	
		
			
			| 51 | 52 |  
 | 
	
		
			
			|  | 53 | +function hotspot_off {
 | 
	
		
			
			|  | 54 | +    if [ ! -f /etc/hostapd/hostapd.conf ]; then
 | 
	
		
			
			|  | 55 | +        return
 | 
	
		
			
			|  | 56 | +    fi
 | 
	
		
			
			|  | 57 | +    systemctl stop hostapd
 | 
	
		
			
			|  | 58 | +
 | 
	
		
			
			|  | 59 | +    rm /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 60 | +
 | 
	
		
			
			|  | 61 | +    if [ -f /etc/network/interfaces_old ]; then
 | 
	
		
			
			|  | 62 | +        cp /etc/network/interfaces_old /etc/network/interfaces
 | 
	
		
			
			|  | 63 | +    else
 | 
	
		
			
			|  | 64 | +        echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
 | 
	
		
			
			|  | 65 | +        echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
 | 
	
		
			
			|  | 66 | +        echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
 | 
	
		
			
			|  | 67 | +    fi
 | 
	
		
			
			|  | 68 | +    
 | 
	
		
			
			|  | 69 | +    systemctl restart network-manager
 | 
	
		
			
			|  | 70 | +}
 | 
	
		
			
			|  | 71 | +
 | 
	
		
			
			|  | 72 | +function hotspot_on {
 | 
	
		
			
			|  | 73 | +    if [ ! -f /etc/default/hostapd ]; then
 | 
	
		
			
			|  | 74 | +        echo $'/etc/default/hostapd was not found'
 | 
	
		
			
			|  | 75 | +        exit 67241
 | 
	
		
			
			|  | 76 | +    fi
 | 
	
		
			
			|  | 77 | +    if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
 | 
	
		
			
			|  | 78 | +        echo $'Wifi hotspot passphrase is too short'
 | 
	
		
			
			|  | 79 | +        exit 25719
 | 
	
		
			
			|  | 80 | +    fi
 | 
	
		
			
			|  | 81 | +    
 | 
	
		
			
			|  | 82 | +    sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
 | 
	
		
			
			|  | 83 | +
 | 
	
		
			
			|  | 84 | +    echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 85 | +    echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 86 | +    echo '' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 87 | +    echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 88 | +    echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 89 | +    echo '' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 90 | +    echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 91 | +    echo "country_code=UK" >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 92 | +    echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 93 | +    echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 94 | +    echo 'channel=6' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 95 | +    echo 'wpa=2' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 96 | +    echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 97 | +    echo '' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 98 | +    echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 99 | +    echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 100 | +    echo '' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 101 | +    echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 102 | +    echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 103 | +    echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 104 | +    echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 105 | +    echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 106 | +    echo '' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 107 | +    echo '## Shared Key Authentication ##'
 | 
	
		
			
			|  | 108 | +    echo 'auth_algs=1'
 | 
	
		
			
			|  | 109 | +    echo '' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 110 | +    echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 111 | +    echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
 | 
	
		
			
			|  | 112 | +
 | 
	
		
			
			|  | 113 | +    if ! grep -q "# Hotspot" /etc/network/interfaces; then
 | 
	
		
			
			|  | 114 | +        cp /etc/network/interfaces /etc/network/interfaces_old
 | 
	
		
			
			|  | 115 | +    fi
 | 
	
		
			
			|  | 116 | +    
 | 
	
		
			
			|  | 117 | +    echo '# Hotspot' > /etc/network/interfaces
 | 
	
		
			
			|  | 118 | +    echo 'auto lo br0' >> /etc/network/interfaces
 | 
	
		
			
			|  | 119 | +    echo 'iface lo inet loopback' >> /etc/network/interfaces
 | 
	
		
			
			|  | 120 | +    echo '' >> /etc/network/interfaces
 | 
	
		
			
			|  | 121 | +    echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
 | 
	
		
			
			|  | 122 | +    echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
 | 
	
		
			
			|  | 123 | +    echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
 | 
	
		
			
			|  | 124 | +    echo '' >> /etc/network/interfaces
 | 
	
		
			
			|  | 125 | +    echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
 | 
	
		
			
			|  | 126 | +    echo 'allow-hotplug eth0' >> /etc/network/interfaces
 | 
	
		
			
			|  | 127 | +    echo 'iface eth0 inet manual' >> /etc/network/interfaces
 | 
	
		
			
			|  | 128 | +    echo '' >> /etc/network/interfaces
 | 
	
		
			
			|  | 129 | +    echo '# Setup bridge' >> /etc/network/interfaces
 | 
	
		
			
			|  | 130 | +    echo 'iface br0 inet static' >> /etc/network/interfaces
 | 
	
		
			
			|  | 131 | +    echo "    bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
 | 
	
		
			
			|  | 132 | +
 | 
	
		
			
			|  | 133 | +    systemctl restart network-manager
 | 
	
		
			
			|  | 134 | +    systemctl restart hostapd
 | 
	
		
			
			|  | 135 | +}
 | 
	
		
			
			|  | 136 | +
 | 
	
		
			
			| 52 | 137 |  function wifi_wpa2_psk {
 | 
	
		
			
			| 53 | 138 |      ssid=$1
 | 
	
		
			
			| 54 | 139 |      passphrase=$2
 | 
	
	
		
			
			|  | @@ -77,6 +162,7 @@ function show_help {
 | 
	
		
			
			| 77 | 162 |      echo $'  -t --type [wpa2-psk|none]        Security type'
 | 
	
		
			
			| 78 | 163 |      echo $'  -s --ssid [id]                   Set SSID'
 | 
	
		
			
			| 79 | 164 |      echo $'  -p --passphrase [text]           Set passphrase'
 | 
	
		
			
			|  | 165 | +    echo $'     --hotspot [yes|no]            Create a hotspot'
 | 
	
		
			
			| 80 | 166 |      echo ''
 | 
	
		
			
			| 81 | 167 |      exit 0
 | 
	
		
			
			| 82 | 168 |  }
 | 
	
	
		
			
			|  | @@ -105,6 +191,10 @@ do
 | 
	
		
			
			| 105 | 191 |              shift
 | 
	
		
			
			| 106 | 192 |              WIFI_PASSPHRASE=${1}            
 | 
	
		
			
			| 107 | 193 |              ;;
 | 
	
		
			
			|  | 194 | +        --hostpot)
 | 
	
		
			
			|  | 195 | +            shift
 | 
	
		
			
			|  | 196 | +            WIFI_HOTSPOT=${1}            
 | 
	
		
			
			|  | 197 | +            ;;
 | 
	
		
			
			| 108 | 198 |          *)
 | 
	
		
			
			| 109 | 199 |              # unknown option
 | 
	
		
			
			| 110 | 200 |              ;;
 | 
	
	
		
			
			|  | @@ -117,6 +207,13 @@ if [ ! $WIFI_SSID ]; then
 | 
	
		
			
			| 117 | 207 |      exit 1
 | 
	
		
			
			| 118 | 208 |  fi
 | 
	
		
			
			| 119 | 209 |  
 | 
	
		
			
			|  | 210 | +if [[ $WIFI_HOTSPOT != 'no' ]]; then
 | 
	
		
			
			|  | 211 | +    hotspot_on
 | 
	
		
			
			|  | 212 | +    exit 0
 | 
	
		
			
			|  | 213 | +else
 | 
	
		
			
			|  | 214 | +    hotspot_off
 | 
	
		
			
			|  | 215 | +fi
 | 
	
		
			
			|  | 216 | +
 | 
	
		
			
			| 120 | 217 |  if [[ $WIFI_TYPE != 'none' ]]; then
 | 
	
		
			
			| 121 | 218 |      if [ ! $WIFI_PASSPHRASE ]; then
 | 
	
		
			
			| 122 | 219 |          echo $'No wifi passphrase was given'
 |