]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95nbd/nbd-generator.sh
fix: always use mkdir -p
[thirdparty/dracut.git] / modules.d / 95nbd / nbd-generator.sh
1 #!/bin/sh
2
3 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
4
5 [ -z "$root" ] && root=$(getarg root=)
6
7 [ "${root%%:*}" = "nbd" ] || exit 0
8
9 GENERATOR_DIR="$2"
10 [ -z "$GENERATOR_DIR" ] && exit 1
11
12 [ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR"
13
14 ROOTFLAGS="$(getarg rootflags)"
15
16 nroot=${root#nbd:}
17 nbdserver=${nroot%%:*}; nroot=${nroot#*:}
18 nbdport=${nroot%%:*}; nroot=${nroot#*:}
19 nbdfstype=${nroot%%:*}; nroot=${nroot#*:}
20 nbdflags=${nroot%%:*}
21
22 if [ "$nbdflags" = "$nbdfstype" ]; then
23 unset nbdflags
24 fi
25 if [ "$nbdfstype" = "$nbdport" ]; then
26 unset nbdfstype
27 fi
28
29 [ -n "$nbdflags" ] && ROOTFLAGS="$nbdflags"
30
31 if getarg "ro"; then
32 if [ -n "$ROOTFLAGS" ]; then
33 ROOTFLAGS="$ROOTFLAGS,ro"
34 else
35 ROOTFLAGS="ro"
36 fi
37 fi
38
39 if [ -n "$nbdfstype" ]; then
40 ROOTFSTYPE="$nbdfstype"
41 else
42 ROOTFSTYPE=$(getarg rootfstype=) || unset ROOTFSTYPE
43 fi
44
45 {
46 echo "[Unit]"
47 echo "Before=initrd-root-fs.target"
48 echo "[Mount]"
49 echo "Where=/sysroot"
50 echo "What=/dev/root"
51 [ -n "$ROOTFSTYPE" ] && echo "Type=${ROOTFSTYPE}"
52 [ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}"
53 } > "$GENERATOR_DIR"/sysroot.mount
54
55 exit 0