#!/bin/bash # Manipulate options in a .config file from the command line myname=${0##*/} # If no prefix forced, use the default BR2_ BR2_PREFIX="${BR2_PREFIX-BR2_}" usage() { cat >&2 <>"$FN" fi } undef_var() { local name=$1 txt_delete "^$name=" "$FN" txt_delete "^# $name is not set" "$FN" } if [ "$1" = "--file" ]; then FN="$2" if [ "$FN" = "" ] ; then usage fi shift 2 else FN=.config fi if [ "$1" = "" ] ; then usage fi MUNGE_CASE=yes while [ "$1" != "" ] ; do CMD="$1" shift case "$CMD" in --keep-case|-k) MUNGE_CASE=no continue ;; --package|-p) BR2_PREFIX="BR2_PACKAGE_" continue ;; --*-after|-E|-D|-M) checkarg "$1" A=$ARG checkarg "$2" B=$ARG shift 2 ;; -*) checkarg "$1" shift ;; esac case "$CMD" in --enable|-e) set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=y" ;; --disable|-d) set_var "${BR2_PREFIX}$ARG" "# ${BR2_PREFIX}$ARG is not set" ;; --set-str) # sed swallows one level of escaping, so we need double-escaping set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=\"${1//\"/\\\\\"}\"" shift ;; --set-val) set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=$1" shift ;; --undefine|-u) undef_var "${BR2_PREFIX}$ARG" ;; --state|-s) if grep -q "# ${BR2_PREFIX}$ARG is not set" $FN ; then echo n else V="$(grep "^${BR2_PREFIX}$ARG=" $FN)" if [ $? != 0 ] ; then echo undef else V="${V/#${BR2_PREFIX}$ARG=/}" V="${V/#\"/}" V="${V/%\"/}" V="${V//\\\"/\"}" echo "${V}" fi fi ;; --enable-after|-E) set_var "${BR2_PREFIX}$B" "${BR2_PREFIX}$B=y" "${BR2_PREFIX}$A" ;; --disable-after|-D) set_var "${BR2_PREFIX}$B" "# ${BR2_PREFIX}$B is not set" "${BR2_PREFIX}$A" ;; *) usage ;; esac done