Merge tag 'block-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / bootconfig / scripts / xbc.sh
blobb8c84e65455623a7bce3a9f7e5418d68f4f7c120
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-only
4 # bootconfig utility functions
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
17 xbc_cleanup() {
18 if [ "$XBC_TMPFILE" ]; then
19 rm -f "$XBC_TMPFILE"
23 xbc_init() { # bootconfig-file
24 xbc_cleanup
25 XBC_TMPFILE=`mktemp bconf-XXXX`
26 trap xbc_cleanup EXIT TERM
28 $BOOTCONFIG -l $1 > $XBC_TMPFILE || exit 1
31 nr_args() { # args
32 echo $#
35 xbc_get_val() { # key [maxnum]
36 if [ "$2" ]; then
37 MAXOPT="-L $2"
39 grep "^$1 =" $XBC_TMPFILE | cut -d= -f2- | \
40 sed -e 's/", /" /g' -e "s/',/' /g" | \
41 xargs $MAXOPT -n 1 echo
44 xbc_has_key() { # key
45 grep -q "^$1 =" $XBC_TMPFILE
48 xbc_has_branch() { # prefix-key
49 grep -q "^$1" $XBC_TMPFILE
52 xbc_subkeys() { # prefix-key depth
53 __keys=`echo $1 | sed "s/\./ /g"`
54 __s=`nr_args $__keys`
55 grep "^$1" $XBC_TMPFILE | cut -d= -f1| cut -d. -f$((__s + 1))-$((__s + $2)) | uniq