mirror of https://github.com/captn3m0/Scripts.git
Updates the ap-hotspot script
This commit is contained in:
parent
c707e65ba2
commit
4d398a0e6c
48
ap-hotspot
48
ap-hotspot
|
@ -2,8 +2,8 @@
|
||||||
# Script to set up a WiFi Hotspot in Ubuntu that works with
|
# Script to set up a WiFi Hotspot in Ubuntu that works with
|
||||||
# Android and Windows Phone.
|
# Android and Windows Phone.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2013 Alin Andrei <andrew@webupd8.org>
|
# Copyright (C) 2014 Alin Andrei <andrew@webupd8.org>
|
||||||
# Copyright (C) 2013 Satyajit sahoo
|
# Copyright (C) 2014 Satyajit sahoo
|
||||||
#
|
#
|
||||||
# This scipt is free software; you can redistribute it and/or modify
|
# This scipt is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published
|
# it under the terms of the GNU General Public License as published
|
||||||
|
@ -21,9 +21,11 @@
|
||||||
# Global variables
|
# Global variables
|
||||||
logfile="/tmp/hostapd.log"
|
logfile="/tmp/hostapd.log"
|
||||||
pidfile="/tmp/hotspot.pid"
|
pidfile="/tmp/hotspot.pid"
|
||||||
hotspotconfig="/etc/hostapd-hotspot.conf"
|
hotspotconfig="/etc/ap-hotspot.conf"
|
||||||
dnsmasqconfig="/etc/dnsmasq.conf"
|
dnsmasqconfig="/etc/dnsmasq.d/ap-hotspot.rules"
|
||||||
user=$(who | grep $(echo "$DISPLAY" | cut -d '.' -f 1) | cut -d ' ' -f 1 | tail -1)
|
user=$(who | awk '{print $1}' | sed '/^root$/d' | uniq)
|
||||||
|
WMPID=$(ps -u $user | tail -n 1 | awk '{print $1}')
|
||||||
|
DBUS=$(egrep -z 'DBUS_SESSION_BUS_ADDRESS|DISPLAY' /proc/${WMPID}/environ | sed -r -e 's/(.)DBUS_/\1 DBUS_/' -e 's/(.)DISPLAY/\1 DISPLAY/')
|
||||||
|
|
||||||
show_msg() {
|
show_msg() {
|
||||||
echo -e "$@"
|
echo -e "$@"
|
||||||
|
@ -48,7 +50,7 @@ done
|
||||||
}
|
}
|
||||||
|
|
||||||
show_notify() {
|
show_notify() {
|
||||||
sudo -u "$user" notify-send -h int:transient:1 -i "network-wireless" "$@"
|
su $user -s /bin/bash -c "${DBUS} notify-send -h int:transient:1 -i \"network-wireless\" \"$@\""
|
||||||
}
|
}
|
||||||
|
|
||||||
check_root() {
|
check_root() {
|
||||||
|
@ -62,7 +64,7 @@ fi
|
||||||
check_supported() {
|
check_supported() {
|
||||||
# Check if the wireless card supports Access Point mode. This script won't work if it doesn't support it
|
# Check if the wireless card supports Access Point mode. This script won't work if it doesn't support it
|
||||||
if [[ ! $(iw list 2>&1 | grep -A6 "Supported interface modes" | grep AP$) ]]; then
|
if [[ ! $(iw list 2>&1 | grep -A6 "Supported interface modes" | grep AP$) ]]; then
|
||||||
show_err "Your wireless card does not support Access Point mode"
|
show_err "Your wireless card or driver does not support Access Point mode"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -102,17 +104,14 @@ check_root
|
||||||
check_supported
|
check_supported
|
||||||
# Reset config
|
# Reset config
|
||||||
rm -f "$hotspotconfig"
|
rm -f "$hotspotconfig"
|
||||||
sed -i "s/# Bind to only one interface//g" "$dnsmasqconfig"
|
rm -f "$dnsmasqconfig"
|
||||||
sed -i "s/bind-interfaces//g" "$dnsmasqconfig"
|
# Detect configuration
|
||||||
sed -i "s/# Choose interface for binding//g" "$dnsmasqconfig"
|
show_msg "Detecting configuration..."
|
||||||
sed -i "s/^interface=.*//g" "$dnsmasqconfig"
|
INTERFACE_NET=$(route | grep -iw "default" | awk '{printf "%s ", $NF}' | sed -s 's/ $//')
|
||||||
sed -i "s/# Specify range of IP addresses for DHCP leasses//g" "$dnsmasqconfig"
|
INTERFACE_WLAN=$(iwconfig 2>&1 | grep "^wlan" | sed -e 's/ .*//g' | tail -n 1)
|
||||||
sed -i "s/dhcp-range=192.168.150.2.*//g" "$dnsmasqconfig"
|
SSID="myhotspot"
|
||||||
sed -i "s/#INTERFACE_NET=.*//g" "$dnsmasqconfig"
|
WPAPASS="qwerty0987"
|
||||||
cat -s "$dnsmasqconfig" | tee "$dnsmasqconfig" > /dev/null 2>&1
|
|
||||||
# Network interface connected to the Internet
|
# Network interface connected to the Internet
|
||||||
show_msg "Detecting main network interface..."
|
|
||||||
INTERFACE_NET=$(route | grep -iw "default" | awk '{print $NF}')
|
|
||||||
if [[ ! $INTERFACE_NET ]]; then
|
if [[ ! $INTERFACE_NET ]]; then
|
||||||
show_warn "Failed to detect the network interface connected to the Internet. Please enter your network interface (e.g.- eth1):"
|
show_warn "Failed to detect the network interface connected to the Internet. Please enter your network interface (e.g.- eth1):"
|
||||||
else
|
else
|
||||||
|
@ -121,7 +120,6 @@ fi
|
||||||
read interface_net
|
read interface_net
|
||||||
[[ "$interface_net" ]] && INTERFACE_NET="$interface_net"
|
[[ "$interface_net" ]] && INTERFACE_NET="$interface_net"
|
||||||
# WiFi interface
|
# WiFi interface
|
||||||
INTERFACE_WLAN=$(iwconfig 2>&1 | grep "^wlan" | sed -e 's/ .*//g')
|
|
||||||
if [[ ! $INTERFACE_WLAN ]]; then
|
if [[ ! $INTERFACE_WLAN ]]; then
|
||||||
show_warn "Failed to detect the WiFi interface. Please enter your WiFi interface (e.g.- wlan0):"
|
show_warn "Failed to detect the WiFi interface. Please enter your WiFi interface (e.g.- wlan0):"
|
||||||
else
|
else
|
||||||
|
@ -130,12 +128,10 @@ fi
|
||||||
read interface_wlan
|
read interface_wlan
|
||||||
[[ "$interface_wlan" ]] && INTERFACE_WLAN="$interface_wlan"
|
[[ "$interface_wlan" ]] && INTERFACE_WLAN="$interface_wlan"
|
||||||
# Hotspot SSID
|
# Hotspot SSID
|
||||||
SSID="myhotspot"
|
|
||||||
show_msg "Enter the desired Access Point name or press ENTER to use the default one ($SSID):"
|
show_msg "Enter the desired Access Point name or press ENTER to use the default one ($SSID):"
|
||||||
read ssid
|
read ssid
|
||||||
[[ "$ssid" ]] && SSID="$ssid"
|
[[ "$ssid" ]] && SSID="$ssid"
|
||||||
# WPA Passphrase
|
# WPA Passphrase
|
||||||
WPAPASS="qwerty0987"
|
|
||||||
show_msg "Enter the desired WPA Passphrase below or press ENTER to use the default one ($WPAPASS):"
|
show_msg "Enter the desired WPA Passphrase below or press ENTER to use the default one ($WPAPASS):"
|
||||||
read wpapass
|
read wpapass
|
||||||
[[ "$wpapass" ]] && WPAPASS="$wpapass"
|
[[ "$wpapass" ]] && WPAPASS="$wpapass"
|
||||||
|
@ -152,15 +148,15 @@ channel=1
|
||||||
macaddr_acl=0
|
macaddr_acl=0
|
||||||
auth_algs=1
|
auth_algs=1
|
||||||
ignore_broadcast_ssid=0
|
ignore_broadcast_ssid=0
|
||||||
wpa=3
|
wpa=2
|
||||||
wpa_passphrase=$WPAPASS
|
wpa_passphrase=$WPAPASS
|
||||||
wpa_key_mgmt=WPA-PSK
|
wpa_key_mgmt=WPA-PSK
|
||||||
wpa_pairwise=TKIP
|
wpa_pairwise=TKIP
|
||||||
rsn_pairwise=CCMP
|
rsn_pairwise=CCMP
|
||||||
EOF
|
EOF
|
||||||
# Add the required bits to the dnsmasq config file
|
# Add the required bits to the dnsmasq config file
|
||||||
if [[ ! $(grep "Bind to only one interface" "$dnsmasqconfig") ]]; then
|
if [[ ! $(grep "Bind to only one interface" "$dnsmasqconfig" > /dev/null 2>&1) ]]; then
|
||||||
cat <<EOF | tee -a "$dnsmasqconfig" > /dev/null 2>&1
|
cat <<EOF | tee "$dnsmasqconfig" > /dev/null 2>&1
|
||||||
# Bind to only one interface
|
# Bind to only one interface
|
||||||
bind-interfaces
|
bind-interfaces
|
||||||
# Choose interface for binding
|
# Choose interface for binding
|
||||||
|
@ -169,6 +165,7 @@ interface=$INTERFACE_WLAN
|
||||||
dhcp-range=192.168.150.2,192.168.150.10,12h
|
dhcp-range=192.168.150.2,192.168.150.10,12h
|
||||||
#INTERFACE_NET=$INTERFACE_NET
|
#INTERFACE_NET=$INTERFACE_NET
|
||||||
EOF
|
EOF
|
||||||
|
chmod +x "$dnsmasqconfig"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +247,10 @@ sysctl net.ipv4.ip_forward=0 2>&1 | show_debug
|
||||||
service hostapd stop 2>&1 | show_debug
|
service hostapd stop 2>&1 | show_debug
|
||||||
service dnsmasq stop 2>&1 | show_debug
|
service dnsmasq stop 2>&1 | show_debug
|
||||||
# Restart WiFi and disable newly created mon.WLAN network
|
# Restart WiFi and disable newly created mon.WLAN network
|
||||||
ifconfig "mon.$INTERFACE_WLAN" down
|
if [[ ! -z $(ifconfig | grep "mon.$INTERFACE_WLAN") ]]; then
|
||||||
|
# Check if the hotspot is active
|
||||||
|
ifconfig "mon.$INTERFACE_WLAN" down
|
||||||
|
fi
|
||||||
ifconfig "$INTERFACE_WLAN" down
|
ifconfig "$INTERFACE_WLAN" down
|
||||||
ifconfig "$INTERFACE_WLAN" up
|
ifconfig "$INTERFACE_WLAN" up
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue