base: hard depend on systemd, if system was started by systemd
[platform/upstream/dracut.git] / mkinitrd-dracut.sh
1 #!/bin/bash --norc
2 kver=$(uname -r)
3
4 error() { echo "$@" >&2; }
5
6 usage () {
7     [[ $1 = '-n' ]] && cmd=echo || cmd=error
8
9     $cmd "usage: ${0##*/} [--version] [--help] [-v] [-f] [--preload <module>]"
10     $cmd "       [--image-version] [--with=<module>]"
11     $cmd "       [--nocompress]"
12     $cmd "       <initrd-image> <kernel-version>"
13     $cmd ""
14     $cmd "       (ex: ${0##*/} /boot/initramfs-$kver.img $kver)"
15
16     [[ $1 = '-n' ]] && exit 0
17     exit 1
18 }
19
20 # Little helper function for reading args from the commandline.
21 # it automatically handles -a b and -a=b variants, and returns 1 if
22 # we need to shift $3.
23 read_arg() {
24     # $1 = arg name
25     # $2 = arg value
26     # $3 = arg parameter
27     local rematch='^[^=]*=(.*)$'
28     if [[ $2 =~ $rematch ]]; then
29         read "$1" <<< "${BASH_REMATCH[1]}"
30     elif [[ $3 != -* ]]; then
31         # Only read next arg if it not an arg itself.
32         read "$1" <<< "$3"
33         # There is no way to shift our callers args, so
34         # return 1 to indicate they should do it instead.
35         return 1
36     fi
37 }
38
39 while (($# > 0)); do
40     case ${1%%=*} in
41         --with-usb) read_arg usbmodule "$@" || shift
42             basicmodules="$basicmodules ${usbmodule:-usb-storage}"
43             unset usbmodule;;
44         --with-avail) read_arg modname "$@" || shift
45             basicmodules="$basicmodules $modname";;
46         --with) read_arg modname "$@" || shift
47             basicmodules="$basicmodules $modname";;
48         --version)
49             echo "mkinitrd: dracut compatibility wrapper"
50             exit 0;;
51         -v|--verbose) dracut_args="${dracut_args} -v";;
52         -f|--force) dracut_args="${dracut_args} -f";;
53         --preload) read_arg modname "$@" || shift
54             basicmodules="$basicmodules $modname";;
55         --image-version) img_vers=yes;;
56         --rootfs) read_arg rootfs "$@" || shift
57             dracut_args="${dracut_args} --filesystems $rootfs";;
58         --nocompress) dracut_args="$dracut_args --no-compress";;
59         --help) usage -n;;
60         --builtin) ;;
61         --without*) ;;
62         --without-usb) ;;
63         --fstab*) ;;
64         --ifneeded) ;;
65         --omit-scsi-modules) ;;
66         --omit-ide-modules) ;;
67         --omit-raid-modules) ;;
68         --omit-lvm-modules) ;;
69         --omit-dmraid) ;;
70         --allow-missing) ;;
71         --net-dev*) ;;
72         --noresume) ;;
73         --rootdev*) ;;
74         --thawdev*) ;;
75         --rootopts*) ;;
76         --root*) ;;
77         --loopdev*) ;;
78         --loopfs*) ;;
79         --loopopts*) ;;
80         --looppath*) ;;
81         --dsdt*) ;;
82         --bootchart) ;;
83         *) if [[ ! $target ]]; then
84             target=$1
85             elif [[ ! $kernel ]]; then
86             kernel=$1
87             else
88             usage
89             fi;;
90     esac
91     shift
92 done
93
94 [[ $target && $kernel ]] || usage
95 [[ $img_vers ]] && target="$target-$kernel"
96
97 if [[ $basicmodules ]]; then
98         dracut $dracut_args --add-drivers "$basicmodules" "$target" "$kernel"
99 else
100         dracut $dracut_args "$target" "$kernel"
101 fi