blob: 7fd5e080096c334ccf547ed52e1fe7d5329d3e7e (
plain)
1 #!/bin/bash
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 # workaround prt-get shortcoming
16 if [ -z "$BASH_VERSION" ]; then
17 echo "Running /bin/bash $0 $@"
18 exec /bin/bash $0 "$@"
19 fi
20
21 ssid="${ssid:-at_STARBUCKS_Wi2}"
22 name="${name:-Wireless connection for $ssid}"
23
24 PATH=/sbin:/usr/sbin:/bin:/usr/bin
25 umask 077
26
27 shopt -s nullglob
28
29 # Generate config for each device
30 for sysdir in /sys/class/net/enp* /sys/class/net/eth* /sys/class/net/wlp* /sys/class/net/wlan*; do
31 iface=${sysdir##*/}
32 cfg=/etc/NetworkManager/system-connections/$iface
33 if [ -f $cfg ]; then
34 echo "Skipping $iface: $cfg found"
35 continue
36 fi
37 echo "Generating sample config: $cfg"
38 macaddr=$(<$sysdir/address)
39 uuid=$(uuidgen)
40 timestamp=$(date +%s)
41 case $iface in
42 eth*|enp*)
43 cat > $cfg << EOF
44 [connection]
45 name=Wired connection $iface
46 id=$iface
47 uuid=$uuid
48 type=802-3-ethernet
49 autoconnect=true
50 timestamp=$timestamp
51
52 [802-3-ethernet]
53 mac-address=$macaddr
54
55 [ipv4]
56 method=auto
57 EOF
58 ;;
59 wlan*|wlp*)
60 # Convert ssid to an array of bytes
61 ssid_bytes=$(perl -e 'print "$_;" foreach unpack("C*", $ARGV[0])' $ssid)
62 cat > $cfg << EOF
63 [connection]
64 name=$name
65 id=$iface
66 uuid=$uuid
67 type=802-11-wireless
68 # the string below is: $ssid
69 ssid=$ssid_bytes
70 autoconnect=true
71 timestamp=$timestamp
72 # security=802-11-wireless-security
73
74 [802-11-wireless]
75 mac-address=$macaddr
76
77 [802-11-wireless-security]
78 key-mgmt=wpa-psk
79 psk=secret
80
81 [ipv4]
82 method=auto
83 EOF
84 ;;
85 esac
86 done
|