]>
Commit | Line | Data |
---|---|---|
df44688f DD |
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 | |
9 | } | |
ae5bc1fd | 10 | |
da1c03c8 HH |
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; | |
19 | fi | |
20 | done | |
21 | [ -n "$found" ] && return 0 | |
22 | return 1 | |
23 | } | |
24 | ||
ae5bc1fd DD |
25 | source_all() { |
26 | local f | |
27 | [ "$1" ] && [ -d "/$1" ] || return | |
28 | for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done | |
29 | } | |
51031303 | 30 | |
311a2769 | 31 | die() { |
449adc61 HH |
32 | { |
33 | echo "<1>dracut: FATAL: $@"; | |
34 | echo "<1>dracut: Refusing to continue"; | |
35 | } > /dev/kmsg | |
36 | ||
532d7d9b | 37 | { |
449adc61 HH |
38 | echo "dracut: FATAL: $@"; |
39 | echo "dracut: Refusing to continue"; | |
532d7d9b | 40 | } >&2 |
449adc61 | 41 | |
311a2769 PS |
42 | exit 1 |
43 | } | |
44 | ||
9f10836d | 45 | warn() { |
449adc61 | 46 | echo "<4>dracut Warning: $@" > /dev/kmsg |
532d7d9b | 47 | echo "dracut Warning: $@" >&2 |
449adc61 HH |
48 | } |
49 | ||
50 | info() { | |
c0dc4c5d HH |
51 | if [ -z "$DRACUT_QUIET" ]; then |
52 | DRACUT_QUIET="no" | |
53 | getarg quiet && DRACUT_QUIET="yes" | |
54 | fi | |
449adc61 | 55 | echo "<6>dracut: $@" > /dev/kmsg |
c0dc4c5d HH |
56 | [ "$DRACUT_QUIET" != "yes" ] && \ |
57 | echo "dracut: $@" | |
449adc61 HH |
58 | } |
59 | ||
60 | vinfo() { | |
61 | while read line; do | |
62 | info $line; | |
63 | done | |
9f10836d PS |
64 | } |
65 | ||
51031303 DD |
66 | check_occurances() { |
67 | # Count the number of times the character $ch occurs in $str | |
68 | # Return 0 if the count matches the expected number, 1 otherwise | |
69 | local str="$1" | |
70 | local ch="$2" | |
71 | local expected="$3" | |
72 | local count=0 | |
73 | ||
74 | while [ "${str#*$ch}" != "${str}" ]; do | |
75 | str="${str#*$ch}" | |
76 | count=$(( $count + 1 )) | |
77 | done | |
78 | ||
79 | [ $count -eq $expected ] | |
80 | } | |
07b2fbb1 PS |
81 | |
82 | incol2() { | |
83 | local dummy check; | |
84 | local file="$1"; | |
85 | local str="$2"; | |
86 | ||
87 | [ -z "$file" ] && return; | |
88 | [ -z "$str" ] && return; | |
89 | ||
90 | while read dummy check restofline; do | |
91 | [ "$check" = "$str" ] && return 0 | |
92 | done < $file | |
93 | return 1 | |
94 | } |