]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut.sh: bail out early, if destination dir is not writeable
authorHarald Hoyer <harald@redhat.com>
Wed, 2 Oct 2013 10:48:11 +0000 (12:48 +0200)
committerHarald Hoyer <harald@redhat.com>
Wed, 2 Oct 2013 10:48:11 +0000 (12:48 +0200)
dracut.sh

index b4b3e13def71c1955975eb606fdcf3f4904ed255..e135dfc82126c76f0b3d019dc65ec416d825c620 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -824,9 +824,25 @@ if [[ -d $srcmods ]]; then
     }
 fi
 
-if [[ -f $outfile && ! $force && ! $print_cmdline ]]; then
-    dfatal "Will not override existing initramfs ($outfile) without --force"
-    exit 1
+if [[ ! $print_cmdline ]]; then
+    if [[ -f $outfile && ! $force ]]; then
+        dfatal "Will not override existing initramfs ($outfile) without --force"
+        exit 1
+    fi
+
+    outdir=${outfile%/*}
+    [[ $outdir ]] || outdir="/"
+
+    if [[ ! -d "$outdir" ]]; then
+        dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
+        exit 1
+    elif [[ ! -w "$outdir" ]]; then
+        dfatal "No permission to write to $outdir."
+        exit 1
+    elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
+        dfatal "No permission to write $outfile."
+        exit 1
+    fi
 fi
 
 # Need to be able to have non-root users read stuff (rpcbind etc)
@@ -1041,20 +1057,6 @@ if [[ $print_cmdline ]]; then
     exit 0
 fi
 
-outdir=${outfile%/*}
-[[ $outdir ]] || outdir="/"
-
-if [[ ! -d "$outdir" ]]; then
-    dfatal "Can't write to $outdir: Directory $outdir does not exist or is not accessible."
-    exit 1
-elif [[ ! -w "$outdir" ]]; then
-    dfatal "No permission to write to $outdir."
-    exit 1
-elif [[ -f "$outfile" && ! -w "$outfile" ]]; then
-    dfatal "No permission to write $outfile."
-    exit 1
-fi
-
 # Create some directory structure first
 [[ $prefix ]] && mkdir -m 0755 -p "${initdir}${prefix}"