blob: 286e4a1e16c7a9523fbfa6c24010c3cd347ffe47 (
plain)
1 #!/bin/sh
2 #
3 # This script creates sample default system-connections files
4 # in /etc/NetworkManager/system-connections/ based on your current
5 # ethernet and wireless devices.
6 #
7 # You can skip it if you prefer to configure them yourself
8 # by creating the ini-files, via nmcli(1) or the networkmanager applet
9 #
10 # Note:
11 # You may override the default ssid by doing:
12 #
13 # ssid=my_wifi sh post-install
14
15 ssid="${ssid:-at_STARBUCKS_Wi2}"
16 name="${name:-Wireless connection for $ssid}"
17
18 PATH=/sbin:/usr/sbin:/bin:/usr/bin
19 umask 077
20
21 # Generate config for each device
22 for sysdir in /sys/class/net/eth* /sys/class/net/wlan*; do
23 iface=${sysdir##*/}
24 cfg=/etc/NetworkManager/system-connections/$iface
25 if [ -f $cfg ]; then
26 echo "Skipping $iface: $cfg found"
27 continue
28 fi
29 echo "Generating sample config: $cfg"
30 macaddr=$(<$sysdir/address)
31 uuid=$(uuidgen)
32 timestamp=$(date +%s)
33 case $iface in
34 eth*)
35 cat > $cfg << EOF
36 [connection]
37 name=Wired connection $iface
38 id=$iface
39 uuid=$uuid
40 type=802-3-ethernet
41 autoconnect=true
42 timestamp=$timestamp
43
44 [802-3-ethernet]
45 mac-address=$macaddr
46
47 [ipv4]
48 method=auto
49 EOF
50 ;;
51 wlan*)
52 # Convert ssid to an array of bytes
53 ssid_bytes=$(perl -e 'print "$_;" foreach unpack("C*", $ARGV[0])' $ssid)
54 cat > $cfg << EOF
55 [connection]
56 name=$name
57 id=$iface
58 uuid=$uuid
59 type=802-11-wireless
60 # the string below is: $ssid
61 ssid=$ssid_bytes
62 autoconnect=true
63 timestamp=$timestamp
64 # security=802-11-wireless-security
65
66 [802-11-wireless]
67 mac-address=$macaddr
68
69 [802-11-wireless-security]
70 key-mgmt=wpa-psk
71 psk=secret
72
73 [ipv4]
74 method=auto
75 EOF
76 ;;
77 esac
78 done
|