OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

608 lines
15 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-config/functions.in
  5. # Copyright (C) 2006 - 2011 The OpenSDE Project
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. # Copyright (C) 1998 - 2003 Clifford Wolf
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. . lib/core-functions.in
  17. # extract first value of a "^#Foo: ..." line from a set of files
  18. #
  19. get_field() {
  20. local label="$1"; shift
  21. sed -n -e "s/^#[ \t]*$label:[ \t]*\(.*\)/\1/p" "$@" 2> /dev/null |
  22. head -n1 | sed -e 's,[ \t]*$,,'
  23. }
  24. # Function to cache config.in and subconfig.in file lists
  25. #
  26. create_configin_list() {
  27. bprof cache_configin_list start
  28. if [ ! -f $cfgtmpdir/noexpert-config.in -o ! -f $cfgtmpdir/expert-config.in ]; then
  29. local file= prio= name=
  30. rm -f $cfgtmpdir/{no,}expert-config.in{,.$$}
  31. rm -f $cfgtmpdir/subconfig-*.in{,.$$}
  32. touch $cfgtmpdir/{no,}expert-config.in{,.$$}
  33. # config.in
  34. # FIXME: this expression may produce duplicated entries!! //mnemoc
  35. ls -1 {package/*,misc,lib}/*/config{,-[a-z]*}{,-[0-9]*}.in 2> /dev/null | while read file; do
  36. prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )"
  37. if [ ${prio:-750} -le 500 ]; then
  38. echo "$prio $file" >> $cfgtmpdir/noexpert-config.in.$$
  39. else
  40. echo "${prio:-750} $file" >> $cfgtmpdir/expert-config.in.$$
  41. fi
  42. done
  43. sort -u $cfgtmpdir/noexpert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/noexpert-config.in
  44. sort -u $cfgtmpdir/expert-config.in.$$ | sed 's,^[^ ]* ,. ,g' > $cfgtmpdir/expert-config.in
  45. rm -f $cfgtmpdir/{no,}expert-config.in.$$
  46. # subconfig.in
  47. ls -1 package/*/*/subconfig-[a-z]*.in 2> /dev/null | while read file; do
  48. prio="$( echo "${file##*/}" | sed -n -e "s,.*-\([0-9]*\).in,\1,p" )"
  49. name="$( echo "${file##*/}" | sed -e "s,-\([0-9]*\).in,.in," )"
  50. echo "${prio:-750} $file" >> $cfgtmpdir/$name.$$
  51. done
  52. for file in $cfgtmpdir/subconfig-[a-z]*.in.$$; do
  53. sort -n $file | sed 's,^[^ ]* ,. ,g' > ${file%.$$}
  54. rm -f $file
  55. done
  56. fi
  57. bprof cache_configin_list stop
  58. }
  59. # Function to cache config.in and subconfig.in file lists
  60. #
  61. create_dot_in_lists() {
  62. local file= x= y=
  63. # {architecture,misc,lib,target,package/*}/*/{pre,post}config.in
  64. bprof cache_dotin_list start
  65. for x in preconfig.in postconfig.in; do
  66. for y in architecture misc lib target; do
  67. file=$cfgtmpdir/$y-$x
  68. if [ ! -f $file ]; then
  69. ls -1 $y/*/$x 2> /dev/null | sed 's,^,. ,' > $file
  70. fi
  71. done
  72. y=package
  73. file=$cfgtmpdir/$y-$x
  74. if [ ! -f $file ]; then
  75. ls -1 $y/*/*/$x 2> /dev/null | sed 's,^,. ,' > $file
  76. fi
  77. done
  78. bprof cache_dotin_list stop
  79. # and {sub,}config.in, which is more complex
  80. create_configin_list
  81. }
  82. hack_stages() {
  83. local stage="$1----------"; shift
  84. local pkgs="$*"
  85. if [ $# -gt 1 ]; then
  86. pkgs="${pkgs// /\|}"
  87. elif [ $# -eq 1 ]; then
  88. true
  89. fi
  90. if [ "$pkgs" ]; then
  91. pkgfilter sed -e "s,^\(.\) [^ ]* \([^ ]*\) \([^ ]*\) \($pkgs\) ,\1 ${stage:0:10} \2 \3 \4 ,"
  92. fi
  93. }
  94. # Functions for working with config/$config/packages
  95. #
  96. # pkgenable package-list
  97. # pkgdisable package-list
  98. # pkgremove package-list
  99. # pkgcheck pattern X|O|.
  100. # pkgfilter cmd arg1 ...
  101. #
  102. if [ -n "$nobashmod" ]
  103. then
  104. pkgin() { :; }
  105. pkgout() { :; }
  106. __pkgfilter() {
  107. "$@" < $cfgtmpdir/config/packages > $cfgtmpdir/packages.new
  108. mv $cfgtmpdir/packages.new $cfgtmpdir/config/packages
  109. }
  110. pkgfilter() {
  111. bprof pkgfilter start
  112. __pkgfilter "$@"
  113. bprof pkgfilter stop
  114. }
  115. pkgenable() {
  116. bprof pkgenable start
  117. local pattern patterns
  118. for pattern; do
  119. patterns="$patterns -e '/ $pattern / s/^./X/'"
  120. done
  121. if [ "$patterns" ]; then
  122. eval "__pkgfilter sed $patterns"
  123. fi
  124. bprof pkgenable stop
  125. }
  126. pkgdisable() {
  127. bprof pkgdisable start
  128. local pattern patterns
  129. for pattern; do
  130. patterns="$patterns -e '/ $pattern / s/^./O/'"
  131. done
  132. if [ "$patterns" ]; then
  133. eval "__pkgfilter sed $patterns"
  134. fi
  135. bprof pkgdisable stop
  136. }
  137. pkgremove() {
  138. bprof pkgremove start
  139. local pattern patterns
  140. if [ "$1" ]; then
  141. patterns=" $1 "; shift
  142. for pattern; do
  143. patterns="$patterns| $pattern "
  144. done
  145. __pkgfilter egrep -v "$patterns"
  146. fi
  147. bprof pkgremove stop
  148. }
  149. pkgcheck() {
  150. bprof pkgcheck start
  151. local pattern="$1"; pattern="${pattern//+/\\+}"
  152. egrep -q "^$2.*[ =]($pattern) " $cfgtmpdir/config/packages; local ret=$?
  153. bprof pkgcheck stop
  154. return $ret
  155. }
  156. else
  157. pkgin() { cfghlp pkg_in $cfgtmpdir/config/packages; }
  158. pkgout() { cfghlp pkg_out $cfgtmpdir/config/packages ; }
  159. pkgfilter() {
  160. bprof pkgfilter start
  161. cfghlp pkg_out $cfgtmpdir/packages.tmp
  162. "$@" < $cfgtmpdir/packages.tmp > $cfgtmpdir/config/packages
  163. cfghlp pkg_in $cfgtmpdir/config/packages
  164. bprof pkgfilter stop
  165. }
  166. pkgenable() {
  167. bprof pkgenable start
  168. cfghlp pkgenable "$@"
  169. bprof pkgenable stop
  170. }
  171. pkgdisable() {
  172. bprof pkgdisable start
  173. cfghlp pkgdisable "$@"
  174. bprof pkgdisable stop
  175. }
  176. pkgremove() {
  177. bprof pkgremove start
  178. cfghlp pkgremove "$@"
  179. bprof pkgremove stop
  180. }
  181. pkgcheck() {
  182. bprof pkgcheck start
  183. cfghlp pkgcheck "$1" "$2"; local ret=$?
  184. bprof pkgcheck stop
  185. return $ret
  186. }
  187. fi
  188. # pkgchecklicense -- checks for files with license issues
  189. pkgchecklicense() {
  190. rm -f $cfgtmpdir/license-issue.*
  191. while read a b c repo pkg dummy; do
  192. if grep -E "\[(L|LICENSE)\][ ]*(Commercial|Restricted)" \
  193. package/$repo/$pkg/$pkg.desc &> /dev/null; then
  194. echo $pkg >> $cfgtmpdir/license-issue.ask
  195. fi
  196. done < <(grep "^X" $cfgtmpdir/config/packages)
  197. }
  198. comment() {
  199. bprof comment start
  200. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] && \
  201. [ $menu_current = $menu_this ] ; then
  202. commentnr=$(( $commentnr + 1 ))
  203. echo "COMMENT_$commentnr '$spacer$1'" >> $cfgtmpdir/config.dialog
  204. if [ "$2" != "" ] ; then
  205. set_help "COMMENT_$commentnr" "$2"
  206. fi
  207. fi
  208. bprof comment stop
  209. }
  210. comment_id() {
  211. bprof comment_id start
  212. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  213. [ $menu_current = $menu_this ] ; then
  214. echo "$2 '$spacer$1'" >> $cfgtmpdir/config.dialog
  215. if [ "$3" != "" ] ; then
  216. set_help "$2" "$3"
  217. fi
  218. fi
  219. bprof comment_id stop
  220. }
  221. const() {
  222. bprof const start
  223. local q="'"
  224. local v="${2//$q/$q\\$q$q}"
  225. eval "$1=\"\$2\""
  226. echo "export $1='$v'" >> $cfgtmpdir/config/config
  227. bprof const stop
  228. }
  229. # Usage: set_data NAME DEFAULT
  230. #
  231. set_data() {
  232. bprof set_data start
  233. local q="'" set_name="SDECFGSET_${1#SDECFG_}"
  234. if eval "[ \"\$$set_name\" ]" ; then
  235. eval "data=\"\$$set_name\""
  236. eval "$1=\"\$data\""
  237. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ]
  238. then menumode=2 ; else menumode=0 ; fi
  239. elif [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  240. eval "data=\"\${$1:-$2}\""
  241. eval "$1=\"\$data\""
  242. menumode=1
  243. else
  244. data="$2" ; eval "$1=\"\$data\""
  245. menumode=0
  246. fi
  247. item="$1"
  248. echo "export $1='${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config/config
  249. bprof set_data stop
  250. }
  251. choice() {
  252. bprof choice start
  253. # desired default value
  254. #
  255. local defval="$2"
  256. # reset to default if current value is not in list
  257. # and default to first element if it's not in list
  258. #
  259. eval $(
  260. eval "value=\$$1" ; name=$1 ; dval=$defval; shift ; shift
  261. while [ "$#" != 0 ] ; do
  262. [ "$dval" = "$1" ] && dval=
  263. [ "$value" = "$1" ] && name= ; shift ; shift
  264. done
  265. [ "$dval" ] && echo "unset defval;"
  266. [ "$name" ] && echo "unset $name"
  267. )
  268. set_data "$1" "${defval:-$3}"
  269. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  270. { $ECHO_E -n "$item\tchoice_action '$1' '$data'" ; shift ; shift
  271. for x ; do echo -n " '$x'" ; done ; echo ; } >> $cfgtmpdir/config.data
  272. fi
  273. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  274. if [ "$menumode" -eq 1 ] ; then xdata="($data)"
  275. else xdata="=$data=" ; fi
  276. while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done
  277. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \
  278. "$xdata" >> $cfgtmpdir/config.dialog
  279. fi
  280. bprof choice stop
  281. }
  282. choice_action() {
  283. command="./tmp/confdialog.bin --title 'Build Config' \
  284. --backtitle '$configtitle' \
  285. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  286. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  287. default=$2 ; item=$1 ; shift ; shift
  288. while [ "$1" ] ; do
  289. if [ "$1" = "$default" ]
  290. then command="$command '$1' '${2//_/ }' ON"
  291. else command="$command '$1' '${2//_/ }' OFF" ; fi
  292. shift ; shift
  293. done
  294. eval "$command" 2> $cfgtmpdir/config.out
  295. case "$?" in
  296. 0|6)
  297. eval "$item='`cat $cfgtmpdir/config.out`'"
  298. ;;
  299. 1|255) return 0 ;;
  300. 2) echo "No help." ; sleep 1 ;;
  301. *) echo "unknown returncode: $?" ; exit 1 ;;
  302. esac
  303. }
  304. text() {
  305. bprof text start
  306. local q="'"
  307. set_data "$2" "$3"
  308. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  309. $ECHO_E "$2\ttext_action '$1' '$2'" \
  310. "'${data//$q/$q\\$q$q}'" >> $cfgtmpdir/config.data
  311. fi
  312. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  313. xdata="$( printf "%-${tabspace}s" \
  314. "$(echo $data | cut -c1-20)")"
  315. if [ "$menumode" -eq 1 ] ; then xdata="($xdata)"
  316. else xdata="=$xdata=" ; fi
  317. printf "'$2' '$spacer%s $1'\n" \
  318. "${xdata//$q/$q\\$q$q}" >> $cfgtmpdir/config.dialog
  319. if [ "$4" != "" ] ; then
  320. set_help "$2" "$4"
  321. fi
  322. fi
  323. bprof text stop
  324. }
  325. text_action() {
  326. ./tmp/confdialog.bin --title 'Build Config' \
  327. --backtitle "$configtitle" \
  328. --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> $cfgtmpdir/config.out
  329. [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat $cfgtmpdir/config.out)\""
  330. }
  331. bool() {
  332. bprof bool start
  333. local x
  334. set_data "$2" "$3"
  335. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  336. $ECHO_E "$2\tbool_action '$1' '$2' '$data'" >> $cfgtmpdir/config.data
  337. fi
  338. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  339. if [ "$menumode" -eq 1 ] ; then
  340. if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi
  341. else
  342. if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi
  343. fi
  344. printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \
  345. "$x" >> $cfgtmpdir/config.dialog
  346. if [ "$4" != "" ] ; then
  347. set_help "$2" "$4"
  348. fi
  349. fi
  350. bprof bool stop
  351. }
  352. bool_action() {
  353. if [ $3 -eq 0 ] ; then eval "$2=1"
  354. else eval "$2=0" ; fi
  355. }
  356. editfile() {
  357. bprof editfile start
  358. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  359. local x="$spacer" q="'"
  360. comment ",----< $3 >----."
  361. block_begin 0 ; spacer="${spacer%??}| "
  362. touch "$2"
  363. line_nr=1
  364. while read line ; do
  365. line="${line//$q/$q\\$q$q}"
  366. if [ $menu_current = $menu_this ] ; then
  367. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  368. `printf "%03d:" $line_nr` "$line" >> $cfgtmpdir/config.dialog
  369. $ECHO_E "$1:${editfilenr}\teditfile_action $2" \
  370. "$line_nr '$3'" >> $cfgtmpdir/config.data
  371. fi
  372. editfilenr=$(( $editfilenr + 1 ))
  373. line_nr=$(( $line_nr + 1 ))
  374. done < "$2"
  375. if [ $menu_current = $menu_this ] ; then
  376. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  377. `printf "%03d:" $line_nr` "<add new rule>" >> $cfgtmpdir/config.dialog
  378. $ECHO_E "$1:${editfilenr}\teditfile_action $2" \
  379. "$line_nr '$3'" >> $cfgtmpdir/config.data
  380. fi
  381. editfilenr=$(( $editfilenr + 1 ))
  382. block_end
  383. comment "\`------${3//?/-}------'\''"
  384. spacer="$x"
  385. else
  386. rm -f "$2"
  387. fi
  388. bprof editfile stop
  389. }
  390. editfile_action() {
  391. line="`tail -n +$2 $1 | head -n 1`"
  392. ./tmp/confdialog.bin --title 'Build Config' \
  393. --backtitle "$configtitle" \
  394. --inputbox "$3 - Line $3" \
  395. 9 $(( $columns - 5 )) "$line" 2> $cfgtmpdir/config.out
  396. head -n $(( $2 - 1 )) $1 > $1.new
  397. [ -s $cfgtmpdir/config.out ] && echo "`cat $cfgtmpdir/config.out`" >> $1.new
  398. tail -n +$(( $2 + 1 )) $1 >> $1.new
  399. mv $1.new $1
  400. }
  401. startprog() {
  402. bprof startprog start
  403. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  404. [ $menu_current = $menu_this ] ; then
  405. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  406. "-->" "$2" >> $cfgtmpdir/config.dialog
  407. $ECHO_E "$1\t$3" >> $cfgtmpdir/config.data
  408. fi
  409. bprof startprog stop
  410. }
  411. block_begin() {
  412. bprof block_begin start
  413. if [ $menu_current = $menu_this ] ; then
  414. [ "$tabspace_list" ] && spacer="$spacer "
  415. tabspace_list="$tabspace $tabspace_list"
  416. tabspace="$(( $tabspace + $1 - 2 ))"
  417. fi
  418. bprof block_begin stop
  419. }
  420. block_end() {
  421. bprof block_end start
  422. if [ $menu_current = $menu_this ] ; then
  423. spacer="${spacer%??}"
  424. tabspace="${tabspace_list%% *}"
  425. tabspace_list="${tabspace_list#* }"
  426. fi
  427. bprof block_end stop
  428. }
  429. expert_begin() {
  430. expert=$(( $exprt + 1 ))
  431. }
  432. expert_end() {
  433. expert=$(( $exprt - 1 ))
  434. }
  435. menu_begin() {
  436. bprof menu_begin start
  437. menu_counter=$(( $menu_counter + 1 ))
  438. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  439. [ $menu_current = $menu_this ] ; then
  440. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  441. "===>" "$2" >> $cfgtmpdir/config.dialog
  442. $ECHO_E "$1\tmenu_current=$menu_counter" >> $cfgtmpdir/config.data
  443. fi
  444. if [ $SDECFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  445. [ $menu_current = $menu_counter ] ; then
  446. echo "$1 '===> $2'" >> $cfgtmpdir/config.dialog
  447. $ECHO_E "$1\tmenu_current=$menu_this" >> $cfgtmpdir/config.data
  448. fi
  449. if [ $menu_current = $menu_counter ] ; then
  450. menu_back=$menu_this
  451. menu_backpos=$1
  452. fi
  453. menu_stack="$menu_this $menu_stack"
  454. menu_this=$menu_counter
  455. block_begin 3
  456. bprof menu_begin stop
  457. }
  458. menu_end() {
  459. bprof menu_end start
  460. block_end
  461. menu_this="${menu_stack%% *}"
  462. menu_stack="${menu_stack#* }"
  463. bprof menu_end stop
  464. }
  465. set_help() {
  466. bprof set_help start
  467. ($ECHO_E -n "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  468. tr -d '\n' | sed 's,\\n$,,'; echo ) >> $cfgtmpdir/config.help
  469. bprof set_help stop
  470. }
  471. get_help() {
  472. bprof get_help start
  473. # Create standard help output ...
  474. default_text="
  475. There is no help on '$1' available.
  476. This is the OpenSDE ($sdever) Configuration Tool.
  477. More information can be found on the OpenSDE Homepage:
  478. http://www.opensde.org/
  479. A Bugtracker, Source Browser and Wiki can be found here:
  480. http://trac.opensde.org/
  481. Subscribe to the mailing list by sending an empty e-mail to:
  482. <list-subscribe@opensde.org>
  483. and confirm the subscription request by replying to the mail
  484. our mailing list manager will send you."
  485. # Ok let us find a help for the current item ...
  486. # First of all mask all special chars in the item name
  487. # Comment: this is sick. You can't get any \n this way !!!
  488. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  489. # Now search *.hlp files
  490. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  491. /^$item_name[ ]*\$/c\\
  492. $item_name:\\
  493. /^#/d
  494. /^[^ ]/q
  495. s/^ //
  496. p
  497. }" lib/*/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp 2>/dev/null )
  498. # Get help strings out of the temporary file.
  499. tmp_text=$(grep "^$item_name" $cfgtmpdir/config.help | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  500. # Let us see what we have ...
  501. if [ "$hlp_text" -a "$tmp_text" ] ; then
  502. echo "
  503. There are two help text's... one in one of the config.in files and one
  504. in one of the config.hlp files. Please remove one of them to get rid of
  505. this message here.
  506. Here the one out of config.in:
  507. $tmp_text
  508. Here the one out of config.hlp:
  509. $hlp_text"
  510. elif [ "$hlp_text" ] ; then
  511. echo "$hlp_text"
  512. elif [ "$tmp_text" ] ; then
  513. echo "$tmp_text"
  514. else
  515. echo "$default_text"
  516. fi
  517. bprof get_help stop
  518. }