|
|
# --- ROCK-COPYRIGHT-NOTE-BEGIN --- # # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # Please add additional copyright information _after_ the line containing # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by # the ./scripts/Create-CopyPatch script. Do not edit this copyright text! # # ROCK Linux: rock-src/scripts/config.func # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. A copy of the GNU General Public # License can be found at Documentation/COPYING. # # Many people helped and are helping developing ROCK Linux. Please # have a look at http://www.rocklinux.org/ and the Documentation/TEAM # file for details. # # --- ROCK-COPYRIGHT-NOTE-END ---
# This function appends or inserts values to a variable: # # var_append PATH ":" "$HOME/bin" # var_insert PATH ":" "$HOME/bin" # var_append() { eval "[ \"\$$1\" ] && $1=\"\${$1}$2\"" eval "$1=\"\${$1}$3\"" } var_insert() { eval "[ \"\$$1\" ] && $1=\"$2\$$1\"" eval "$1=\"$3\$$1\"" }
# Functions for working with config/$config.$swpid/packages # # pkgenable package-list # pkgdisable package-list # pkgremove package-list # pkgcheck pattern X|O|. # pkgfilter cmd arg1 ... # if [ -n "$nobashmod" ] then pkgin() { :; } pkgout() { :; } __pkgfilter() { "$@" < config/$config.$swpid/packages > config/$config.$swpid/packages.new mv config/$config.$swpid/packages.new config/$config.$swpid/packages } pkgfilter() { bprof pkgfilter start __pkgfilter "$@" bprof pkgfilter stop } pkgenable() { bprof pkgenable start local pattern patterns for pattern; do patterns="$patterns -e '/ $pattern / s/^./X/'" done if [ "$patterns" ]; then eval "__pkgfilter sed $patterns" fi bprof pkgenable stop } pkgdisable() { bprof pkgdisable start local pattern patterns for pattern; do patterns="$patterns -e '/ $pattern / s/^./O/'" done if [ "$patterns" ]; then eval "__pkgfilter sed $patterns" fi bprof pkgdisable stop } pkgremove() { bprof pkgremove start local pattern patterns if [ "$1" ]; then patterns=" $1 "; shift for pattern; do patterns="$patterns| $pattern " done __pkgfilter egrep -v "$patterns" fi bprof pkgremove stop } pkgcheck() { bprof pkgcheck start local pattern="$1"; pattern="${pattern//+/\\+}" egrep -q "^$2.*[ =]($pattern) " config/$config.$swpid/packages; local ret=$? bprof pkgcheck stop return $ret } else pkgin() { cfghlp pkg_in config/$config.$swpid/packages; } pkgout() { cfghlp pkg_out config/$config.$swpid/packages ; } pkgfilter() { bprof pkgfilter start cfghlp pkg_out config/$config.$swpid/packages.tmp "$@" < config/$config.$swpid/packages.tmp > config/$config.$swpid/packages cfghlp pkg_in config/$config.$swpid/packages bprof pkgfilter stop } pkgenable() { bprof pkgenable start cfghlp pkgenable "$@" bprof pkgenable stop } pkgdisable() { bprof pkgdisable start cfghlp pkgdisable "$@" bprof pkgdisable stop } pkgremove() { bprof pkgremove start cfghlp pkgremove "$@" bprof pkgremove stop } pkgcheck() { bprof pkgcheck start cfghlp pkgcheck "$1" "$2"; local ret=$? bprof pkgcheck stop return $ret } fi
# # pkgfork <origpkg> <newpkg> <name1> <value1> <name2> <value2> .. # # Names: # status X / O # stages 012--5---9 # priority 115.000 # version 0.9.26 # prefix /opt/foobar # flag CORE # unflag CORE # pkgfork() { local script="\$5==\"$1\" {print;\$5=\"$1=$2\";" shift; shift; while [ -n "$1" ]; do case "$1" in status) script="$script \$1=\"$2\";" ;; stages) script="$script \$2=\"$2\";" ;; priority) script="$script \$3=\"$2\";" ;; version) script="$script \$6=\"$2\";" ;; prefix) script="$script \$7=\"$2\";" ;; flag) script="$script sub(\" 0\$\", \" $2 0\");" ;; unflag) script="$script sub(\" $2 \", \" \");" ;; esac shift; shift; done script="$script} {print;}" pkgfilter "awk" "--" "$script" }
comment() { bprof comment start if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && \ [ $menu_current = $menu_this ] ; then commentnr=$(( $commentnr + 1 )) echo "COMMENT_$commentnr '$spacer$1'" >> config.dialog.$swpid
# Hi, esden here, very ill stuff here I save the help # strings here to a temporary file named config.help.$swpid # this sed tr sandwitch formats the string so that # \n are masked and the Help strings are not killed some way if [ "$2" != "" ] ; then set_help "COMMENT_$commentnr" "$2" fi fi bprof comment stop }
comment_id() { bprof comment_id start if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_this ] ; then echo "$2 '$spacer$1'" >> config.dialog.$swpid
# If you do not know what mighty esden # is doing here see comment() if [ "$3" != "" ] ; then set_help "$2" "$3" fi fi bprof comment_id stop }
const() { bprof const start local q="'" local v="${2//$q/$q\\$q$q}" eval "$1=\"\$2\"" echo "export $1='$v'" >> config/$config.$swpid/config bprof const stop }
# Usage: set_data NAME DEFAULT # set_data() { bprof set_data start local q="'"
set_name="ROCKCFGSET_${1#ROCKCFG_}" usr_name="ROCKCFGUSR_${1#ROCKCFG_}" eval "usr_data=\"\$$usr_name\""
menumode=0 data="$2"
if eval "[ \"\$$set_name\" ]"; then eval "data=\"\$$set_name\"" fi dfl_data="$data"
if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]; then menumode=2 if [ $nousrconfig -eq 1 ] && eval "[ -n \"\$$1\" -a \"\$$1\" != \"\$data\" ]"; then eval "$usr_name=\"\$$1\"" eval "usr_data=\"\$$1\"" fi if [ -n "$usr_data" ]; then data="$usr_data" obegin="<" oend=">" menumode=1 else unset $usr_name fi fi
eval "$1=\"\$data\"" item="$1"
echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config.$swpid/config bprof set_data stop }
choice() { bprof choice start local obegin="(" oend=")" local q="'"
set_data "$1" "$2"
# if data is not in list, leave usr_data unmodified # but set the current value to the default local fallback_hack=0 eval $( shift; shift while [ "$#" != 0 ] ; do [ "$data" = "$1" ] && exit shift; shift done echo "fallback_hack=1" ) if [ "$fallback_hack" = 1 ]; then obegin="?"; oend="?"; data="$dfl_data"; eval "$1=\"\$data\"" echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config.$swpid/config fi
if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then { echo -en "$item\tchoice_action '$usr_name' '$usr_data'" ; shift ; shift echo -n " '' 'Reset_this_switch_to_default_value'" for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data.$swpid
xdata="$obegin$data$oend"
while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" "$xdata" >> config.dialog.$swpid fi
bprof choice stop }
choice_action() { command="./src/rockdialog.bin --title 'Build Config' \ --backtitle '$configtitle' \ --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \ $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))" default=$2 ; item=$1 ; shift ; shift while [ "$#" -gt 1 ] ; do if [ "$1" = "$default" ] then command="$command '$1' '${2//_/ }' ON" else command="$command '$1' '${2//_/ }' OFF" ; fi shift ; shift done eval "$command" 2> config.out.$swpid
case "$?" in 0|6) eval "$item='`cat config.out.$swpid`'" ;; 1|255) return 0 ;; 2) echo "No help." ; sleep 1 ;; *) echo "unknown returncode: $?" ; exit 1 ;; esac }
text() { bprof text start local q="'" obegin="(" oend=")" set_data "$2" "$3"
if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then echo -e "$2\ttext_action '$1' '$usr_name'" \ "'${data//$q/$q\\$q$q}'" >> config.data.$swpid
xdata="${obegin}$( printf "%-${tabspace}s" \ "$(echo $data | cut -c1-20)")${oend}"
printf "'$2' '$spacer%s $1'\n" \ "${xdata//$q/$q\\$q$q}" >> config.dialog.$swpid
# If you do not know what mighty esden # is doin here see comment() if [ "$4" != "" ] ; then set_help "$2" "$4" fi fi bprof text stop }
text_action() { ./src/rockdialog.bin --title 'Build Config' \ --backtitle "$configtitle" \ --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> config.out.$swpid [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat config.out.$swpid)\"" }
bool() { bprof bool start local x obegin="[" oend="]" set_data "$2" "$3"
if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then if [ $data -eq 0 ] ; then x="${obegin} ${oend}" ; else x="${obegin}*${oend}" ; fi echo -e "$2\tbool_action '$usr_name' '$usr_data' '$3'" >> config.data.$swpid
printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" "$x" >> config.dialog.$swpid
# If you do not know what mighty esden is doin here see comment() if [ "$4" != "" ] ; then set_help "$2" "$4" fi fi bprof bool stop }
bool_action() { local usrvar=$1 local origval=$3 local usrval eval "usrval=\${$usrvar}" case "$usrval" in "") [ "$origval" == "0" ] && eval "$usrvar=1" [ "$origval" == "1" ] && eval "$usrvar=0" ;; 1) [ "$origval" == "0" ] && eval "$usrvar=0" [ "$origval" == "1" ] && eval "$usrvar=" ;; 0) [ "$origval" == "0" ] && eval "$usrvar=" [ "$origval" == "1" ] && eval "$usrvar=1" ;; esac }
editfile() { bprof editfile start if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then local x="$spacer" q="'" comment ",----< $3 >----." block_begin 0 ; spacer="${spacer%??}| "
touch "$2" line_nr=1 while read line ; do line="${line//$q/$q\\$q$q}" if [ $menu_current = $menu_this ] ; then printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \ `printf "%03d:" $line_nr` "$line" >> config.dialog.$swpid
echo -e "$1:${editfilenr}\teditfile_action $2" \ "$line_nr '$3'" >> config.data.$swpid fi
editfilenr=$(( $editfilenr + 1 )) line_nr=$(( $line_nr + 1 )) done < "$2"
if [ $menu_current = $menu_this ] ; then printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \ `printf "%03d:" $line_nr` "<add new rule>" >> config.dialog.$swpid
echo -e "$1:${editfilenr}\teditfile_action $2" \ "$line_nr '$3'" >> config.data.$swpid fi
editfilenr=$(( $editfilenr + 1 ))
block_end comment "\`------${3//?/-}------'\''" spacer="$x" else rm -f "$2" fi bprof editfile stop }
editfile_action() { line="`tail -n +$2 $1 | head -n 1`"
./src/rockdialog.bin --title 'Build Config' \ --backtitle "$configtitle" \ --inputbox "$3 - Line $3" \ 9 $(( $columns - 5 )) "$line" 2> config.out.$swpid
head -n $(( $2 - 1 )) $1 > $1.new [ -s config.out.$swpid ] && echo "`cat config.out.$swpid`" >> $1.new tail -n +$(( $2 + 1 )) $1 >> $1.new
mv $1.new $1 }
startprog() { bprof startprog start if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_this ] ; then printf "$1 '$spacer%-${tabspace}s %s'\n" \ "-->" "$2" >> config.dialog.$swpid echo -e "$1\t$3" >> config.data.$swpid fi bprof startprog stop }
block_begin() { bprof block_begin start if [ $menu_current = $menu_this ] ; then [ "$tabspace_list" ] && spacer="$spacer " tabspace_list="$tabspace $tabspace_list" tabspace="$(( $tabspace + $1 - 2 ))" fi bprof block_begin stop }
block_end() { bprof block_end start if [ $menu_current = $menu_this ] ; then spacer="${spacer%??}" tabspace="${tabspace_list%% *}" tabspace_list="${tabspace_list#* }" fi bprof block_end stop }
expert_begin() { expert=$(( $exprt + 1 )) }
expert_end() { expert=$(( $exprt - 1 )) }
menu_begin() { bprof menu_begin start menu_counter=$(( $menu_counter + 1 ))
if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_this ] ; then printf "$1 '$spacer%-${tabspace}s %s'\n" \ "===>" "$2" >> config.dialog.$swpid echo -e "$1\tmenu_current=$menu_counter" >> config.data.$swpid fi if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_counter ] ; then echo "$1 '===> $2'" >> config.dialog.$swpid echo -e "$1\tmenu_current=$menu_this" >> config.data.$swpid fi
if [ $menu_current = $menu_counter ] ; then menu_back=$menu_this menu_backpos=$1 fi
menu_stack="$menu_this $menu_stack" menu_this=$menu_counter
block_begin 3 bprof menu_begin stop }
menu_end() { bprof menu_end start block_end menu_this="${menu_stack%% *}" menu_stack="${menu_stack#* }" bprof menu_end stop }
set_help() { bprof set_help start (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' | tr -d '\n' | sed 's,\\n$,,'; echo ) >> config.help.$swpid bprof set_help stop }
get_help() { bprof get_help start
cat << EOT
This is the ROCK Linux $rockver Configuration Tool.
Config option types: [*] [ ] Unmodified bool value (set and unset) <*> < > User-modified bool value (set and unset) (foobar) Unmodified selection or text field <foobar> User-modified selection or text field
Note that e.g. bool value are in fact tristate options: user set, user unset and and the unmodified default value
This is because one option might change the default value of another option. You might need a while to get used to the concept, but in the end it really makes sense.
----- EOT
# Create standard help output ... default_text=" There is no help on '$1' available.
Please read the build Documentation (Documentation/BUILD) before building ROCK Linux.
More information can be found on the ROCK Linux Homepage:
http://www.rocklinux.org/
Information about the ROCK Linux mailing lists and the mailing list archive can be found at:
http://www.rocklinux.org/mail.html and http://www.rocklinux.net/lurker/splash" # Ok let us find a help for the current item ...
# First of all mask all special chars in the item name # Comment: this is sick. You can't get any \n this way !!! item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' ) # Now search *.hlp files hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${ /^$item_name[ ]*\$/c\\ $item_name:\\
/^#/d /^[^ ]/q s/^ // p }" scripts/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp misc/*/config*.hlp misc/*/*/config*.hlp 2>/dev/null ) # Get help strings out of the temporary file. tmp_text=$(grep "^$item_name" config.help.$swpid | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
# Let us see what we have ... if [ "$hlp_text" -a "$tmp_text" ] ; then echo " There are two help text's... one in one of the config.in files and one in one of the config.hlp files. Please remove one of them to get rid of this message here.
Here the one out of config.in:
$tmp_text
Here the one out of config.hlp:
$hlp_text" elif [ "$hlp_text" ] ; then echo "$hlp_text" elif [ "$tmp_text" ] ; then echo "$tmp_text" else echo "$default_text" fi bprof get_help stop }
|