Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/bootconfig/scripts/xbc.sh
26288 views
1
#!/bin/sh
2
# SPDX-License-Identifier: GPL-2.0-only
3
4
# bootconfig utility functions
5
6
XBC_TMPFILE=
7
XBC_BASEDIR=`dirname $0`
8
BOOTCONFIG=${BOOTCONFIG:=$XBC_BASEDIR/../bootconfig}
9
if [ ! -x "$BOOTCONFIG" ]; then
10
BOOTCONFIG=`which bootconfig`
11
if [ -z "$BOOTCONFIG" ]; then
12
echo "Erorr: bootconfig command is not found" 1>&2
13
exit 1
14
fi
15
fi
16
17
xbc_cleanup() {
18
if [ "$XBC_TMPFILE" ]; then
19
rm -f "$XBC_TMPFILE"
20
fi
21
}
22
23
xbc_init() { # bootconfig-file
24
xbc_cleanup
25
XBC_TMPFILE=`mktemp bconf-XXXX`
26
trap xbc_cleanup EXIT TERM
27
28
$BOOTCONFIG -l $1 > $XBC_TMPFILE || exit 1
29
}
30
31
nr_args() { # args
32
echo $#
33
}
34
35
xbc_get_val() { # key [maxnum]
36
if [ "$2" ]; then
37
MAXOPT="-L $2"
38
fi
39
grep "^$1 =" $XBC_TMPFILE | cut -d= -f2- | \
40
sed -e 's/", /" /g' -e "s/',/' /g" | \
41
xargs $MAXOPT -n 1 echo
42
}
43
44
xbc_has_key() { # key
45
grep -q "^$1 =" $XBC_TMPFILE
46
}
47
48
xbc_has_branch() { # prefix-key
49
grep -q "^$1" $XBC_TMPFILE
50
}
51
52
xbc_subkeys() { # prefix-key depth [subkey-pattern]
53
__keys=`echo $1 | sed "s/\./ /g"`
54
__s=`nr_args $__keys`
55
grep "^$1$3" $XBC_TMPFILE | cut -d= -f1| cut -d. -f$((__s + 1))-$((__s + $2)) | uniq
56
}
57
58