diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-04-11 13:40:19 +0200 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-04-11 13:40:19 +0200 |
commit | 0340759269f84f071b5b7ec11ae4691a8722c21a (patch) | |
tree | c17cb1b507c633038d3288af4ea8b9976c2416a1 | |
parent | 7fab9eaf848004fd742e0513d620ced9ee7667a2 (diff) | |
download | netctl-0340759269f84f071b5b7ec11ae4691a8722c21a.tar.gz netctl-0340759269f84f071b5b7ec11ae4691a8722c21a.tar.xz |
Add netcfg-daemon
For reuse in a systemd service
-rw-r--r-- | Makefile | 1 | ||||
-rwxr-xr-x | rc.d/net-profiles | 54 | ||||
-rwxr-xr-x[-rw-r--r--] | scripts/ifplugd.action | 0 | ||||
-rwxr-xr-x | scripts/netcfg-daemon | 67 |
4 files changed, 81 insertions, 41 deletions
@@ -18,6 +18,7 @@ install: install-docs install -d $(DESTDIR)/usr/bin install -m755 \ scripts/netcfg \ + scripts/netcfg-daemon \ scripts/netcfg-menu \ scripts/netcfg-wpa_actiond \ scripts/netcfg-wpa_actiond-action \ diff --git a/rc.d/net-profiles b/rc.d/net-profiles index f8c0992..66f0851 100755 --- a/rc.d/net-profiles +++ b/rc.d/net-profiles @@ -1,9 +1,10 @@ #!/bin/bash +# +# This script utilizes netcfg-daemon. . /etc/rc.conf . /etc/rc.d/functions . /usr/lib/network/globals -. /etc/conf.d/netcfg case "$1" in start) @@ -21,64 +22,35 @@ case "$1" in done # $NET env var is passed from the kernel boot line - [[ -z "$NETWORKS_MENU_TIMEOUT" ]] && NETWORKS_MENU_TIMEOUT=5 - if [[ "$NET" = "menu" ]]; then - if /usr/bin/netcfg-menu "$NETWORKS_MENU_TIMEOUT"; then - mv "$STATE_DIR"/{menu,net-profiles} # JP: user may want to disconnect profile by calling net-profiles stop + if /usr/bin/netcfg-menu; then + mv "$STATE_DIR"/{menu,netcfg-daemon} # JP: user may want to disconnect profile by calling net-profiles stop add_daemon net-profiles exit 0 fi elif [[ -n "$NET" ]]; then if /usr/bin/netcfg check-iface "$NET"; then - echo "$NET" > "$STATE_DIR/net-profiles" # JP: user may want to disconnect profile by calling net-profiles stop - add_daemon net-profiles - exit 0 - fi - elif [[ $NETWORKS = "menu" ]]; then - if /usr/bin/netcfg-menu "$NETWORKS_MENU_TIMEOUT"; then - mv "$STATE_DIR"/menu "$STATE_DIR"/net-profiles + echo "$NET" > "$STATE_DIR/netcfg-daemon" # JP: user may want to disconnect profile by calling net-profiles stop add_daemon net-profiles exit 0 fi + elif /usr/bin/netcfg-daemon start; then + add_daemon net-profiles else - # No NET= passed at boot, go to NETWORKS=() - for network in "${NETWORKS[@]}"; do - if [[ "$network" = "${network#@}" ]]; then - if /usr/bin/netcfg check-iface "$network"; then - echo "$network" >> "$STATE_DIR/net-profiles" - add_daemon net-profiles - fi - else - # It is up to the user to make sure no backgrounded profile - # uses an interface that is used by another active profile. - if /usr/bin/netcfg "${network#@}"; then - echo "${network#@}" >> "$STATE_DIR/net-profiles" - add_daemon net-profiles - fi >/dev/null & - PROFILE_BKGD=1 - fi - done - fi - if [[ ! -f "$STATE_DIR"/net-profiles && -z "$PROFILE_BKGD" ]]; then - exit_err "No profile started." # JP: don't add_daemon unless we were successful (above) + exit_err "No profile started." fi ;; stop) if ck_daemon net-profiles; then - exit_stderr "net-profiles not running" + exit_stderr "net-profiles is not running" fi - - # shutdown any profiles started by netcfg (or from NET_PROFILES in rc.conf) - # JP: only attempt to disconnect the profiles _this daemon_ was told to control - while read profile; do - /usr/bin/netcfg down "$profile" - done < "$STATE_DIR/net-profiles" - rm -f "$STATE_DIR/net-profiles" + /usr/bin/netcfg-daemon stop rm_daemon net-profiles ;; restart) - "$0" stop; sleep 1; "$0" start + "$0" stop + sleep 1 + "$0" start ;; *) exit_stderr "Usage: $0 {start|stop|restart}" diff --git a/scripts/ifplugd.action b/scripts/ifplugd.action index ea3a16c..ea3a16c 100644..100755 --- a/scripts/ifplugd.action +++ b/scripts/ifplugd.action diff --git a/scripts/netcfg-daemon b/scripts/netcfg-daemon new file mode 100755 index 0000000..5a6a6d1 --- /dev/null +++ b/scripts/netcfg-daemon @@ -0,0 +1,67 @@ +#!/bin/bash +# +# This script implements support for the NETWORKS array in /etc/conf.d/netcfg. + +. /usr/lib/network/globals +STATE_FILE="$STATE_DIR/netcfg-daemon" + +case "$1" in + start) + (( $(id -u) )) && exit_stderr "This script should be run as root." + [[ -e $STATE_FILE ]] && exit_err "netcfg-daemon is already started" + . /etc/conf.d/netcfg + [[ ${NETWORKS+x} != x ]] && exit_err "NETWORKS is not set in /etc/conf.d/netcfg" + if [[ ${#NETWORKS[@]} -eq 1 && $NETWORKS = menu ]]; then + if /usr/bin/netcfg-menu ${NETWORKS_MENU_TIMEOUT-5}; then + mv "$STATE_DIR/menu" "$STATE_FILE" + fi + exit 0 + fi + for profile in "${NETWORKS[@]}"; do + if [[ "$profile" = "${profile#@}" ]]; then + if /usr/bin/netcfg check-iface "$profile"; then + echo "$profile" >> "$STATE_FILE" + fi + else + # It is up to the user to make sure no backgrounded profile + # uses an interface that is used by another active profile. + if /usr/bin/netcfg up "${profile#@}"; then + echo "$profile" >> "$STATE_FILE" + fi >/dev/null & + PROFILE_BKGD=1 + fi + done + # Generate a return value. + [[ -f $STATE_FILE || -n $PROFILE_BKGD ]] + ;; + stop) + (( $(id -u) )) && exit_stderr "This script should be run as root." + [[ ! -e $STATE_FILE ]] && exit_err "netcfg-daemon was not started" + tac "$STATE_FILE" | while read profile; do + if [[ "$profile" = "${profile#@}" ]]; then + if [[ -e "$STATE_DIR/profiles/$profile" ]]; then + /usr/bin/netcfg down "$profile" || exit 1 + fi + else + /usr/bin/netcfg down "${profile#@}" & + fi + done + rm -f "$STATE_FILE" + ;; + restart) + "$0" stop + sleep 1 + "$0" start + ;; + status) + if [[ -e $STATE_FILE ]]; then + report_notice "profiles started by netcfg-daemon:" + cat "$STATE_FILE" + else + report_notice "netcfg-daemon was not started" + fi + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" +esac + |