summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Young <jesse.young@gmail.com>2010-10-26 03:28:13 +0200
committerJames Rayner <james@rayner.id.au>2010-11-21 04:28:00 +0100
commit908428678697664643937801c77e1c2403419c9d (patch)
tree637be9cec86a9f63d649cfb9dfce0bd8ddf66334 /src
parentf1fe938e761f2b6a58c922ef74f0b1a26a1acda8 (diff)
downloadnetctl-908428678697664643937801c77e1c2403419c9d.tar.gz
netctl-908428678697664643937801c77e1c2403419c9d.tar.xz
Make sure $STATE_DIR and expected subdirs are created
Signed-off-by: Jesse Young <jesse.young@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/network17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/network b/src/network
index 5bb4182..87c0e77 100644
--- a/src/network
+++ b/src/network
@@ -42,15 +42,22 @@ all_down()
done
}
+# Create the state dir and sub directories if they don't already exist
+check_make_state_dir()
+{
+ [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles}
+ for d in interfaces profiles suspend; do
+ [[ ! -d "$STATE_DIR/$d" ]] && mkdir "$STATE_DIR/$d"
+ done
+}
+
# interface_suspend interface/all [call_profile_down? default=yes]
# store a list of running profiles and take them down (unless $2 is "no")
interface_suspend()
{
report_debug interface_suspend "$@"
- [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles}
- [[ ! -d "$STATE_DIR/suspend" ]] && mkdir "$STATE_DIR/suspend"
-
+ check_make_state_dir
find "$STATE_DIR/profiles/" -maxdepth 1 -type f -printf '%f\n' \
| while read prof; do
# the pipe to "while read" will create a subshell
@@ -96,7 +103,7 @@ profile_up()
(
# Keep inside subshell so that options from one profile don't cross to others
# exit 1 used in a subshell is effectively exiting a new process
- [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend}
+ check_make_state_dir
local status PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks
@@ -186,7 +193,7 @@ profile_up()
profile_down()
{
(
- [[ ! -d "$STATE_DIR" ]] && mkdir -p "$STATE_DIR"/{interfaces,profiles,suspend}
+ check_make_state_dir
local status PROFILE="$1" # save PROFILE in a variable so that it's available to PRE_UP/POST_DOWN etc hooks