2015-07-23 15:48:26 +09:00
|
|
|
#!/bin/bash
|
2013-09-28 21:12:52 +09:00
|
|
|
#
|
|
|
|
# This script creates sample default system-connections files
|
|
|
|
# in /etc/NetworkManager/system-connections/ based on your current
|
|
|
|
# ethernet and wireless devices.
|
|
|
|
#
|
|
|
|
# You can skip it if you prefer to configure them yourself
|
|
|
|
# by creating the ini-files, via nmcli(1) or the networkmanager applet
|
|
|
|
#
|
|
|
|
# Note:
|
|
|
|
# You may override the default ssid by doing:
|
|
|
|
#
|
|
|
|
# ssid=my_wifi sh post-install
|
|
|
|
|
2016-01-04 16:53:12 +09:00
|
|
|
# workaround prt-get shortcoming
|
|
|
|
if [ -z "$BASH_VERSION" ]; then
|
|
|
|
echo "Running /bin/bash $0 $@"
|
|
|
|
exec /bin/bash $0 "$@"
|
|
|
|
fi
|
|
|
|
|
2013-09-28 21:12:52 +09:00
|
|
|
ssid="${ssid:-at_STARBUCKS_Wi2}"
|
|
|
|
name="${name:-Wireless connection for $ssid}"
|
|
|
|
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
|
|
umask 077
|
|
|
|
|
2015-07-23 15:48:26 +09:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2013-09-28 21:12:52 +09:00
|
|
|
# Generate config for each device
|
2015-07-23 15:48:26 +09:00
|
|
|
for sysdir in /sys/class/net/enp* /sys/class/net/eth* /sys/class/net/wlp* /sys/class/net/wlan*; do
|
2013-09-28 21:12:52 +09:00
|
|
|
iface=${sysdir##*/}
|
|
|
|
cfg=/etc/NetworkManager/system-connections/$iface
|
|
|
|
if [ -f $cfg ]; then
|
|
|
|
echo "Skipping $iface: $cfg found"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo "Generating sample config: $cfg"
|
|
|
|
macaddr=$(<$sysdir/address)
|
|
|
|
uuid=$(uuidgen)
|
|
|
|
timestamp=$(date +%s)
|
|
|
|
case $iface in
|
2015-07-23 15:48:26 +09:00
|
|
|
eth*|enp*)
|
2013-09-28 21:12:52 +09:00
|
|
|
cat > $cfg << EOF
|
|
|
|
[connection]
|
|
|
|
name=Wired connection $iface
|
|
|
|
id=$iface
|
|
|
|
uuid=$uuid
|
|
|
|
type=802-3-ethernet
|
|
|
|
autoconnect=true
|
|
|
|
timestamp=$timestamp
|
|
|
|
|
|
|
|
[802-3-ethernet]
|
|
|
|
mac-address=$macaddr
|
|
|
|
|
|
|
|
[ipv4]
|
|
|
|
method=auto
|
|
|
|
EOF
|
|
|
|
;;
|
2015-07-23 15:48:26 +09:00
|
|
|
wlan*|wlp*)
|
2013-09-28 21:12:52 +09:00
|
|
|
# Convert ssid to an array of bytes
|
|
|
|
ssid_bytes=$(perl -e 'print "$_;" foreach unpack("C*", $ARGV[0])' $ssid)
|
|
|
|
cat > $cfg << EOF
|
|
|
|
[connection]
|
|
|
|
name=$name
|
|
|
|
id=$iface
|
|
|
|
uuid=$uuid
|
|
|
|
type=802-11-wireless
|
|
|
|
# the string below is: $ssid
|
|
|
|
ssid=$ssid_bytes
|
|
|
|
autoconnect=true
|
|
|
|
timestamp=$timestamp
|
|
|
|
# security=802-11-wireless-security
|
|
|
|
|
|
|
|
[802-11-wireless]
|
|
|
|
mac-address=$macaddr
|
|
|
|
|
|
|
|
[802-11-wireless-security]
|
|
|
|
key-mgmt=wpa-psk
|
|
|
|
psk=secret
|
|
|
|
|
|
|
|
[ipv4]
|
|
|
|
method=auto
|
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|