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.

605 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 config/$config.$swpid/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. "$@" < config/$config.$swpid/packages > config/$config.$swpid/packages.new
  50. mv config/$config.$swpid/packages.new config/$config.$swpid/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. < config/$config.$swpid/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; shift;
  140. done
  141. script="$script} {print;}"
  142. pkgfilter "awk" "--" "$script"
  143. }
  144. else
  145. pkgin() { cfghlp pkg_in config/$config.$swpid/packages; }
  146. pkgout() { cfghlp pkg_out config/$config.$swpid/packages ; }
  147. pkgfilter() {
  148. bprof pkgfilter start
  149. cfghlp pkg_out config/$config.$swpid/packages.tmp
  150. "$@" < config/$config.$swpid/packages.tmp > config/$config.$swpid/packages
  151. cfghlp pkg_in config/$config.$swpid/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. bprof comment start
  183. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  184. then
  185. commentnr=$(( $commentnr + 1 ))
  186. echo "COMMENT_$commentnr '$spacer$1'" >> config.dialog.$menu_this.$swpid
  187. # Hi, esden here, very ill stuff here I save the help
  188. # strings here to a temporary file named config.help.$swpid
  189. # this sed tr sandwitch formats the string so that
  190. # \n are masked and the Help strings are not killed some way
  191. if [ "$2" != "" ] ; then
  192. set_help "COMMENT_$commentnr" "$2"
  193. fi
  194. fi
  195. bprof comment stop
  196. }
  197. comment_id() {
  198. bprof comment_id start
  199. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  200. then
  201. echo "$2 '$spacer$1'" >> config.dialog.$menu_this.$swpid
  202. # If you do not know what mighty esden
  203. # is doing here see comment()
  204. if [ "$3" != "" ] ; then
  205. set_help "$2" "$3"
  206. fi
  207. fi
  208. bprof comment_id stop
  209. }
  210. const() {
  211. bprof const start
  212. local q="'"
  213. local v="${2//$q/$q\\$q$q}"
  214. eval "$1=\"\$2\""
  215. echo "export $1='$v'" >> config/$config.$swpid/config
  216. bprof const stop
  217. }
  218. # Usage: set_data NAME DEFAULT
  219. #
  220. set_data() {
  221. bprof set_data start
  222. local q="'"
  223. set_name="ROCKCFGSET_${1#ROCKCFG_}"
  224. usr_name="ROCKCFGUSR_${1#ROCKCFG_}"
  225. usr_data="${!usr_name}"
  226. menumode=0
  227. data="$2"
  228. if [ "${!set_name}" ]; then
  229. data="${!set_name}"
  230. fi
  231. dfl_data="$data"
  232. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]; then
  233. menumode=2
  234. if [ $nousrconfig -eq 1 ] && [ -n "${!1}" -a "${!1}" != "$data" ] ; then
  235. eval "$usr_name=\"${!1}\""
  236. usr_data="${!1}"
  237. fi
  238. if [ -n "$usr_data" ]; then
  239. data="$usr_data"
  240. obegin="<" oend=">" menumode=1
  241. else
  242. unset $usr_name
  243. fi
  244. fi
  245. eval "$1=\"\$data\""
  246. item="$1"
  247. echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config.$swpid/config
  248. bprof set_data stop
  249. }
  250. choice() {
  251. bprof choice start
  252. local obegin="(" oend=")"
  253. local q="'"
  254. set_data "$1" "$2"
  255. # if data is not in list, leave usr_data unmodified
  256. # but set the current value to the default
  257. local fallback_hack=0
  258. eval $(
  259. shift; shift
  260. while [ "$#" != 0 ] ; do
  261. [ "$data" = "$1" ] && exit
  262. shift; shift
  263. done
  264. echo "fallback_hack=1"
  265. )
  266. if [ "$fallback_hack" = 1 ]; then
  267. obegin="?"; oend="?"; data="$dfl_data"; eval "$1=\"\$data\""
  268. echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config.$swpid/config
  269. fi
  270. if [ "$menumode" -gt 0 ]
  271. then
  272. { echo -en "$item\tchoice_action '$usr_name' '$usr_data'" ; shift ; shift
  273. echo -n " '' 'Reset_this_switch_to_default_value'"
  274. for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data.$menu_this.$swpid
  275. xdata="$obegin$data$oend"
  276. while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done
  277. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" "$xdata" \
  278. >> config.dialog.$menu_this.$swpid
  279. fi
  280. bprof choice stop
  281. }
  282. choice_action() {
  283. command="./src/rockdialog.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 [ "$#" -gt 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> config.out.$swpid
  295. case "$?" in
  296. 0|6)
  297. eval "$item='`cat config.out.$swpid`'"
  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="'" obegin="(" oend=")"
  307. set_data "$2" "$3"
  308. if [ "$menumode" -gt 0 ]
  309. then
  310. echo -e "$2\ttext_action '$1' '$usr_name'" \
  311. "'${data//$q/$q\\$q$q}'" >> config.data.$menu_this.$swpid
  312. xdata="${obegin}$( printf "%-${tabspace}s" \
  313. "$(echo $data | cut -c1-20)")${oend}"
  314. printf "'$2' '$spacer%s $1'\n" \
  315. "${xdata//$q/$q\\$q$q}" >> config.dialog.$menu_this.$swpid
  316. # If you do not know what mighty esden
  317. # is doin here see comment()
  318. if [ "$4" != "" ] ; then
  319. set_help "$2" "$4"
  320. fi
  321. fi
  322. bprof text stop
  323. }
  324. text_action() {
  325. ./src/rockdialog.bin --title 'Build Config' \
  326. --backtitle "$configtitle" \
  327. --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> config.out.$swpid
  328. [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat config.out.$swpid)\""
  329. }
  330. bool() {
  331. bprof bool start
  332. local x obegin="[" oend="]"
  333. set_data "$2" "$3"
  334. if [ "$menumode" -gt 0 ]
  335. then
  336. if [ $data -eq 0 ] ; then x="${obegin} ${oend}" ; else x="${obegin}*${oend}" ; fi
  337. echo -e "$2\tbool_action '$usr_name' '$usr_data' '$3'" >> config.data.$menu_this.$swpid
  338. printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" "$x" >> config.dialog.$menu_this.$swpid
  339. # If you do not know what mighty esden is doin here see comment()
  340. if [ "$4" != "" ] ; then
  341. set_help "$2" "$4"
  342. fi
  343. fi
  344. bprof bool stop
  345. }
  346. bool_action() {
  347. local usrvar=$1
  348. local origval=$3
  349. local usrval
  350. eval "usrval=\${$usrvar}"
  351. case "$usrval" in
  352. "") [ "$origval" == "0" ] && eval "$usrvar=1"
  353. [ "$origval" == "1" ] && eval "$usrvar=0"
  354. ;;
  355. 1) [ "$origval" == "0" ] && eval "$usrvar=0"
  356. [ "$origval" == "1" ] && eval "$usrvar="
  357. ;;
  358. 0) [ "$origval" == "0" ] && eval "$usrvar="
  359. [ "$origval" == "1" ] && eval "$usrvar=1"
  360. ;;
  361. esac
  362. }
  363. editfile() {
  364. bprof editfile start
  365. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  366. local x="$spacer" q="'"
  367. comment ",----< $3 >----."
  368. block_begin 0 ; spacer="${spacer%??}| "
  369. touch "$2"
  370. line_nr=1
  371. while read line ; do
  372. line="${line//$q/$q\\$q$q}"
  373. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  374. `printf "%03d:" $line_nr` "$line" >> config.dialog.$menu_this.$swpid
  375. echo -e "$1:${editfilenr}\teditfile_action $2" \
  376. "$line_nr '$3'" >> config.data.$menu_this.$swpid
  377. editfilenr=$(( $editfilenr + 1 ))
  378. line_nr=$(( $line_nr + 1 ))
  379. done < "$2"
  380. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  381. `printf "%03d:" $line_nr` "<add new rule>" >> config.dialog.$menu_this.$swpid
  382. echo -e "$1:${editfilenr}\teditfile_action $2" \
  383. "$line_nr '$3'" >> config.data.$menu_this.$swpid
  384. editfilenr=$(( $editfilenr + 1 ))
  385. block_end
  386. comment "\`------${3//?/-}------'\''"
  387. spacer="$x"
  388. fi
  389. bprof editfile stop
  390. }
  391. editfile_action() {
  392. line="`tail -n +$2 $1 | head -n 1`"
  393. ./src/rockdialog.bin --title 'Build Config' \
  394. --backtitle "$configtitle" \
  395. --inputbox "$3 - Line $3" \
  396. 9 $(( $columns - 5 )) "$line" 2> config.out.$swpid
  397. head -n $(( $2 - 1 )) $1 > $1.new
  398. [ -s config.out.$swpid ] && echo "`cat config.out.$swpid`" >> $1.new
  399. tail -n +$(( $2 + 1 )) $1 >> $1.new
  400. mv $1.new $1
  401. }
  402. startprog() {
  403. bprof startprog start
  404. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  405. then
  406. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  407. "-->" "$2" >> config.dialog.$menu_this.$swpid
  408. echo -e "$1\t$3" >> config.data.$menu_this.$swpid
  409. fi
  410. bprof startprog stop
  411. }
  412. block_begin() {
  413. bprof block_begin start
  414. [ "$tabspace_list" ] && spacer="$spacer "
  415. tabspace_list="$tabspace $tabspace_list"
  416. tabspace="$(( $tabspace + $1 - 2 ))"
  417. bprof block_begin stop
  418. }
  419. block_end() {
  420. bprof block_end start
  421. spacer="${spacer%??}"
  422. tabspace="${tabspace_list%% *}"
  423. tabspace_list="${tabspace_list#* }"
  424. bprof block_end stop
  425. }
  426. expert_begin() {
  427. expert=$(( $expert + 1 ))
  428. }
  429. expert_end() {
  430. expert=$(( $expert - 1 ))
  431. }
  432. menu_begin() {
  433. bprof menu_begin start
  434. menu_counter=$(( $menu_counter + 1 ))
  435. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  436. then
  437. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  438. "===>" "$2" >> config.dialog.$menu_this.$swpid
  439. echo -e "$1\tmenu_current=$menu_counter" >> config.data.$menu_this.$swpid
  440. echo "$1 '===> $2'" >> config.dialog.$menu_counter.$swpid
  441. echo -e "$1\tmenu_current=$menu_this current=$1" >> config.data.$menu_counter.$swpid
  442. echo -e "MENU_BACK\tmenu_current=$menu_this current=$1" >> config.data.$menu_counter.$swpid
  443. fi
  444. menu_stack="$menu_this $menu_stack"
  445. menu_this=$menu_counter
  446. block_begin 3
  447. bprof menu_begin stop
  448. }
  449. menu_end() {
  450. bprof menu_end start
  451. block_end
  452. menu_this="${menu_stack%% *}"
  453. menu_stack="${menu_stack#* }"
  454. bprof menu_end stop
  455. }
  456. set_help() {
  457. bprof set_help start
  458. (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  459. tr -d '\n' | sed 's,\\n$,,'; echo ) >> config.help.$swpid
  460. bprof set_help stop
  461. }
  462. get_help() {
  463. bprof get_help start
  464. cat << EOT
  465. This is the ROCK Linux $rockver Configuration Tool.
  466. Config option types:
  467. [*] [ ] Unmodified bool value (set and unset)
  468. <*> < > User-modified bool value (set and unset)
  469. (foobar) Unmodified selection or text field
  470. <foobar> User-modified selection or text field
  471. Note that e.g. bool value are in fact tristate options:
  472. user set, user unset and and the unmodified default value
  473. This is because one option might change the default value
  474. of another option. You might need a while to get used to
  475. the concept, but in the end it really makes sense.
  476. -----
  477. EOT
  478. # Create standard help output ...
  479. default_text="
  480. There is no help on '$1' available.
  481. Please read the build Documentation (Documentation/BUILD)
  482. before building ROCK Linux.
  483. More information can be found on the ROCK Linux Homepage:
  484. http://www.rocklinux.org/
  485. Information about the ROCK Linux mailing lists and the mailing
  486. list archive can be found at:
  487. http://www.rocklinux.org/mail.html and
  488. http://www.rocklinux.net/lurker/splash"
  489. # Ok let us find a help for the current item ...
  490. # First of all mask all special chars in the item name
  491. # Comment: this is sick. You can't get any \n this way !!!
  492. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  493. # Now search *.hlp files
  494. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  495. /^$item_name[ ]*\$/c\\
  496. $item_name:\\
  497. /^#/d
  498. /^[^ ]/q
  499. s/^ //
  500. p
  501. }" scripts/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp misc/*/config*.hlp misc/*/*/config*.hlp 2>/dev/null )
  502. # Get help strings out of the temporary file.
  503. tmp_text=$(grep "^$item_name" config.help.$swpid | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  504. # Let us see what we have ...
  505. if [ "$hlp_text" -a "$tmp_text" ] ; then
  506. echo "
  507. There are two help text's... one in one of the config.in files and one
  508. in one of the config.hlp files. Please remove one of them to get rid of
  509. this message here.
  510. Here the one out of config.in:
  511. $tmp_text
  512. Here the one out of config.hlp:
  513. $hlp_text"
  514. elif [ "$hlp_text" ] ; then
  515. echo "$hlp_text"
  516. elif [ "$tmp_text" ] ; then
  517. echo "$tmp_text"
  518. else
  519. echo "$default_text"
  520. fi
  521. bprof get_help stop
  522. }