mirror of the now-defunct rocklinux.org
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.

598 lines
14 KiB

  1. #!/bin/bash
  2. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  3. #
  4. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. # Please add additional copyright information _after_ the line containing
  6. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  7. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  8. #
  9. # ROCK Linux: rock-src/scripts/config.func
  10. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version. A copy of the GNU General Public
  16. # License can be found at Documentation/COPYING.
  17. #
  18. # Many people helped and are helping developing ROCK Linux. Please
  19. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  20. # file for details.
  21. #
  22. # --- ROCK-COPYRIGHT-NOTE-END ---
  23. # This function appends or inserts values to a variable:
  24. #
  25. # var_append PATH ":" "$HOME/bin"
  26. # var_insert PATH ":" "$HOME/bin"
  27. #
  28. var_append() {
  29. eval "[ \"\$$1\" ] && $1=\"\${$1}$2\""
  30. eval "$1=\"\${$1}$3\""
  31. }
  32. var_insert() {
  33. eval "[ \"\$$1\" ] && $1=\"$2\$$1\""
  34. eval "$1=\"$3\$$1\""
  35. }
  36. # Functions for working with $swpdir/packages
  37. #
  38. # pkgenable package-list
  39. # pkgdisable package-list
  40. # pkgremove package-list
  41. # pkgcheck pattern X|O|.
  42. # pkgfilter cmd arg1 ...
  43. #
  44. if [ -n "$nobashmod" ]
  45. then
  46. pkgin() { :; }
  47. pkgout() { :; }
  48. __pkgfilter() {
  49. "$@" < $swpdir/packages > $swpdir/packages.new
  50. mv $swpdir/packages.new $swpdir/packages
  51. }
  52. pkgfilter() {
  53. bprof pkgfilter start
  54. __pkgfilter "$@"
  55. bprof pkgfilter stop
  56. }
  57. pkgenable() {
  58. bprof pkgenable start
  59. local pattern patterns
  60. for pattern; do
  61. patterns="$patterns /[ =]$pattern / s,^O,X, ;"
  62. done
  63. if [ "$patterns" ]; then
  64. __pkgfilter sed -e "$patterns"
  65. fi
  66. bprof pkgenable stop
  67. }
  68. pkgdisable() {
  69. bprof pkgdisable start
  70. local pattern patterns
  71. for pattern; do
  72. patterns="$patterns /[ =]$pattern / s,^X,O, ;"
  73. done
  74. if [ "$patterns" ]; then
  75. __pkgfilter sed -e "$patterns"
  76. fi
  77. bprof pkgdisable stop
  78. }
  79. pkgremove() {
  80. bprof pkgremove start
  81. local pattern patterns
  82. if [ "$1" ]; then
  83. patterns="/ $1 / d ;"; shift
  84. for pattern; do
  85. patterns="$patterns / $pattern / d ;"
  86. done
  87. __pkgfilter sed -e "$patterns"
  88. fi
  89. bprof pkgremove stop
  90. }
  91. pkgcheck() {
  92. bprof pkgcheck start
  93. local pattern="$1" stat="$2"
  94. sed -n -e "/^$stat.*[ =]${pattern} / q0 ; $ q1 ;" \
  95. < $swpdir/packages
  96. local ret=$?
  97. bprof pkgcheck stop
  98. return $ret
  99. }
  100. #
  101. # pkgfork <origpkg> <newpkg> <name1> <value1> <name2> <value2> ..
  102. #
  103. # Names:
  104. # status X / O
  105. # stages 012--5---9
  106. # priority 115.000
  107. # version 0.9.26
  108. # prefix /opt/foobar
  109. # flag CORE
  110. # unflag CORE
  111. #
  112. pkgfork() {
  113. local script="\$5==\"$1\" {print;\$5=\"$1=$2\";"
  114. shift; shift;
  115. while [ -n "$1" ]; do
  116. case "$1" in
  117. status)
  118. script="$script \$1=\"$2\";"
  119. ;;
  120. stages)
  121. script="$script \$2=\"$2\";"
  122. ;;
  123. priority)
  124. script="$script \$3=\"$2\";"
  125. ;;
  126. version)
  127. script="$script \$6=\"$2\";"
  128. ;;
  129. prefix)
  130. script="$script \$7=\"$2\";"
  131. ;;
  132. flag)
  133. script="$script sub(\" 0\$\", \" $2 0\");"
  134. ;;
  135. unflag)
  136. script="$script sub(\" $2 \", \" \");"
  137. ;;
  138. esac
  139. shift 2
  140. done
  141. script="$script} {print;}"
  142. pkgfilter "awk" "--" "$script"
  143. }
  144. else
  145. pkgin() { cfghlp pkg_in $swpdir/packages; }
  146. pkgout() { cfghlp pkg_out $swpdir/packages ; }
  147. pkgfilter() {
  148. bprof pkgfilter start
  149. cfghlp pkg_out $swpdir/packages.tmp
  150. "$@" < $swpdir/packages.tmp > $swpdir/packages
  151. cfghlp pkg_in $swpdir/packages
  152. bprof pkgfilter stop
  153. }
  154. pkgenable() {
  155. bprof pkgenable start
  156. cfghlp pkgenable "$@"
  157. bprof pkgenable stop
  158. }
  159. pkgdisable() {
  160. bprof pkgdisable start
  161. cfghlp pkgdisable "$@"
  162. bprof pkgdisable stop
  163. }
  164. pkgremove() {
  165. bprof pkgremove start
  166. cfghlp pkgremove "$@"
  167. bprof pkgremove stop
  168. }
  169. pkgcheck() {
  170. bprof pkgcheck start
  171. cfghlp pkgcheck "$1" "$2"; local ret=$?
  172. bprof pkgcheck stop
  173. return $ret
  174. }
  175. pkgfork() {
  176. bprof pkgfork start
  177. cfghlp pkgfork "$@"
  178. bprof pkgfork stop
  179. }
  180. fi
  181. comment() {
  182. local text="$1" help="$2"
  183. bprof comment start
  184. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ]
  185. then
  186. commentnr=$(( $commentnr + 1 ))
  187. echo "COMMENT_$commentnr '$spacer$text'" >> $swpdir/config.dialog.$menu_this
  188. set_help "COMMENT_$commentnr" "$help"
  189. fi
  190. bprof comment stop
  191. }
  192. comment_id() {
  193. local text="$1" id="$2" help="$3"
  194. bprof comment_id start
  195. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  196. then
  197. echo "$id '$spacer$text'" >> $swpdir/config.dialog.$menu_this
  198. set_help "$id" "$help"
  199. fi
  200. bprof comment_id stop
  201. }
  202. const() {
  203. bprof const start
  204. eval "$1=\"\$2\""
  205. bprof const stop
  206. }
  207. # Usage: set_data NAME DEFAULT
  208. #
  209. set_data() {
  210. local name="$1" q="'"
  211. data="$2"
  212. bprof set_data start
  213. set_name="ROCKCFGSET_${name#ROCKCFG_}"
  214. usr_name="ROCKCFGUSR_${name#ROCKCFG_}"
  215. usr_data="${!usr_name}"
  216. if [ "${!set_name}" ]; then
  217. data="${!set_name}"
  218. fi
  219. dfl_data="$data"
  220. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]; then
  221. if [ -n "$usr_data" ]; then
  222. data="$usr_data"
  223. obegin="<" oend=">"
  224. else
  225. unset $usr_name
  226. fi
  227. fi
  228. eval "$name=\"\$data\""
  229. item="$name"
  230. bprof set_data stop
  231. }
  232. choice() {
  233. bprof choice start
  234. local obegin="(" oend=")"
  235. local q="'"
  236. local name="$1" default="$2"
  237. set_data "$name" "$default"
  238. # if data is not in list, leave usr_data unmodified
  239. # but set the current value to the default
  240. local fallback_hack=0
  241. eval $(
  242. shift 2
  243. while [ "$#" != 0 ] ; do
  244. [ "$1" = "$default" ] && exit
  245. shift 2
  246. done
  247. echo "fallback_hack=1"
  248. )
  249. if [ "$fallback_hack" = 1 ]; then
  250. obegin="?"; oend="?"; data="$dfl_data"; eval "$name=\"\$data\""
  251. fi
  252. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  253. then
  254. { echo -en "$item\tchoice_action '$usr_name' '$usr_data'"
  255. echo -n " '' 'Reset_this_switch_to_default_value'"
  256. shift 2 ; printf " '%s'" "$@" ; echo
  257. } >> $swpdir/config.data.$menu_this
  258. xdata="$obegin$data$oend"
  259. while [ "$1" -a "$1" != "$data" ] ; do shift 2 ; done
  260. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" "$xdata" \
  261. >> $swpdir/config.dialog.$menu_this
  262. fi
  263. bprof choice stop
  264. }
  265. choice_action() {
  266. item="$1" ; default="$2" ; shift 2
  267. command="./src/rockdialog.bin --title 'Build Config' \
  268. --backtitle '$configtitle' \
  269. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  270. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  271. while [ "$#" -gt 1 ] ; do
  272. command="$command '$1' '${2//_/ }'"
  273. if [ "$1" = "$default" ]
  274. then command="$command ON"
  275. else command="$command OFF" ; fi
  276. shift 2
  277. done
  278. eval "$command" 2> $swpdir/config.out
  279. case "$?" in
  280. 0|6)
  281. eval "$item='`cat $swpdir/config.out`'"
  282. set_data "${item/ROCKCFGUSR/ROCKCFG}" "$default"
  283. ;;
  284. 1|255) return 0 ;;
  285. 2) echo "No help." ; sleep 1 ;;
  286. *) echo "unknown returncode: $?" ; exit 1 ;;
  287. esac
  288. }
  289. text() {
  290. local name="$1" id="$2" default="$3" help="$4"
  291. bprof text start
  292. local q="'" obegin="(" oend=")"
  293. set_data "$id" "$default"
  294. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  295. then
  296. echo -e "$id\ttext_action '$name' '$usr_name'" \
  297. "'${data//$q/$q\\$q$q}'" >> $swpdir/config.data.$menu_this
  298. xdata="${obegin}$( printf "%-${tabspace}s" \
  299. "$(echo $data | cut -c1-20)")${oend}"
  300. printf "'$id' '$spacer%s $name'\n" \
  301. "${xdata//$q/$q\\$q$q}" >> $swpdir/config.dialog.$menu_this
  302. set_help "$id" "$help"
  303. fi
  304. bprof text stop
  305. }
  306. text_action() {
  307. local label="$1" usrvar="$2" data="$3"
  308. ./src/rockdialog.bin --title 'Build Config' \
  309. --backtitle "$configtitle" \
  310. --inputbox "$label" 9 $(( $columns - 5 )) "$data" 2> $swpdir/config.out
  311. if [ "$?" -eq 0 -o "$?" -eq 1 ] ; then
  312. eval "$usrvar=\"\$(cat $swpdir/config.out)\""
  313. set_data "${usrvar/ROCKCFGUSR/ROCKCFG}" "$data"
  314. fi
  315. }
  316. bool() {
  317. local name="$1" id="$2" default="$3" help="$4"
  318. local x obegin="[" oend="]"
  319. bprof bool start
  320. set_data "$id" "$default"
  321. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  322. then
  323. if [ $data -eq 0 ] ; then
  324. x="${obegin} ${oend}"
  325. else
  326. x="${obegin}*${oend}"
  327. fi
  328. echo -e "$id\tbool_action '$usr_name' '$usr_data' '$default'" \
  329. >> $swpdir/config.data.$menu_this
  330. printf "$id '$spacer%-${tabspace}s ${name//_/ }'\n" "$x" \
  331. >> $swpdir/config.dialog.$menu_this
  332. set_help "$id" "$help"
  333. fi
  334. bprof bool stop
  335. }
  336. bool_action() {
  337. local usrvar=$1 origval=$3
  338. case "${!usrvar}" in
  339. "") [ "$origval" == "0" ] && eval "$usrvar=1"
  340. [ "$origval" == "1" ] && eval "$usrvar=0"
  341. ;;
  342. 1) [ "$origval" == "0" ] && eval "$usrvar=0"
  343. [ "$origval" == "1" ] && eval "$usrvar="
  344. ;;
  345. 0) [ "$origval" == "0" ] && eval "$usrvar="
  346. [ "$origval" == "1" ] && eval "$usrvar=1"
  347. ;;
  348. esac
  349. set_data "${usrvar/ROCKCFGUSR/ROCKCFG}" "$3"
  350. }
  351. editfile() {
  352. local id="$1" file="$2" label="$3"
  353. bprof editfile start
  354. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ] ; then
  355. local x="$spacer" q="'"
  356. comment ",----< $label >----."
  357. block_begin 0 ; spacer="${spacer%??}| "
  358. touch "$file"
  359. line_nr=1
  360. while read line ; do
  361. line="${line//$q/$q\\$q$q}"
  362. printf "$id:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  363. `printf "%03d:" $line_nr` "$line" >> $swpdir/config.dialog.$menu_this
  364. echo -e "$id:${editfilenr}\teditfile_action $file" \
  365. "$line_nr '$label'" >> $swpdir/config.data.$menu_this
  366. editfilenr=$(( $editfilenr + 1 ))
  367. line_nr=$(( $line_nr + 1 ))
  368. done < "$file"
  369. printf "$id:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  370. `printf "%03d:" $line_nr` "<add new rule>" >> $swpdir/config.dialog.$menu_this
  371. echo -e "$id:${editfilenr}\teditfile_action $file" \
  372. "$line_nr '$label'" >> $swpdir/config.data.$menu_this
  373. editfilenr=$(( $editfilenr + 1 ))
  374. block_end
  375. comment "\`------${label//?/-}------'\''"
  376. spacer="$x"
  377. fi
  378. bprof editfile stop
  379. }
  380. editfile_action() {
  381. local filename="$1"
  382. cp -a "$filename"{,.orig}
  383. ${EDITOR:-vim} "$filename" && rm -f "$filename.orig" \
  384. || mv "$filename"{.orig,}
  385. }
  386. startprog() {
  387. local id="$1" label="$2" prog="$3"
  388. bprof startprog start
  389. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ]
  390. then
  391. printf "$id '$spacer%-${tabspace}s %s'\n" \
  392. "-->" "$label" >> $swpdir/config.dialog.$menu_this
  393. echo -e "$id\t$prog" >> $swpdir/config.data.$menu_this
  394. fi
  395. bprof startprog stop
  396. }
  397. block_begin() {
  398. bprof block_begin start
  399. [ "$tabspace_list" ] && spacer="$spacer "
  400. tabspace_list="$tabspace $tabspace_list"
  401. tabspace="$(( $tabspace + $1 - 2 ))"
  402. bprof block_begin stop
  403. }
  404. block_end() {
  405. bprof block_end start
  406. spacer="${spacer%??}"
  407. tabspace="${tabspace_list%% *}"
  408. tabspace_list="${tabspace_list#* }"
  409. bprof block_end stop
  410. }
  411. # has to be called at the beginning of each config cycle
  412. config_cycle() {
  413. expert=0;
  414. menu_counter=0;
  415. }
  416. expert_begin() {
  417. expert=$(( $expert + 1 ))
  418. }
  419. expert_end() {
  420. expert=$(( $expert - 1 ))
  421. }
  422. menu_begin() {
  423. local id="$1" name="$2"
  424. bprof menu_begin start
  425. menu_counter=$(( $menu_counter + 1 ))
  426. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ]
  427. then
  428. printf "$id '$spacer%-${tabspace}s %s'\n" \
  429. "===>" "$name" >> $swpdir/config.dialog.$menu_this
  430. echo -e "$id\tmenu_current=$menu_counter" \
  431. >> $swpdir/config.data.$menu_this
  432. echo "$id '===> $name'" >> $swpdir/config.dialog.$menu_counter
  433. echo -e "$id\tmenu_current=$menu_this current=$id" \
  434. >> $swpdir/config.data.$menu_counter
  435. echo -e "MENU_BACK\tmenu_current=$menu_this current=$id" \
  436. >> $swpdir/config.data.$menu_counter
  437. fi
  438. menu_stack="$menu_this $menu_stack"
  439. menu_this=$menu_counter
  440. block_begin 3
  441. bprof menu_begin stop
  442. }
  443. menu_end() {
  444. bprof menu_end start
  445. block_end
  446. menu_this="${menu_stack%% *}"
  447. menu_stack="${menu_stack#* }"
  448. bprof menu_end stop
  449. }
  450. set_help() {
  451. local id="$1" help="$2"
  452. bprof set_help start
  453. if [ "$help" != "" ] ; then
  454. echo -e "$id $help\n\n" >> $swpdir/config.help
  455. fi
  456. bprof set_help stop
  457. }
  458. get_help() {
  459. local item_name="$1" tmp_text hlp_text default_text
  460. bprof get_help start
  461. cat << EOT
  462. This is the ROCK Linux $rockver Configuration Tool.
  463. Config option types:
  464. [*] [ ] Unmodified bool value (set and unset)
  465. <*> < > User-modified bool value (set and unset)
  466. (foobar) Unmodified selection or text field
  467. <foobar> User-modified selection or text field
  468. Note that e.g. bool value are in fact tristate options:
  469. user set, user unset and and the unmodified default value
  470. This is because one option might change the default value
  471. of another option. You might need a while to get used to
  472. the concept, but in the end it really makes sense.
  473. -----
  474. EOT
  475. # Create standard help output ...
  476. default_text="
  477. There is no help on '$item_name' available.
  478. Please read the build Documentation (Documentation/BUILD)
  479. before building ROCK Linux.
  480. More information can be found on the ROCK Linux Homepage:
  481. http://www.rocklinux.org/
  482. Information about the ROCK Linux mailing lists and the mailing
  483. list archive can be found at:
  484. http://www.rocklinux.org/wiki/Mailing_Lists and
  485. http://www.rocklinux.net/lurker/splash"
  486. # Ok let us find a help for the current item ...
  487. hlp_text="$( sed -e "/^$item_name\$/,/^\$/ p ; d" \
  488. misc/*/{,*/}config*.hlp package/*/*/{sub,}config-*.hlp \
  489. {scripts,target/*}/config*.hlp 2>/dev/null )"
  490. # Get help strings out of the temporary file.
  491. tmp_text="$( sed -e "/^[ ]*$item_name\([ ]\|\$\)/,/^\$/ p ; d" \
  492. $swpdir/config.help 2>/dev/null )"
  493. # Let us see what we have ...
  494. if [ "$hlp_text" -a "$tmp_text" ] ; then
  495. echo "
  496. There are two help text's... one in one of the config.in files and one
  497. in one of the config.hlp files. Please remove one of them to get rid of
  498. this message here.
  499. Here the one out of config.in:
  500. $tmp_text
  501. Here the one out of config.hlp:
  502. $hlp_text"
  503. elif [ "$hlp_text" ] ; then
  504. echo "config.hlp: $hlp_text"
  505. elif [ "$tmp_text" ] ; then
  506. echo "config.in: $tmp_text"
  507. else
  508. echo "$default_text"
  509. fi
  510. bprof get_help stop
  511. }