diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-06-24 23:55:47 +0200 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-06-24 23:55:47 +0200 |
commit | 3fcb56d6743fc1c00ae4d05b671e221ea3df6492 (patch) | |
tree | 90388a1e8da785dff9213da68800f8b2e103a5c6 | |
parent | 2d949d5ab65851bc8b6610dd4288eb8737aa9f86 (diff) | |
download | netctl-3fcb56d6743fc1c00ae4d05b671e221ea3df6492.tar.gz netctl-3fcb56d6743fc1c00ae4d05b671e221ea3df6492.tar.xz |
Provide the ability to activate the last used profile (FS#23015)
Henrik Hallberg made this a hot topic. Thanks.
This implementation differs from his in a couple of ways. One is that @last is not implemented. Equivalent functionality is provided by using @net-profiles in the DAEMONS array.
-rw-r--r-- | config/netcfg | 8 | ||||
-rw-r--r-- | docs/features.txt | 9 | ||||
-rwxr-xr-x | scripts/netcfg-daemon | 36 |
3 files changed, 41 insertions, 12 deletions
diff --git a/config/netcfg b/config/netcfg index f56272a..e74e5ea 100644 --- a/config/netcfg +++ b/config/netcfg @@ -1,9 +1,9 @@ -# Enable these netcfg profiles at boot-up. -# - set to 'menu' to present a menu during boot-up (dialog package required) +# Enable these netcfg profiles at boot time. # - prefix an entry with a '@' to background its startup +# - set to 'last' to restore the profiles running at the last shutdown +# - set to 'menu' to present a menu (requires the dialog package) # Network profiles are found in /etc/network.d -# -#NETWORKS=(menu) +NETWORKS=(last) ## Specify the name of your wired interface for net-auto-wired WIRED_INTERFACE="eth0" diff --git a/docs/features.txt b/docs/features.txt index f07376f..4155a2d 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -37,14 +37,17 @@ For more options, see ''netcfg help'' Start a specific list of profiles on boot ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ net-profiles allows you to start some profiles at boot time. Specify the -profiles you want netcfg to start (in this order) in the +NETWORKS+ line -in '/etc/conf.d/netcfg'. Prefix a profile with a `@' to start it in the -background. For example: +profiles you want netcfg to start (in the order you want them to be +started) in the +NETWORKS+ line in '/etc/conf.d/netcfg'. +Prefix a profile with a `@' to start it in the background. For example: -------------------------------- NETWORKS=(@adsl @mywireless lan) -------------------------------- +Alternatively, you can have netcfg restart the profiles you had running +at the previous shutdown by specifying +NETWORKS=(last)+. + Next, add `net-profiles' to your +DAEMONS+ line in '/etc/rc.conf'. diff --git a/scripts/netcfg-daemon b/scripts/netcfg-daemon index 97ed1ef..d0b6f7c 100755 --- a/scripts/netcfg-daemon +++ b/scripts/netcfg-daemon @@ -3,19 +3,37 @@ # This script implements support for the NETWORKS array in /etc/conf.d/netcfg. . /usr/lib/network/globals +. /etc/conf.d/netcfg STATE_FILE="$STATE_DIR/netcfg-daemon" +LAST_STATE="/var/lib/netcfg/netcfg.state" 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 - /usr/bin/netcfg-menu ${NETWORKS_MENU_TIMEOUT-5} && \ - mv "$STATE_DIR/menu" "$STATE_FILE" - exit $? + + if [[ ${#NETWORKS[@]} -eq 1 ]]; then + case $NETWORKS in + last) + [[ -e $LAST_STATE ]] || exit_err "No recorded netcfg state to restore" + + # The order in LAST_STATE is meaningless so we can just as + # well start the profiles in the background. + while read profile; do + if /usr/bin/netcfg up "$profile"; then + echo "$profile" >> "$STATE_FILE" + fi & + done < "$LAST_STATE" + wait + exit $? ;; + menu) + /usr/bin/netcfg-menu ${NETWORKS_MENU_TIMEOUT-5} && \ + mv "$STATE_DIR/menu" "$STATE_FILE" + exit $? ;; + esac fi + for profile in "${NETWORKS[@]}"; do if [[ "$profile" = "${profile#@}" ]]; then if /usr/bin/netcfg check-iface "$profile"; then @@ -35,6 +53,14 @@ case "$1" in ;; stop) (( $(id -u) )) && exit_stderr "This script should be run as root." + + if [[ ${#NETWORKS[@]} -eq 1 && $NETWORKS = last ]]; then + mkdir -p "$(dirname "$LAST_STATE")" + /usr/bin/netcfg current > "$LAST_STATE" + /usr/bin/netcfg all-down + exit $? + fi + [[ ! -e $STATE_FILE ]] && exit_err "netcfg-daemon was not started" # Stop the profiles in the reverse order they were started. tac "$STATE_FILE" | ( |