[Pkg-utopia-maintainers] Bug#637769: #637769: network-manager: please provide an example system-connections file

Tzafrir Cohen tzafrir at cohens.org.il
Wed Apr 4 14:28:34 UTC 2012


Update: a simple script to generate simple system-connections entry for
a wi-fi connection.

-- 
Tzafrir Cohen         | tzafrir at jabber.org | VIM is
http://tzafrir.org.il |                    | a Mutt's
tzafrir at cohens.org.il |                    |  best
tzafrir at debian.org    |                    | friend
-------------- next part --------------
#!/bin/sh

# mk_nm_con: create a NetworkManager wifi system connection entry

set -e

ssid=''
name=''
wpa_pass=''

usage() {
	me=`basename $0`
	echo >&2 "$me: Usage: $me [-s <ssid>] [-p <password>] <name>"
}

while getopts p:s: arg
do
	case "$arg" in
	s) ssid="$OPTARG";;
	p) wpa_pass="$OPTARG";;
        \?) usage; exit 1;;
        esac
done
shift `expr $OPTIND - 1`
name="$1"

if [ "$name" = '' ]; then
	usage
	exit 2
fi

if [ "$ssid" = '' ]; then
	ssid="$name"
fi

tmp_file=`mktemp mk_nm_XXXXXX`
chmod 600 "$tmp_file"

file="/etc/NetworkManager/system-connections/$name" 
if [ -e "$file" ]; then
	echo >&2 "File $file already exist. Cannot create connection file $name. Aborting."
	exit 1
fi
new_uuid=`cat /proc/sys/kernel/random/uuid`

cat >"$tmp_file" <<EOF
[connection]
type=802-11-wireless
id=$name
uuid=$new_uuid

[802-11-wireless]
ssid=$ssid
EOF

if [ "$wpa_pass" != '' ]; then
	cat >>"$tmp_file" <<EOF
security=802-11-wireless-security

[802-11-wireless-security]
key-mgmt=wpa-psk
psk=$wpa_pass
EOF
fi
mv "$tmp_file" "$file"


More information about the Pkg-utopia-maintainers mailing list