-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadapter.sh
83 lines (66 loc) · 2.23 KB
/
adapter.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
status="0"
read -rp "Press Enter To Continue! (WARNING: THIS MUST BE DONE OVER ETHERNET!)"
if [[ ${status} == "0" ]]; then
# Backup wireless configuration (only done on first run)
cp /etc/config/wireless /etc/config/conf_backup/wireless-pre-ap.bk
sed -i 's/statkus="0"/status="1"/' "$0"
fi
# Prompt to attach USB WiFi adapter
echo "REMOVE NETWORK ADAPTER!"
read -rp "Press Enter after detaching USB WiFi adapter!"
sed -i '19,100d' /etc/config/wireless # removes any wireless config besides our wifi connection
read -rp "Press Enter after attaching USB WiFi adapter!"
sleep 3
# Check if adapter is found
if lsusb | grep -iq "WLAN"; then
echo "Adapter Found!"
else
echo "No Adapter Found!"
exit 1
fi
#if [[ ${status} == "0" ]]; then
ifconfig wlan1 up
#fi
# Prompt for AP configuration
echo "Enter AP SSID:"
read -r ssid
echo "Enter AP Key: (must be longer than 8 digits) (can also enter random for a random password"
read -r key
if [[ ${key} == "random" ]]; then
echo "Enter Random Key Length: "
read -r length
key=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c ${length})
echo "Your Password Is ${key}"
fi
echo "Enter AP Channel (1-11):"
read -r channel
# add channel check (must be between 1 and 11!)
# Prompt for hidden AP configuration
echo "Hidden AP? (0/1) (1=hidden):"
read -r hidden
if ! [[ "${hidden}" =~ ^[0-1]$ ]]; then
echo "Error: Invalid hidden value. Must be either 0 or 1. Exiting..."
exit 1
fi
# modify lines in wireless config
sed -i "23s/.*/ option channel '${channel}'/" /etc/config/wireless # sets channel
sed -i "26s/.*/ option disabled '0'/" /etc/config/wireless # enables wifi-adapter
sed -i "32s/.*/ option ssid '${ssid}'/" /etc/config/wireless # sets channel
sed -i "33s/.*/ option encryption 'psk2'/" /etc/config/wireless # enables wifi-adapter
cat <<EOF >>/etc/config/wireless
option key '${key}'
option hidden '${hidden}'
EOF
sed -i '34d' /etc/config/wireless # removes empty line
echo "TIP: IF WIFI DOESNT SHOW UP PASSWORD IS PROBABLY TOO SHORT!"
read -p "Press Enter to Start AP! (Will Reboot!)"
#rm /root/adapter.sh
cat <<EOF > /etc/rc.local # this belongs in adapter.sh
wifi
exit 0
EOF
chmod +x /etc/rc.local
uci commit wireless
wifi
sleep 10
reboot now