forked from balena-os/wifi-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·47 lines (36 loc) · 1.34 KB
/
start.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
#!/usr/bin/env bash
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
# Optional step - it takes couple of seconds (or longer) to establish a WiFi connection
# sometimes. In this case, following checks will fail and wifi-connect
# will be launched even if the device will be able to connect to a WiFi network.
# If this is your case, you can wait for a while and then check for the connection.
# sleep 15
# Choose a condition for running WiFi Connect according to your use case:
# 1. Is there a default gateway?
# ip route | grep default
# 2. Is there Internet connectivity?
# nmcli -t g | grep full
# 3. Is there Internet connectivity via a google ping?
# wget --spider http://google.com 2>&1
# 4. Is there an active WiFi connection?
# iwgetid -r
echo "192.168.42.1 samizdapp.localhost" >> /etc/hosts
echo "192.168.42.1 samizdapp.local" >> /etc/hosts
ETH=$(ip a show eth0 up | grep inet)
iwgetid -r
if [ $? -eq 0 ]; then
echo 'Have WiFi Connect\n'
if [ -z "$ETH" ]; then
echo "no ethernet, do nothing"
else
echo "have wifi + ethernet, enable hotspot"
printf 'Starting WiFi Connect\n'
./wifi-connect --portal-listening-port 8000
fi
else
echo "no wifi, start hotspot"
printf 'Starting WiFi Connect\n'
./wifi-connect --portal-listening-port 8000
fi
# Start your application here.
sleep infinity