summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorJim Pryor <profjim@jimpryor.net>2009-08-11 14:05:02 +0200
committerJames Rayner <james@archlinux.org>2009-08-15 04:28:27 +0200
commit29b8a7c378cd275c4c1f8d8c995b65cdf19657af (patch)
treef66472861c788026296baa56b6c406f740a04c01 /src/network
parentefc7183790cec4fc2b3425f17201e0e2fea51c44 (diff)
downloadnetctl-29b8a7c378cd275c4c1f8d8c995b65cdf19657af.tar.gz
netctl-29b8a7c378cd275c4c1f8d8c995b65cdf19657af.tar.xz
Improve listing/iterating over profiles
Signed-off-by: Jim Pryor <profjim@jimpryor.net>
Diffstat (limited to 'src/network')
-rw-r--r--src/network37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/network b/src/network
index e7e262a..94494cb 100644
--- a/src/network
+++ b/src/network
@@ -33,12 +33,13 @@ validate_profile()
### Profile up/down
##
# all_down
-# take all profiles down
-#
+# take all registered profiles down
all_down()
{
- for prof in $(find ${STATE_DIR}/profiles/ -maxdepth 1 -type f -printf '%f\n'); do
- profile_down $prof
+ find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \
+ | while read prof; do
+ # the pipe to while read... creates a subshell
+ profile_down "$prof"
done
}
@@ -50,20 +51,26 @@ all_suspend()
[[ ! -d $STATE_DIR ]] && mkdir -p $STATE_DIR/{interfaces,profiles}
[[ ! -d $STATE_DIR/suspend ]] && mkdir $STATE_DIR/suspend
- for prof in $(find $STATE_DIR/profiles/ -maxdepth 1 -type f); do
- cp $prof $STATE_DIR/suspend/
- profile_down $(basename $prof)
+ find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \
+ | while read prof; do
+ # the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox
+ report_notify "suspending profile $prof"
+ cp "$STATE_DIR/profiles/$prof" "$STATE_DIR/suspend/"
+ profile_down "$prof"
done
}
-# all_suspend
-# store a list of running profiles and take them down
-#
+# all_resume
+# resume suspended interfaces
all_resume()
{
- for prof in $(find $STATE_DIR/suspend/ -maxdepth 1 -type f); do
- profile_up $(basename $prof)
- rm $prof
+ report_debug all_resume "$@"
+ find "$STATE_DIR/suspend/" -maxdepth 1 -type f -printf '%f\n' \
+ | while read prof; do
+ # the pipe to "while read" will create a subshell, so sourced variables will already be in a sandbox
+ report_notify "resuming profile $prof"
+ profile_up "$prof"
+ rm -f "$STATE_DIR/suspend/$prof" # if profile_up succeeds, it will have already removed this
done
}
@@ -235,9 +242,9 @@ get_iface_prof() {
# list_profiles
# Outputs a list of all profiles
list_profiles() {
- find $PROFILE_DIR/ -maxdepth 1 -type f -printf "%f\n"
+ # JP: follow aliases with -L, also skip profiles that start with '.' or end with '~' or '.conf' (so profile.conf can be the wpa.conf file for profile)
+ find -L "$PROFILE_DIR/" -maxdepth 1 -type f -not -name '*~' -not -name '*.conf' -not -name '.*' -printf "%f\n"
}
-
# check_profile profile
# Return 0 if profile up
# Return 1 if profile down