From 4278b9e04952c24b14ce5eb3b5ed25885129a859 Mon Sep 17 00:00:00 2001 From: James Rayner Date: Thu, 18 Dec 2008 22:06:56 +1100 Subject: Arrange tree for future packaging --- Makefile | 30 ++++----- contrib/net-auto | 43 ------------ contrib/netcfg-auto-wireless | 58 ---------------- src-wireless/net-auto | 43 ++++++++++++ src-wireless/netcfg-auto-wireless | 58 ++++++++++++++++ src-wireless/wireless-dbus | 137 ++++++++++++++++++++++++++++++++++++++ src/connections/wireless-dbus | 137 -------------------------------------- src/netcfg | 2 +- 8 files changed, 252 insertions(+), 256 deletions(-) delete mode 100755 contrib/net-auto delete mode 100755 contrib/netcfg-auto-wireless create mode 100755 src-wireless/net-auto create mode 100755 src-wireless/netcfg-auto-wireless create mode 100755 src-wireless/wireless-dbus delete mode 100755 src/connections/wireless-dbus diff --git a/Makefile b/Makefile index 54eaa29..6e89601 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ DESTDIR= -VERSION=2.1.3 +VERSION=2.2.0_B1 install: install -d $(DESTDIR)/usr/lib/network/connections $(DESTDIR)/etc/network.d/examples \ @@ -18,32 +18,28 @@ install: install -m755 src/netcfg-menu $(DESTDIR)/usr/bin/netcfg-menu # Daemons install -m755 src/net-profiles src/net-rename $(DESTDIR)/etc/rc.d - - -install-contrib: - install -m755 contrib/netcfg-auto-wireless $(DESTDIR)/usr/bin - install -m755 contrib/net-auto $(DESTDIR)/etc/rc.d + +install-wireless: + install -d $(DESTDIR)/usr/lib/network/connections $(DESTDIR)/usr/bin \ + $(DESTDIR)/etc/rc.d + install -m755 src/wireless-dbus $(DESTDIR)/usr/lib/network/connections + install -m755 src/netcfg-auto-wireless $(DESTDIR)/usr/bin + install -m755 src/net-auto $(DESTDIR)/etc/rc.d tarball: sed -i "s/NETCFG_VER=.*/NETCFG_VER=$(VERSION)/g" src/netcfg mkdir -p netcfg-$(VERSION) - cp -r src examples contrib man Makefile LICENSE README netcfg-$(VERSION) + cp -r src src-wireless examples contrib man Makefile LICENSE README netcfg-$(VERSION) tar -zcvf netcfg-$(VERSION).tar.gz netcfg-$(VERSION) rm -rf netcfg-$(VERSION) - md5sum netcfg-$(VERSION)*gz > MD5SUMS.$(VERSION) - -pkg: tarball - sed -i "s/pkgver=.*/pkgver=$(VERSION)/g" PKGBUILD - makepkg - rm -rf pkg - rm -rf src/netcfg-$(VERSION)* - md5sum netcfg-$(VERSION)*gz > MD5SUMS.$(VERSION) + upload: - scp netcfg-$(VERSION)*gz MD5SUMS.$(VERSION) archlinux.org:/home/ftp/other/netcfg/ + md5sum netcfg-$(VERSION)*gz > MD5SUMS.$(VERSION) + #scp netcfg-$(VERSION)*gz MD5SUMS.$(VERSION) archlinux.org:/home/ftp/other/netcfg/ clean: rm *gz - rm -rf netcfg-$(VERSION) + rm -rf netcfg-*$(VERSION) rm -rf pkg rm MD5SUMS* diff --git a/contrib/net-auto b/contrib/net-auto deleted file mode 100755 index add6711..0000000 --- a/contrib/net-auto +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -. /etc/rc.conf -. /etc/rc.d/functions - -case "$1" in - start) - # Ensure any device renaming has occurred as intended - for daemon in "${DAEMONS[@]}"; do - if [ "$daemon" = "${daemon#!}" -a "$daemon" = "net-rename" ]; then - if ck_daemon net-rename; then - /etc/rc.d/net-rename start - fi - fi - done - - for network in ${AUTO_NETWORKS[@]}; do - case $network in - auto-*) # Automatic configuration, store type and get interface next - auto=$network - ;; - *) # Either interface or profile - if [[ "$auto" ]]; then # Auto set, so interface - /usr/bin/netcfg-$auto $network - unset auto - fi - esac - done - - add_daemon net-auto - ;; - stop) - /usr/bin/netcfg2 -a - rm_daemon net-auto - ;; - restart) - $0 stop; sleep 1; $0 start - ;; - *) - echo "usage: $0 {start|stop|restart}" -esac - -# vim: set ts=4 et sw=4: diff --git a/contrib/netcfg-auto-wireless b/contrib/netcfg-auto-wireless deleted file mode 100755 index e5e4fc1..0000000 --- a/contrib/netcfg-auto-wireless +++ /dev/null @@ -1,58 +0,0 @@ -#! /bin/bash -# Originally contributed by Neuro: http://bbs.archlinux.org/viewtopic.php?pid=278148#p278148 - -. /usr/lib/network/network.subr -. /usr/lib/network/wireless.subr -. /etc/rc.conf -. /etc/rc.d/functions - -# wifi_auto -# autoconnect wireless interface -# $1 - wireless interface -wifi_auto() -{ - interface=$1; RETRIES=6 - stat_busy "Scanning for networks" - - ifconfig $interface up - networks="$(list_networks $interface)" - - if [[ ! "$networks" ]]; then - stat_append "- No networks available." - stat_fail - exit 1 - fi - - # Loop through all the found essid's, then find a matching profile. - while read essid; do - for network in $(list_profiles); do - load_profile $network - if [[ "$CONNECTION" = "wireless" && "$essid" = "$ESSID" && "$interface" = "$INTERFACE" ]]; then - found=$network - fi - # Clear out any variables set by the profile - . /usr/lib/network/${CONNECTION}.subr - ${CONNECTION}_clean_scope - done - done < $networks - - if [[ "$found" ]]; then - netcfg2 $found - exit $? - fi - - stat_append "- No profiles matched the found networks" - stat_fail - exit 1 -} - -if [[ $(id -u) -ne 0 ]]; then - err "This script needs to be run with root priviledges" - exit 1 -fi -if [[ -z $1 ]]; then - err "Please supply an interface to connect" - exit 1 -fi -wifi_auto $1 - diff --git a/src-wireless/net-auto b/src-wireless/net-auto new file mode 100755 index 0000000..add6711 --- /dev/null +++ b/src-wireless/net-auto @@ -0,0 +1,43 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +case "$1" in + start) + # Ensure any device renaming has occurred as intended + for daemon in "${DAEMONS[@]}"; do + if [ "$daemon" = "${daemon#!}" -a "$daemon" = "net-rename" ]; then + if ck_daemon net-rename; then + /etc/rc.d/net-rename start + fi + fi + done + + for network in ${AUTO_NETWORKS[@]}; do + case $network in + auto-*) # Automatic configuration, store type and get interface next + auto=$network + ;; + *) # Either interface or profile + if [[ "$auto" ]]; then # Auto set, so interface + /usr/bin/netcfg-$auto $network + unset auto + fi + esac + done + + add_daemon net-auto + ;; + stop) + /usr/bin/netcfg2 -a + rm_daemon net-auto + ;; + restart) + $0 stop; sleep 1; $0 start + ;; + *) + echo "usage: $0 {start|stop|restart}" +esac + +# vim: set ts=4 et sw=4: diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless new file mode 100755 index 0000000..e5e4fc1 --- /dev/null +++ b/src-wireless/netcfg-auto-wireless @@ -0,0 +1,58 @@ +#! /bin/bash +# Originally contributed by Neuro: http://bbs.archlinux.org/viewtopic.php?pid=278148#p278148 + +. /usr/lib/network/network.subr +. /usr/lib/network/wireless.subr +. /etc/rc.conf +. /etc/rc.d/functions + +# wifi_auto +# autoconnect wireless interface +# $1 - wireless interface +wifi_auto() +{ + interface=$1; RETRIES=6 + stat_busy "Scanning for networks" + + ifconfig $interface up + networks="$(list_networks $interface)" + + if [[ ! "$networks" ]]; then + stat_append "- No networks available." + stat_fail + exit 1 + fi + + # Loop through all the found essid's, then find a matching profile. + while read essid; do + for network in $(list_profiles); do + load_profile $network + if [[ "$CONNECTION" = "wireless" && "$essid" = "$ESSID" && "$interface" = "$INTERFACE" ]]; then + found=$network + fi + # Clear out any variables set by the profile + . /usr/lib/network/${CONNECTION}.subr + ${CONNECTION}_clean_scope + done + done < $networks + + if [[ "$found" ]]; then + netcfg2 $found + exit $? + fi + + stat_append "- No profiles matched the found networks" + stat_fail + exit 1 +} + +if [[ $(id -u) -ne 0 ]]; then + err "This script needs to be run with root priviledges" + exit 1 +fi +if [[ -z $1 ]]; then + err "Please supply an interface to connect" + exit 1 +fi +wifi_auto $1 + diff --git a/src-wireless/wireless-dbus b/src-wireless/wireless-dbus new file mode 100755 index 0000000..d954577 --- /dev/null +++ b/src-wireless/wireless-dbus @@ -0,0 +1,137 @@ +#! /usr/bin/env python +import sys +import dbus +import shlex +import subprocess +from signal import SIGTERM +from os import kill +from time import sleep + +# dbus constants. +WPAS_DBUS_SERVICE = "fi.epitest.hostap.WPASupplicant" +WPAS_DBUS_INTERFACE = "fi.epitest.hostap.WPASupplicant" +WPAS_DBUS_OPATH = "/fi/epitest/hostap/WPASupplicant" + +WPAS_DBUS_INTERFACES_INTERFACE = "fi.epitest.hostap.WPASupplicant.Interface" +WPAS_DBUS_INTERFACES_OPATH = "/fi/epitest/hostap/WPASupplicant/Interfaces" +WPAS_DBUS_BSSID_INTERFACE = "fi.epitest.hostap.WPASupplicant.BSSID" +WPAS_DBUS_NETWORKS_INTERFACE = "fi.epitest.hostap.WPASupplicant.Network" + +def read_config(config): + cfg = shlex.split(open(config, "r").read()) + options = {} + for line in cfg: + (var, delim, value) = line.partition('=') + if not delim: + raise SyntaxError, 'Bad configuration file' + options[var] = value + return options + +def start(profile): + # TODO: Add check if it's even a wireless interface + # Interface up... + try: + subprocess.check_call(["ifconfig", profile['INTERFACE'], "up"]) + except CalledProcessError: + print " - Could not bring interface up" + return False + + # Manually set any iwconfig options, ignoring errors + if profile.has_key('IWCONFIG'): + subprocess.call(["iwconfig", profile['INTERFACE'], profile['IWCONFIG']]) + + + # Base arguments + args=["wpa_supplicant", "-Bu", "-P/var/run/wpa_supplicant.pid"] + + try: + args.append(profile['WPA_OPTS']) + except KeyError: + args.append("-Dwext") + + if profile['SECURITY'] == "wpa-config": + try: + args.append("-c" + profile["WPA_CONF"]) + except KeyError: + args.append("-c/etc/wpa_supplicant.conf") + elif not profile['SECURITY'] in ['yes', 'wpa', 'wep']: + print " - Invalid security chosen" + return False + + # Start wpa_supplicant + supplicant = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE) + output = supplicant.communicate()[0] + if supplicant.returncode not in [255,0]: + print output + print " - Could not start wpa_supplicant" + return False + + # Connect to wpa_supplicant + bus = dbus.SystemBus() + wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH) + wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE) + + # Add/Get interface path + try: + driver=profile["WPA_DRIVER"] + except KeyError: + driver="wext" + + try: + path = wpas.getInterface("ipw0") + except dbus.exceptions.DBusException: + path = wpas.addInterface("ipw0", {"driver":dbus.String(driver,variant_level=1)}) + + # Get interface object + if_obj = bus.get_object(WPAS_DBUS_SERVICE, path) + iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE); + + # Connect + if profile['SECURITY'] in ['wpa','yes','wep']: + # Add+select the network + path = iface.addNetwork() + net_obj = bus.get_object(WPAS_DBUS_SERVICE, path) + rnet = dbus.Interface(net_obj, WPAS_DBUS_NETWORKS_INTERFACE) + iface.selectNetwork(rnet) + # Set the options + opts = dbus.Dictionary({"ssid": dbus.ByteArray(profile['ESSID']), "psk": dbus.String(profile['KEY'])}, signature="sv") + rnet.set(opts) + + # Determine timeout + try: + timeout = profile["TIMEOUT"] + except KeyError: + timeout = 15 + + # Check for association + n=0 + while n <= timeout: + n+=1 + sleep(1) + state = iface.state() + if state == "COMPLETED": + break + + if n == timeout: + print " - Association/Authentication failed:", state + return False + + # Run ethernet and get an ip. + try: + subprocess.check_call(["/usr/lib/network/connections/ethernet", "up", sys.argv[2]]) + except CalledProcessError: + return False + return True + +def stop(profile): + subprocess.call(["/usr/lib/network/connections/ethernet", "down", sys.argv[2]]) + kill(int(open("/var/run/wpa_supplicant.pid").read()),SIGTERM) + return True + +if __name__ == "__main__": + profile = read_config("/etc/network.d/"+sys.argv[2]) + + if sys.argv[1] == "up": + sys.exit(not start(profile)) + elif sys.argv[1] == "down": + sys.exit(not stop(profile)) diff --git a/src/connections/wireless-dbus b/src/connections/wireless-dbus deleted file mode 100755 index d954577..0000000 --- a/src/connections/wireless-dbus +++ /dev/null @@ -1,137 +0,0 @@ -#! /usr/bin/env python -import sys -import dbus -import shlex -import subprocess -from signal import SIGTERM -from os import kill -from time import sleep - -# dbus constants. -WPAS_DBUS_SERVICE = "fi.epitest.hostap.WPASupplicant" -WPAS_DBUS_INTERFACE = "fi.epitest.hostap.WPASupplicant" -WPAS_DBUS_OPATH = "/fi/epitest/hostap/WPASupplicant" - -WPAS_DBUS_INTERFACES_INTERFACE = "fi.epitest.hostap.WPASupplicant.Interface" -WPAS_DBUS_INTERFACES_OPATH = "/fi/epitest/hostap/WPASupplicant/Interfaces" -WPAS_DBUS_BSSID_INTERFACE = "fi.epitest.hostap.WPASupplicant.BSSID" -WPAS_DBUS_NETWORKS_INTERFACE = "fi.epitest.hostap.WPASupplicant.Network" - -def read_config(config): - cfg = shlex.split(open(config, "r").read()) - options = {} - for line in cfg: - (var, delim, value) = line.partition('=') - if not delim: - raise SyntaxError, 'Bad configuration file' - options[var] = value - return options - -def start(profile): - # TODO: Add check if it's even a wireless interface - # Interface up... - try: - subprocess.check_call(["ifconfig", profile['INTERFACE'], "up"]) - except CalledProcessError: - print " - Could not bring interface up" - return False - - # Manually set any iwconfig options, ignoring errors - if profile.has_key('IWCONFIG'): - subprocess.call(["iwconfig", profile['INTERFACE'], profile['IWCONFIG']]) - - - # Base arguments - args=["wpa_supplicant", "-Bu", "-P/var/run/wpa_supplicant.pid"] - - try: - args.append(profile['WPA_OPTS']) - except KeyError: - args.append("-Dwext") - - if profile['SECURITY'] == "wpa-config": - try: - args.append("-c" + profile["WPA_CONF"]) - except KeyError: - args.append("-c/etc/wpa_supplicant.conf") - elif not profile['SECURITY'] in ['yes', 'wpa', 'wep']: - print " - Invalid security chosen" - return False - - # Start wpa_supplicant - supplicant = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE) - output = supplicant.communicate()[0] - if supplicant.returncode not in [255,0]: - print output - print " - Could not start wpa_supplicant" - return False - - # Connect to wpa_supplicant - bus = dbus.SystemBus() - wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH) - wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE) - - # Add/Get interface path - try: - driver=profile["WPA_DRIVER"] - except KeyError: - driver="wext" - - try: - path = wpas.getInterface("ipw0") - except dbus.exceptions.DBusException: - path = wpas.addInterface("ipw0", {"driver":dbus.String(driver,variant_level=1)}) - - # Get interface object - if_obj = bus.get_object(WPAS_DBUS_SERVICE, path) - iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE); - - # Connect - if profile['SECURITY'] in ['wpa','yes','wep']: - # Add+select the network - path = iface.addNetwork() - net_obj = bus.get_object(WPAS_DBUS_SERVICE, path) - rnet = dbus.Interface(net_obj, WPAS_DBUS_NETWORKS_INTERFACE) - iface.selectNetwork(rnet) - # Set the options - opts = dbus.Dictionary({"ssid": dbus.ByteArray(profile['ESSID']), "psk": dbus.String(profile['KEY'])}, signature="sv") - rnet.set(opts) - - # Determine timeout - try: - timeout = profile["TIMEOUT"] - except KeyError: - timeout = 15 - - # Check for association - n=0 - while n <= timeout: - n+=1 - sleep(1) - state = iface.state() - if state == "COMPLETED": - break - - if n == timeout: - print " - Association/Authentication failed:", state - return False - - # Run ethernet and get an ip. - try: - subprocess.check_call(["/usr/lib/network/connections/ethernet", "up", sys.argv[2]]) - except CalledProcessError: - return False - return True - -def stop(profile): - subprocess.call(["/usr/lib/network/connections/ethernet", "down", sys.argv[2]]) - kill(int(open("/var/run/wpa_supplicant.pid").read()),SIGTERM) - return True - -if __name__ == "__main__": - profile = read_config("/etc/network.d/"+sys.argv[2]) - - if sys.argv[1] == "up": - sys.exit(not start(profile)) - elif sys.argv[1] == "down": - sys.exit(not stop(profile)) diff --git a/src/netcfg b/src/netcfg index 377a71e..82f613f 100644 --- a/src/netcfg +++ b/src/netcfg @@ -12,7 +12,7 @@ err() { printhl "$*" } -NETCFG_VER=2.1.3 +NETCFG_VER=2.2.0_B1 version() { -- cgit v1.2.3-24-g4f1b