-
Notifications
You must be signed in to change notification settings - Fork 0
/
enter_screen_name.sh
executable file
·218 lines (168 loc) · 5.22 KB
/
enter_screen_name.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#! /bin/bash
# ignore CTRL-C press in this script ---------
trap '' INT
# ignore CTRL-C press in this script ---------
dmesg -D 2> /dev/null
# tell network manager to NOT manage these network interfaces!!
mkdir -p /etc/network 2> /dev/null
echo '
auto lo
iface lo inet loopback
# allow-hotplug eth0
# iface eth0 inet dhcp
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
' > /etc/network/interfaces 2> /dev/null
function set_wlan_values
{
export mount_dir="/tmp/"
if [ -e "$mount_dir""/""wlan_ssid.txt" ]; then
wpa_net_country="AT" # TODO: also make this a parameter?
wpa_net_id_rand=$(( ( RANDOM % 100000 ) + 1 ))
########-------------------------------------
wpa_conf_file_location="/etc/wpa_supplicant/wpa_supplicant.conf"
wpa_conf_file_mode="600"
wpa_conf_file_content_001='country=@NETCOUNTRY@
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="'
wpa_conf_file_content_002='"
scan_ssid=1
psk="'
wpa_conf_file_content_003='"
key_mgmt=WPA-PSK
mode=0
proto=WPA2
pairwise=CCMP
group=CCMP
auth_alg=OPEN
id_str="ToxPhone@RAND@"
priority=1
}
'
wpa_conf_file_content_openwlan='
network={
key_mgmt=NONE
priority=-999
}
'
########-------------------------------------
rm -f "/tmp/abc.txt"
rm -f "/tmp/abc001.txt"
echo -n "$wpa_conf_file_content_001" \
| sed -e 's#@NETCOUNTRY@#'"$wpa_net_country"'#' \
> "/tmp/abc001.txt"
chmod og-rwx "/tmp/abc001.txt"
rm -f "/tmp/abc003.txt"
echo -n "$wpa_conf_file_content_003" \
| sed -e 's#@RAND@#'"$wpa_net_id_rand"'#' \
> "/tmp/abc003.txt"
chmod og-rwx "/tmp/abc003.txt"
cat "/tmp/abc001.txt" > "/tmp/abc.txt"
cat "$mount_dir""/""wlan_ssid.txt"|head -1|tr -d '\r'|tr -d '\n' >> "/tmp/abc.txt"
echo -n "$wpa_conf_file_content_002" >> "/tmp/abc.txt"
cat "$mount_dir""/""wlan_pass.txt"|head -1|tr -d '\r'|tr -d '\n' >> "/tmp/abc.txt"
cat "/tmp/abc003.txt" >> "/tmp/abc.txt"
rm -f "/tmp/abc001.txt" "/tmp/abc003.txt"
if [ -e "$mount_dir""/""wlan_public.txt" ]; then
echo "$wpa_conf_file_content_openwlan" >> "/tmp/abc.txt"
fi
chmod $wpa_conf_file_mode "/tmp/abc.txt"
mv -v "/tmp/abc.txt" "$wpa_conf_file_location"
rm -f "/tmp/abc.txt" # just to be safe
fi
return 0
}
echo ""
echo ""
echo ""
echo ""
echo "####################################"
echo ""
echo ' press "A" to enter your screename'
echo ' press "N" to setup WIFI'
echo ' press "F" to setup Public Free WIFI'
echo " or wait 6 seconds"
echo ""
screen_name=''
name_set=0
what=0
echo -n 'press "A" or "N" or "F" ';
for _ in {1..6}; do
read -rs -n1 -t1 name1 > /dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
if [ "$name1""x" == "ax" ]; then
echo ""
read -p 'New Screenname : ' -t60 -r -e screen_name
name_set=1
what=0
break
elif [ "$name1""x" == "nx" ]; then
echo ""
echo " WIFI Networks in the area:"
echo ""
nmcli device wifi list
echo ""
echo ""
sleep 2
read -p 'WIFI SSID : ' -t60 -r -e wifi_ssid
read -p 'WIFI PASS : ' -t60 -r -e wifi_pass
name_set=1
what=1
break
elif [ "$name1""x" == "fx" ]; then
echo ""
echo " WIFI Networks in the area:"
echo ""
nmcli device wifi list
echo ""
echo ""
sleep 2
wifi_ssid="_PUBLIC_FREE_"
wifi_pass="xxyy12_PUBLIC_FREE_213213123"
name_set=1
what=1
break
else
echo -n '.'
fi
else
echo -n '.'
fi
done
echo ""
# restore toxname from persistent storage
cp -av /home/pi/ToxBlinkenwall/toxblinkenwall/db/toxname.txt /home/pi/ToxBlinkenwall/toxblinkenwall/toxname.txt > /dev/null 2> /dev/null
chown pi:pi /home/pi/ToxBlinkenwall/toxblinkenwall/toxname.txt > /dev/null 2> /dev/null
# set values from user input
if [ $name_set -eq 1 ]; then
if [ "$what""x" == "0x" ]; then
if [ "$screen_name""x" != "x" ]; then
echo ""
echo ""
echo "Screenname will be : ""$screen_name"
echo "$screen_name" > /home/pi/ToxBlinkenwall/toxblinkenwall/toxname.txt 2> /dev/null
chown pi:pi /home/pi/ToxBlinkenwall/toxblinkenwall/toxname.txt > /dev/null 2> /dev/null
echo ""
echo ""
sleep 5
fi
elif [ "$what""x" == "1x" ]; then
if [ "$wifi_ssid""x" != "x" ]; then
if [ "$wifi_pass""x" != "x" ]; then
echo ""
echo ""
echo "Connecting to WIFI ""$wifi_ssid"" ..."
echo "$wifi_ssid" > /tmp/wlan_ssid.txt
echo "$wifi_pass" > /tmp/wlan_pass.txt
echo "" > /tmp/wlan_public.txt
set_wlan_values > /dev/null 2>&1
sleep 5
fi
fi
fi
fi
dmesg -E 2> /dev/null