]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/95nbd/nbd-generator.sh
fix: always use mkdir -p
[thirdparty/dracut.git] / modules.d / 95nbd / nbd-generator.sh
CommitLineData
07149fe6
HH
1#!/bin/sh
2
3type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
4
5[ -z "$root" ] && root=$(getarg root=)
6
7[ "${root%%:*}" = "nbd" ] || exit 0
8
9GENERATOR_DIR="$2"
10[ -z "$GENERATOR_DIR" ] && exit 1
11
9cf7b1c5 12[ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR"
07149fe6
HH
13
14ROOTFLAGS="$(getarg rootflags)"
15
16nroot=${root#nbd:}
17nbdserver=${nroot%%:*}; nroot=${nroot#*:}
18nbdport=${nroot%%:*}; nroot=${nroot#*:}
19nbdfstype=${nroot%%:*}; nroot=${nroot#*:}
20nbdflags=${nroot%%:*}
21
22if [ "$nbdflags" = "$nbdfstype" ]; then
23 unset nbdflags
24fi
25if [ "$nbdfstype" = "$nbdport" ]; then
26 unset nbdfstype
27fi
28
29[ -n "$nbdflags" ] && ROOTFLAGS="$nbdflags"
30
31if getarg "ro"; then
32 if [ -n "$ROOTFLAGS" ]; then
33 ROOTFLAGS="$ROOTFLAGS,ro"
34 else
35 ROOTFLAGS="ro"
36 fi
37fi
38
39if [ -n "$nbdfstype" ]; then
40 ROOTFSTYPE="$nbdfstype"
41else
42 ROOTFSTYPE=$(getarg rootfstype=) || unset ROOTFSTYPE
43fi
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
55exit 0