1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0-only 2 # SPDX-License-Identifier: GPL-2.0-only 3 3 4 # bootconfig utility functions 4 # bootconfig utility functions 5 5 6 XBC_TMPFILE= 6 XBC_TMPFILE= 7 XBC_BASEDIR=`dirname $0` 7 XBC_BASEDIR=`dirname $0` 8 BOOTCONFIG=${BOOTCONFIG:=$XBC_BASEDIR/../bootc 8 BOOTCONFIG=${BOOTCONFIG:=$XBC_BASEDIR/../bootconfig} 9 if [ ! -x "$BOOTCONFIG" ]; then 9 if [ ! -x "$BOOTCONFIG" ]; then 10 BOOTCONFIG=`which bootconfig` 10 BOOTCONFIG=`which bootconfig` 11 if [ -z "$BOOTCONFIG" ]; then 11 if [ -z "$BOOTCONFIG" ]; then 12 echo "Erorr: bootconfig comman 12 echo "Erorr: bootconfig command is not found" 1>&2 13 exit 1 13 exit 1 14 fi 14 fi 15 fi 15 fi 16 16 17 xbc_cleanup() { 17 xbc_cleanup() { 18 if [ "$XBC_TMPFILE" ]; then 18 if [ "$XBC_TMPFILE" ]; then 19 rm -f "$XBC_TMPFILE" 19 rm -f "$XBC_TMPFILE" 20 fi 20 fi 21 } 21 } 22 22 23 xbc_init() { # bootconfig-file 23 xbc_init() { # bootconfig-file 24 xbc_cleanup 24 xbc_cleanup 25 XBC_TMPFILE=`mktemp bconf-XXXX` 25 XBC_TMPFILE=`mktemp bconf-XXXX` 26 trap xbc_cleanup EXIT TERM 26 trap xbc_cleanup EXIT TERM 27 27 28 $BOOTCONFIG -l $1 > $XBC_TMPFILE || ex 28 $BOOTCONFIG -l $1 > $XBC_TMPFILE || exit 1 29 } 29 } 30 30 31 nr_args() { # args 31 nr_args() { # args 32 echo $# 32 echo $# 33 } 33 } 34 34 35 xbc_get_val() { # key [maxnum] 35 xbc_get_val() { # key [maxnum] 36 if [ "$2" ]; then 36 if [ "$2" ]; then 37 MAXOPT="-L $2" 37 MAXOPT="-L $2" 38 fi 38 fi 39 grep "^$1 =" $XBC_TMPFILE | cut -d= -f 39 grep "^$1 =" $XBC_TMPFILE | cut -d= -f2- | \ 40 sed -e 's/", /" /g' -e "s/',/' 40 sed -e 's/", /" /g' -e "s/',/' /g" | \ 41 xargs $MAXOPT -n 1 echo 41 xargs $MAXOPT -n 1 echo 42 } 42 } 43 43 44 xbc_has_key() { # key 44 xbc_has_key() { # key 45 grep -q "^$1 =" $XBC_TMPFILE 45 grep -q "^$1 =" $XBC_TMPFILE 46 } 46 } 47 47 48 xbc_has_branch() { # prefix-key 48 xbc_has_branch() { # prefix-key 49 grep -q "^$1" $XBC_TMPFILE 49 grep -q "^$1" $XBC_TMPFILE 50 } 50 } 51 51 52 xbc_subkeys() { # prefix-key depth [subkey-pat !! 52 xbc_subkeys() { # prefix-key depth 53 __keys=`echo $1 | sed "s/\./ /g"` 53 __keys=`echo $1 | sed "s/\./ /g"` 54 __s=`nr_args $__keys` 54 __s=`nr_args $__keys` 55 grep "^$1$3" $XBC_TMPFILE | cut -d= -f !! 55 grep "^$1" $XBC_TMPFILE | cut -d= -f1| cut -d. -f$((__s + 1))-$((__s + $2)) | uniq 56 } 56 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.