blob: 8e3aab6f25ae65cc223e984980891d44c4fb43fa (
plain)
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
|
#!/bin/bash
file="/var/lib/connman/wifi.config"
service_name="service_home_wifi"
create_file()
{
if [ -f "$file" ] ; then
echo "remove existing file"
rm "$file"
fi
touch "$file"
}
add_ssid_pw()
{
echo "Name = ${SSID}" >> "$file"
echo "Passphrase = ${PASSWORD}" >> "$file"
echo -e "SET ==>> Name = ${SSID}"
echo -e "SET ==>> Passphrase = ${PASSWORD}"
}
add_ip_address()
{
if [ -n "$IP" ] && [ -n "$NETMASK" ] && [ -n "$GATEWAY" ]; then
ipv4="$IP"/"$NETMASK"/"$GATEWAY"
elif [ -n "$DHCP" ]; then
ipv4="dhcp"
else
ipv4=""
fi
if [ -n "$ipv4" ]; then
echo "IPv4 = ${ipv4}" >> "$file"
echo -e "SET ==>> IPv4 = ${ipv4}"
fi
}
add_dns_server()
{
if [ -n "$DNS1" ] && [ -n "$DNS2" ]; then
dns_server="$DNS1","$DNS2"
elif [ -n "$DNS1" ] && [ -z "$DNS2" ]; then
dns_server="$DNS1"
else
dns_server=""
fi
if [ -n "$dns_server" ]; then
echo "Nameservers = ${dns_server}" >> "$file"
echo "SET ==>> Nameservers = ${dns_server}"
fi
}
#start to write config file
echo "create config file ${file}"
create_file
echo "[${service_name}]" >> "$file"
echo "Type = wifi" >> "$file"
add_ssid_pw
add_ip_address
add_dns_server
#change file mode
chmod +x "$file"
echo -e "complete to write...\n"
#disable wifi service
connmanctl disable wifi
#enable wifi service
connmanctl enable wifi
cat ${file}
|