a56a5e
From cf9f56be9c0ab44e5ae5d5abde01151b33206fc2 Mon Sep 17 00:00:00 2001
90b079
From: Harald Hoyer <harald@redhat.com>
90b079
Date: Wed, 2 Oct 2013 12:48:11 +0200
90b079
Subject: [PATCH] dracut.sh: bail out early, if destination dir is not
90b079
 writeable
90b079
90b079
---
90b079
 dracut.sh | 36 +++++++++++++++++++-----------------
90b079
 1 file changed, 19 insertions(+), 17 deletions(-)
90b079
90b079
diff --git a/dracut.sh b/dracut.sh
1755ca
index b4b3e13d..e135dfc8 100755
90b079
--- a/dracut.sh
90b079
+++ b/dracut.sh
90b079
@@ -824,9 +824,25 @@ if [[ -d $srcmods ]]; then
90b079
     }
90b079
 fi
90b079
 
90b079
-if [[ -f $outfile && ! $force && ! $print_cmdline ]]; then
90b079
-    dfatal "Will not override existing initramfs ($outfile) without --force"
90b079
-    exit 1
90b079
+if [[ ! $print_cmdline ]]; then
90b079
+    if [[ -f $outfile && ! $force ]]; then
90b079
+        dfatal "Will not override existing initramfs ($outfile) without --force"
90b079
+        exit 1
90b079
+    fi
90b079
+
90b079
+    outdir=${outfile%/*}
90b079
+    [[ $outdir ]] || outdir="/"
90b079
+
90b079
+    if [[ ! -d "$outdir" ]]; then
90b079
+        dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
90b079
+        exit 1
90b079
+    elif [[ ! -w "$outdir" ]]; then
90b079
+        dfatal "No permission to write to $outdir."
90b079
+        exit 1
90b079
+    elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
90b079
+        dfatal "No permission to write $outfile."
90b079
+        exit 1
90b079
+    fi
90b079
 fi
90b079
 
90b079
 # Need to be able to have non-root users read stuff (rpcbind etc)
90b079
@@ -1041,20 +1057,6 @@ if [[ $print_cmdline ]]; then
90b079
     exit 0
90b079
 fi
90b079
 
90b079
-outdir=${outfile%/*}
90b079
-[[ $outdir ]] || outdir="/"
90b079
-
90b079
-if [[ ! -d "$outdir" ]]; then
90b079
-    dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
90b079
-    exit 1
90b079
-elif [[ ! -w "$outdir" ]]; then
90b079
-    dfatal "No permission to write to $outdir."
90b079
-    exit 1
90b079
-elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
90b079
-    dfatal "No permission to write $outfile."
90b079
-    exit 1
90b079
-fi
90b079
-
90b079
 # Create some directory structure first
90b079
 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"
90b079