Modify Makefile to use new test harness
[dracut.git] / dracut
blobeb3ff24a1730b4a05e7ac29f8b9b411f661e54fd
1 #!/bin/bash
2 #
3 # Generator script for a dracut initramfs
4 # Tries to retain some degree of compatibility with the command line
5 # of the various mkinitrd implementations out there
8 # Copyright 2008, Red Hat, Inc. Jeremy Katz <katzj@redhat.com>
9 # GPLv2 header here
11 while (($# > 0)); do
12 case $1 in
13 -f|--force) force=yes;;
14 -m|--modules) dracutmodules_l="$2"; shift;;
15 -d|--drivers) modules_l="$2"; shift;;
16 -h|--help) echo "Usage: $0 [-f] <initramfs> <kernel-version>"
17 exit 1 ;;
18 -v|--verbose) set -x;;
19 -c|--conf) conffile="$2"; shift;;
20 -l|--local) allowlocal="yes" ;;
21 -h|--hostonly) hostonly="-h" ;;
22 --skip-missing) skipmissing="yes" ;;
23 *) break ;;
24 esac
25 shift
26 done
28 [[ -f $conffile ]] || ( [[ -f /etc/dracut.conf ]] && conffile="/etc/dracut.conf" )
29 [[ -f $conffile ]] && . "$conffile"
30 [[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l
31 [[ $modules_l ]] && modules=$modules_l
33 [[ $allowlocal && -f dracut-functions ]] && dsrc="." || dsrc=/usr/lib/dracut
34 . $dsrc/dracut-functions
35 dracutfunctions=$dsrc/dracut-functions
36 export dracutfunctions
38 [[ $dracutmodules ]] || dracutmodules="auto"
39 [[ $dracutmodules = "auto" ]] && {
40 dracutmodules="all"
41 skipmissing="yes"
43 [[ $dracutmodules = "hostonly" ]] && {
44 dracutmodules="all"
45 skipmissing="yes"
46 hostonly="-h"
50 [[ $2 ]] && kernel=$2 || kernel=$(uname -r)
51 [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
53 if [[ -f $outfile && ! $force ]]; then
54 echo "Will not override existing initramfs ($outfile) without --force"
55 exit 1
58 hookdirs="pre-udev pre-mount pre-pivot mount"
60 readonly initdir=$(mktemp -d -t initramfs.XXXXXX)
61 trap 'rm -rf "$initdir"' 0 # clean up after ourselves no matter how we die.
63 export initdir hookdirs dsrc dracutmodules modules
65 # Create some directory structure first
66 for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
67 mkdir -p "$initdir/$d";
68 done
70 skip_missing() {
71 # $1 = location of module
72 [[ $skipmissing ]] || return 0
73 [[ -x $1/check ]] || return 0
74 "$1/check" $hostonly
77 can_source_module() {
78 # $1 = location of module
79 mod=${1##*/}; mod=${mod#[0-9][0-9]};
80 if [[ $dracutmodules != all ]]; then
81 strstr "$dracutmodules " "$mod " || return 1
83 skip_missing "$1"
86 # source all our modules
87 for moddir in "$dsrc/modules.d"/*; do
88 [[ -d $moddir || -L $moddir ]] || continue
89 can_source_module "$moddir" || continue
90 [[ -x $moddir/install ]] && . "$moddir/install"
91 done
92 unset moddir
94 ## final stuff that has to happen
96 # generate module dependencies for the initrd
97 /sbin/depmod -a -b "$initdir" $kernel || {
98 echo "\"/sbin/depmod -a $kernel\" failed."
99 exit 1
102 # make sure that library links are correct and up to date
103 ldconfig -n -r "$initdir" /lib* /usr/lib*
105 ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )