# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: lib/sde-config/functions.in # Copyright (C) 2006 - 2008 The OpenSDE Project # Copyright (C) 2004 - 2006 The T2 SDE Project # Copyright (C) 1998 - 2003 Clifford Wolf # # More information can be found in the files COPYING and README. # # 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; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- SDE-COPYRIGHT-NOTE-END --- . lib/core-functions.in # Function to cache config.in and subconfig.in file lists # create_configin_list() { bprof cache_configin_list start if [ ! -f $cfgtmpdir/noexpert-config.in -o ! -f $cfgtmpdir/expert-config.in ]; then local file= prio= name= rm -f $cfgtmpdir/{no,}expert-config.in{,.$$} rm -f $cfgtmpdir/subconfig-*.in{,.$$} touch $cfgtmpdir/{no,}expert-config.in{,.$$} # config.in # FIXME: this expression may produce duplicated entries!! //mnemoc ls -1 {package/*,misc,lib}/*/config{,-[a-z]*}{,-[0-9]*}.in 2> /dev/null | while read file; do prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )" if [ ${prio:-750} -le 500 ]; then echo "$prio $file" >> $cfgtmpdir/noexpert-config.in.$$ else echo "${prio:-750} $file" >> $cfgtmpdir/expert-config.in.$$ fi done sort -u $cfgtmpdir/noexpert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/noexpert-config.in sort -u $cfgtmpdir/expert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/expert-config.in rm -f $cfgtmpdir/{no,}expert-config.in.$$ # subconfig.in ls -1 package/*/*/subconfig-[a-z]*.in 2> /dev/null | while read file; do prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )" name="$( echo "${file##*/}" | sed -e "s,-\([0-9]*\).in,.in," )" echo "${prio:-750} $file" >> $cfgtmpdir/$name.$$ done for file in $cfgtmpdir/subconfig-[a-z]*.in.$$; do sort -n $file | sed 's,^[^ ]* ,. ,g' > ${file%.$$} rm -f $file done fi bprof cache_configin_list stop } # Function to cache config.in and subconfig.in file lists # create_dot_in_lists() { local file= x= y= # {architecture,misc,lib,target,package/*}/*/{pre,post}config.in bprof cache_dotin_list start for x in preconfig.in postconfig.in; do for y in architecture misc lib target; do file=$cfgtmpdir/$y-$x if [ ! -f $file ]; then ls -1 $y/*/$x 2> /dev/null | sed 's,^,. ,' > $file fi done y=package file=$cfgtmpdir/$y-$x if [ ! -f $file ]; then ls -1 $y/*/*/$x 2> /dev/null | sed 's,^,. ,' > $file fi done bprof cache_dotin_list stop # and {sub,}config.in, which is more complex create_configin_list } hack_stages() { local stage="$1----------"; shift local pkgs="$*" if [ $# -gt 1 ]; then pkgs="${pkgs// /\|}" elif [ $# -eq 1 ]; then true fi if [ "$pkgs" ]; then pkgfilter sed -e "s,^\(.\) [^ ]* \([^ ]*\) \([^ ]*\) \($pkgs\) ,\1 ${stage:0:10} \2 \3 \4 ," fi } # Functions for working with config/$config/packages # # pkgenable package-list # pkgdisable package-list # pkgremove package-list # pkgcheck pattern X|O|. # pkgfilter cmd arg1 ... # if [ -n "$nobashmod" ] then pkgin() { :; } pkgout() { :; } __pkgfilter() { "$@" < $cfgtmpdir/config/packages > $cfgtmpdir/packages.new mv $cfgtmpdir/packages.new $cfgtmpdir/config/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) " $cfgtmpdir/config/packages; local ret=$? bprof pkgcheck stop return $ret } else pkgin() { cfghlp pkg_in $cfgtmpdir/config/packages; } pkgout() { cfghlp pkg_out $cfgtmpdir/config/packages ; } pkgfilter() { bprof pkgfilter start cfghlp pkg_out $cfgtmpdir/packages.tmp "$@" < $cfgtmpdir/packages.tmp > $cfgtmpdir/config/packages cfghlp pkg_in $cfgtmpdir/config/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 # pkgchecklicense -- checks for files with license issues pkgchecklicense() { rm -f $cfgtmpdir/license-issue.* while read a b c repo pkg dummy; do if grep -E "\[(L|LICENSE)\][ ]*(Commercial|Restricted)" \ package/$repo/$pkg/$pkg.desc &> /dev/null; then echo $pkg >> $cfgtmpdir/license-issue.ask fi done < <(grep "^X" $cfgtmpdir/config/packages) } comment() { bprof comment start if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && \ [ $menu_current = $menu_this ] ; then commentnr=$(( $commentnr + 1 )) echo "COMMENT_$commentnr '$spacer$1'" >> $cfgtmpdir/config.dialog if [ "$2" != "" ] ; then set_help "COMMENT_$commentnr" "$2" fi fi bprof comment stop } comment_id() { bprof comment_id start if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_this ] ; then echo "$2 '$spacer$1'" >> $cfgtmpdir/config.dialog 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'" >> $cfgtmpdir/config/config bprof const stop } # Usage: set_data NAME DEFAULT # set_data() { bprof set_data start local q="'" set_name="SDECFGSET_${1#SDECFG_}" if eval "[ \"\$$set_name\" ]" ; then eval "data=\"\$$set_name\"" eval "$1=\"\$data\"" if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] then menumode=2 ; else menumode=0 ; fi elif [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then eval "data=\"\${$1:-$2}\"" eval "$1=\"\$data\"" menumode=1 else data="$2" ; eval "$1=\"\$data\"" menumode=0 fi item="$1" echo "export $1='${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config/config bprof set_data stop } choice() { bprof choice start # desired default value # local defval="$2" # reset to default if current value is not in list # and default to first element if it's not in list # eval $( eval "value=\$$1" ; name=$1 ; dval=$defval; shift ; shift while [ "$#" != 0 ] ; do [ "$dval" = "$1" ] && dval= [ "$value" = "$1" ] && name= ; shift ; shift done [ "$dval" ] && echo "unset defval;" [ "$name" ] && echo "unset $name" ) set_data "$1" "${defval:-$3}" if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then { $ECHO_E -n "$item\tchoice_action '$1' '$data'" ; shift ; shift for x ; do echo -n " '$x'" ; done ; echo ; } >> $cfgtmpdir/config.data fi if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then if [ "$menumode" -eq 1 ] ; then xdata="($data)" else xdata="=$data=" ; fi while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \ "$xdata" >> $cfgtmpdir/config.dialog fi bprof choice stop } choice_action() { command="./tmp/confdialog.bin --title 'Build Config' \ --backtitle '$configtitle' \ --radiolist 'Arrow keys navigate the menu. Press to activate menu items. Highlighted letters are hotkeys.' \ $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))" default=$2 ; item=$1 ; shift ; shift while [ "$1" ] ; do if [ "$1" = "$default" ] then command="$command '$1' '${2//_/ }' ON" else command="$command '$1' '${2//_/ }' OFF" ; fi shift ; shift done eval "$command" 2> $cfgtmpdir/config.out case "$?" in 0|6) eval "$item='`cat $cfgtmpdir/config.out`'" ;; 1|255) return 0 ;; 2) echo "No help." ; sleep 1 ;; *) echo "unknown returncode: $?" ; exit 1 ;; esac } text() { bprof text start local q="'" set_data "$2" "$3" if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then $ECHO_E "$2\ttext_action '$1' '$2'" \ "'${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config.data fi if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then xdata="$( printf "%-${tabspace}s" \ "$(echo $data | cut -c1-20)")" if [ "$menumode" -eq 1 ] ; then xdata="($xdata)" else xdata="=$xdata=" ; fi printf "'$2' '$spacer%s $1'\n" \ "${xdata//$q/$q\\$q$q}" >> $cfgtmpdir/config.dialog if [ "$4" != "" ] ; then set_help "$2" "$4" fi fi bprof text stop } text_action() { ./tmp/confdialog.bin --title 'Build Config' \ --backtitle "$configtitle" \ --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> $cfgtmpdir/config.out [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat $cfgtmpdir/config.out)\"" } bool() { bprof bool start local x set_data "$2" "$3" if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then $ECHO_E "$2\tbool_action '$1' '$2' '$data'" >> $cfgtmpdir/config.data fi if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then if [ "$menumode" -eq 1 ] ; then if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi else if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi fi printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \ "$x" >> $cfgtmpdir/config.dialog if [ "$4" != "" ] ; then set_help "$2" "$4" fi fi bprof bool stop } bool_action() { if [ $3 -eq 0 ] ; then eval "$2=1" else eval "$2=0" ; fi } editfile() { bprof editfile start if [ $SDECFG_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" >> $cfgtmpdir/config.dialog $ECHO_E "$1:${editfilenr}\teditfile_action $2" \ "$line_nr '$3'" >> $cfgtmpdir/config.data 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` "" >> $cfgtmpdir/config.dialog $ECHO_E "$1:${editfilenr}\teditfile_action $2" \ "$line_nr '$3'" >> $cfgtmpdir/config.data 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`" ./tmp/confdialog.bin --title 'Build Config' \ --backtitle "$configtitle" \ --inputbox "$3 - Line $3" \ 9 $(( $columns - 5 )) "$line" 2> $cfgtmpdir/config.out head -n $(( $2 - 1 )) $1 > $1.new [ -s $cfgtmpdir/config.out ] && echo "`cat $cfgtmpdir/config.out`" >> $1.new tail -n +$(( $2 + 1 )) $1 >> $1.new mv $1.new $1 } startprog() { bprof startprog start if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_this ] ; then printf "$1 '$spacer%-${tabspace}s %s'\n" \ "-->" "$2" >> $cfgtmpdir/config.dialog $ECHO_E "$1\t$3" >> $cfgtmpdir/config.data 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 [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_this ] ; then printf "$1 '$spacer%-${tabspace}s %s'\n" \ "===>" "$2" >> $cfgtmpdir/config.dialog $ECHO_E "$1\tmenu_current=$menu_counter" >> $cfgtmpdir/config.data fi if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && [ $menu_current = $menu_counter ] ; then echo "$1 '===> $2'" >> $cfgtmpdir/config.dialog $ECHO_E "$1\tmenu_current=$menu_this" >> $cfgtmpdir/config.data 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_E -n "$1 '$1:\n\n$2'" | sed 's,$,\\n,' | tr -d '\n' | sed 's,\\n$,,'; echo ) >> $cfgtmpdir/config.help bprof set_help stop } get_help() { bprof get_help start # Create standard help output ... default_text=" There is no help on '$1' available. This is the OpenSDE ($sdever) Configuration Tool. More information can be found on the OpenSDE Homepage: http://www.opensde.org/ A Bugtracker, Source Browser and Wiki can be found here: http://trac.opensde.org/ Subscribe to the mailing list by sending an empty e-mail to: and confirm the subscription request by replying to the mail our mailing list manager will send you." # 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 }" lib/*/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp 2>/dev/null ) # Get help strings out of the temporary file. tmp_text=$(grep "^$item_name" $cfgtmpdir/config.help | 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 }