-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi.sh
97 lines (72 loc) · 2.38 KB
/
wifi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#
# @hmenn 29.03.18
#
COLOR_OFF='\033[0m'
COLOR_RED='\033[0;31m'
COLOR_GREEN='\033[0;32m'
TOOL_PATH="/opt/rpi-wifi-tool"
ORIG_INTERFACE_FILE=${TOOL_PATH}/"interfaces.orig"
ORIG_INTERFACE_HOTSPOT_FILE=${TOOL_PATH}/"interfaces_hotspot.orig"
DEFAULT_INTERFACE_PATH="/etc/network/interfaces"
ORIG_HOSTAPD_FILE=${TOOL_PATH}/"hostapd.conf.orig"
DEFAULT_HOSTAPD_CONF_PATH="/etc/hostapd/hostapd.conf"
ORIF_DNSMASQ_FILE=${TOOL_PATH}/"dnsmasq.conf.orig"
DEFAULT_DNSMASQ_CONF_PATH="/etc/dnsmasq.conf"
print_message(){
echo -e $1 $2 ${COLOR_OFF}
}
prepare(){
# install required packages
print_message ${COLOR_GREEN} "Prepare/Install required packages"
sudo apt-get update
print_message ${COLOR_GREEN} "Installing hostapd"
sudo apt-get install -y hostapd
print_message ${COLOR_GREEN} "Installing dnsmasq"
sudo apt-get install -y dnsmasq
print_message ${COLOR_GREEN} "Stopping dnsmasq and hostapd services"
sudo systemctl stop hostapd
sudo systemctl disable hostapd
sudo systemctl stop dnsmasq
sudo systemctl disable dnsmasq
print_message ${COLOR_GREEN} "Prepare interfaces, hostapd.conf and dnsmasq.conf file"
sudo cp ${ORIG_INTERFACE_FILE} ${DEFAULT_INTERFACE_PATH}
sudo cp ${ORIG_HOSTAPD_FILE} ${DEFAULT_HOSTAPD_CONF_PATH}
sudo cp ${ORIF_DNSMASQ_FILE} ${DEFAULT_DNSMASQ_CONF_PATH}
print_message ${COLOR_GREEN} "Prepare done."
}
open_client(){
print_message ${COLOR_GREEN} "ACTIVATING WIFI-CLIENT MODE..."
sudo ifdown wlan0
sudo systemctl stop hostapd
sudo systemctl disable hostapd
sudo systemctl stop dnsmasq
sudo systemctl disable dnsmasq
sudo cp ${ORIG_INTERFACE_FILE} ${DEFAULT_INTERFACE_PATH}
sudo ifup wlan0
print_message ${COLOR_GREEN} "WIFI-CLIENT MODE ACTIVE"
}
open_hotspot(){
print_message ${COLOR_GREEN} "ACTIVATING WIFI-HOTSPOT MODE"
sudo ifdown wlan0
sudo systemctl start hostapd
sudo systemctl enable hostapd
sudo cp ${ORIG_INTERFACE_HOTSPOT_FILE} ${DEFAULT_INTERFACE_PATH}
sync
sudo ifup wlan0 # activate wlan0, because dnsmasq needs networking
sudo systemctl start dnsmasq
sudo systemctl enable dnsmasq
print_message ${COLOR_GREEN} "WIFI-HOTSPOT MODE ACTIVE"
}
case $1 in
prepare)
prepare
;;
open_client)
open_client
;;
open_hotspot)
open_hotspot
;;
*)
echo "Invalid parameter"
esac