dracut-lib: output warn() and die() to stderr
[dracut/plouj.git] / modules.d / 99base / dracut-lib.sh
blob235e313e0543a749c609596feef376cebd7c3024
1 getarg() {
2 local o line
3 [ "$CMDLINE" ] || read CMDLINE </proc/cmdline;
4 for o in $CMDLINE; do
5 [ "$o" = "$1" ] && return 0
6 [ "${o%%=*}" = "${1%=}" ] && { echo ${o#*=}; return 0; }
7 done
8 return 1
11 getargs() {
12 local o line found
13 [ "$CMDLINE" ] || read CMDLINE </proc/cmdline;
14 for o in $CMDLINE; do
15 [ "$o" = "$1" ] && return 0
16 if [ "${o%%=*}" = "${1%=}" ]; then
17 echo -n "${o#*=} ";
18 found=1;
20 done
21 [ -n "$found" ] && return 0
22 return 1
25 source_all() {
26 local f
27 [ "$1" ] && [ -d "/$1" ] || return
28 for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done
31 die() {
33 echo "<1>dracut: FATAL: $@";
34 echo "<1>dracut: Refusing to continue";
35 } > /dev/kmsg
38 echo "dracut: FATAL: $@";
39 echo "dracut: Refusing to continue";
40 } >&2
42 exit 1
45 warn() {
46 echo "<4>dracut Warning: $@" > /dev/kmsg
47 echo "dracut Warning: $@" >&2
50 info() {
51 [ "$DRACUT_QUIET" ] || DRACUT_QUIET="x$(getarg quiet)"
52 echo "<6>dracut: $@" > /dev/kmsg
53 [ "$DRACUT_QUIET" != "xquiet" ] && \
54 echo "dracut: $@" > /dev/console
57 vinfo() {
58 while read line; do
59 info $line;
60 done
63 check_occurances() {
64 # Count the number of times the character $ch occurs in $str
65 # Return 0 if the count matches the expected number, 1 otherwise
66 local str="$1"
67 local ch="$2"
68 local expected="$3"
69 local count=0
71 while [ "${str#*$ch}" != "${str}" ]; do
72 str="${str#*$ch}"
73 count=$(( $count + 1 ))
74 done
76 [ $count -eq $expected ]
79 incol2() {
80 local dummy check;
81 local file="$1";
82 local str="$2";
84 [ -z "$file" ] && return;
85 [ -z "$str" ] && return;
87 while read dummy check restofline; do
88 [ "$check" = "$str" ] && return 0
89 done < $file
90 return 1