diff options
author | Jim Pryor <profjim@jimpryor.net> | 2009-08-11 14:05:04 +0200 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2009-08-15 04:28:28 +0200 |
commit | 8f9a77369c89db4de7d50d058b63c6b47a3428c9 (patch) | |
tree | 9854d550c4ba580c353c1c9052409573327f6bc3 /src | |
parent | 1c1a48accda117ca7368d916e07672c4ded6f63f (diff) | |
download | netctl-8f9a77369c89db4de7d50d058b63c6b47a3428c9.tar.gz netctl-8f9a77369c89db4de7d50d058b63c6b47a3428c9.tar.xz |
Integrate netcfg-menu and net-profiles
* net-profiles will only attempt to control the profiles it was told to;
if you manually netcfg a different interface, it will be left alone.
(This also helps keep netcfg from stomping on other daemons that might be
hooking into it.)
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/net-profiles | 36 | ||||
-rw-r--r-- | src/netcfg-menu | 18 |
2 files changed, 42 insertions, 12 deletions
diff --git a/src/net-profiles b/src/net-profiles index 6c001ea..152d803 100644 --- a/src/net-profiles +++ b/src/net-profiles @@ -21,30 +21,54 @@ case "$1" in [ ! "$NETWORKS_MENU_TIMEOUT" ] && NETWORKS_MENU_TIMEOUT=5 if [[ "$NET" = "menu" ]]; then - /usr/bin/netcfg-menu $NETWORKS_MENU_TIMEOUT + 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 + add_daemon net-profiles + exit 0 + fi elif [[ "$NET" ]]; then - /usr/bin/netcfg2 -c $NET + if /usr/bin/netcfg2 -c "$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 else # No NET= passed at boot, go to NETWORKS=() for network in ${NETWORKS[@]}; do case $network in menu) # Pull up menu of networks - /usr/bin/netcfg-menu $NETWORKS_MENU_TIMEOUT + 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 + add_daemon net-profiles + exit 0 + fi + break # if netcfg-menu was called but failed: exit for loop ;; *) # Either interface or profile if [ "$network" = "${network#!}" ]; then # otherwise profile - /usr/bin/netcfg2 -c $network + if /usr/bin/netcfg2 -c "$network"; then + echo "$network" > "$STATE_DIR/net-profiles" # JP: user may want to disconnect profile by calling net-profiles stop + add_daemon net-profiles + exit 0 + fi + break # found an enabled profile but failed to bring it up: exit for loop fi ;; esac done fi - add_daemon net-profiles + exit_err "No profile started." # JP: don't add_daemon unless we were successful (above) ;; stop) + if ck_daemon net-profiles; then + exit_stderr "net-profiles not running" + fi + # shutdown any profiles started by netcfg (or from NET_PROFILES in rc.conf) - /usr/bin/netcfg2 -a + # JP: only attempt to disconnect the profiles _this daemon_ was told to control + cat "${state_DIR}/net-profiles" 2>/dev/null | xargs -d'\n' /usr/bin/netcfg2 down # JP: use xargs in case any of the profile names contain spaces etc + rm -f "$STATE_DIR/net-profiles" rm_daemon net-profiles ;; restart) diff --git a/src/netcfg-menu b/src/netcfg-menu index 055cdf0..1d740fb 100644 --- a/src/netcfg-menu +++ b/src/netcfg-menu @@ -2,6 +2,8 @@ . /usr/lib/network/network +# JP: we'll use $STATE_DIR/menu to record what profile is being connected in this way +rm -f "$STATE_DIR/menu" # Scan all profiles i=0 @@ -21,11 +23,10 @@ if [ ${#profiles} -eq 0 ]; then exit_err "No profiles were found in $PROFILE_DIR" fi -# if no default yet, use the first entry [ "$NETWORKS_MENU_DEFAULT" ] && DEFAULT="$NETWORKS_MENU_DEFAULT" - +# if no default yet, use the first entry [ "$DEFAULT" = "" ] && DEFAULT=${profiles[0]} -ANSWER=$(mktemp) || exit 1 +ANSWER=$(mktemp /tmp/menu.XXXXXXXX) || exit 1 # Set timeout if [ "$1" = "" ]; then @@ -44,15 +45,20 @@ ret=$? case $ret in 1) ;; # Cancel - do nothing 255) # timeout - use default - netcfg2 $DEFAULT + profile_up "$DEFAULT" # JP: use profile_up and catch $? + ret=$? + if [[ $ret -eq 0 ]]; then echo "$DEFAULT" > "$STATE_DIR/menu"; fi ;; 0) # User selection - netcfg2 $(cat $ANSWER) + profile_up "$(cat $ANSWER)" + ret=$? + if [[ $ret -eq 0 ]]; then mv $ANSWER "$STATE_DIR/menu"; fi ;; *) # Shouldnt happen exit_err "Abnormal ret code from dialog: $ret" ;; esac -rm $ANSWER +rm -f $ANSWER # JP: add -f +exit $ret # JP: exit with caught $? # vim: set ts=4 et sw=4: |