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.

618 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 pkg=$1 xpkg=$2 script ; shift 2
  114. parse_desc package/*/$pkg/$pkg.desc P V
  115. extraver=$( echo $desc_V 0 | cut -f2 -d" " )
  116. script="\$5==\"$pkg\" {print; \$1=\"${desc_P%% *}\"; \
  117. \$2=\"$( echo $desc_P | cut -f2 -d" ")\"; \
  118. \$3=\"${desc_P##* }\"; \$5=\"$pkg=$xpkg\"; \
  119. \$6=\"${desc_V%% *}\"; \$7=\"$extraver\";"
  120. while [ -n "$1" ]; do
  121. case "$1" in
  122. status)
  123. script="$script \$1=\"$2\";"
  124. ;;
  125. stages)
  126. script="$script \$2=\"$2\";"
  127. ;;
  128. priority)
  129. script="$script \$3=\"$2\";"
  130. ;;
  131. version)
  132. script="$script \$6=\"$2\";"
  133. ;;
  134. extraversion)
  135. script="$script \$7=\"$2\";"
  136. ;;
  137. flag)
  138. script="$script sub(\" 0\$\", \" $2 0\");"
  139. ;;
  140. unflag)
  141. script="$script sub(\" $2 \", \" \");"
  142. ;;
  143. esac
  144. shift 2
  145. done
  146. script="$script} {print;}"
  147. pkgfilter "awk" "--" "$script"
  148. }
  149. else
  150. pkgin() { cfghlp pkg_in $swpdir/packages; }
  151. pkgout() { cfghlp pkg_out $swpdir/packages ; }
  152. pkgfilter() {
  153. bprof pkgfilter start
  154. cfghlp pkg_out $swpdir/packages.tmp
  155. "$@" < $swpdir/packages.tmp > $swpdir/packages
  156. cfghlp pkg_in $swpdir/packages
  157. bprof pkgfilter stop
  158. }
  159. pkgenable() {
  160. bprof pkgenable start
  161. cfghlp pkgenable "$@"
  162. bprof pkgenable stop
  163. }
  164. pkgdisable() {
  165. bprof pkgdisable start
  166. cfghlp pkgdisable "$@"
  167. bprof pkgdisable stop
  168. }
  169. pkgremove() {
  170. bprof pkgremove start
  171. cfghlp pkgremove "$@"
  172. bprof pkgremove stop
  173. }
  174. pkgcheck() {
  175. bprof pkgcheck start
  176. cfghlp pkgcheck "$1" "$2"; local ret=$?
  177. bprof pkgcheck stop
  178. return $ret
  179. }
  180. pkgfork() {
  181. local pkg=$1 xpkg=$2 extraver ; shift 2
  182. bprof pkgfork start
  183. # >50% of the Config time is spent in this line!
  184. parse_desc package/*/$pkg/$pkg.desc P V
  185. extraver=$( echo $desc_V 0 | cut -f2 -d" " )
  186. cfghlp pkgfork $pkg $xpkg status ${desc_P%% *} priority ${desc_P##* } \
  187. stages $( echo $desc_P | cut -f2 -d" ") \
  188. version ${desc_V%% *} extraversion $extraver $@
  189. bprof pkgfork stop
  190. }
  191. fi
  192. comment() {
  193. local text="$1" help="$2"
  194. bprof comment start
  195. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ]
  196. then
  197. commentnr=$(( $commentnr + 1 ))
  198. echo "COMMENT_$commentnr '$spacer$text'" >> $swpdir/config.dialog.$menu_this
  199. set_help "COMMENT_$commentnr" "$help"
  200. fi
  201. bprof comment stop
  202. }
  203. comment_id() {
  204. local text="$1" id="$2" help="$3"
  205. bprof comment_id start
  206. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  207. then
  208. echo "$id '$spacer$text'" >> $swpdir/config.dialog.$menu_this
  209. set_help "$id" "$help"
  210. fi
  211. bprof comment_id stop
  212. }
  213. const() {
  214. bprof const start
  215. eval "$1=\"\$2\""
  216. bprof const stop
  217. }
  218. # Usage: set_data NAME DEFAULT
  219. #
  220. set_data() {
  221. local name="$1" q="'"
  222. data="$2"
  223. bprof set_data start
  224. set_name="ROCKCFGSET_${name#ROCKCFG_}"
  225. usr_name="ROCKCFGUSR_${name#ROCKCFG_}"
  226. usr_data="${!usr_name}"
  227. if [ "${!set_name}" ]; then
  228. data="${!set_name}"
  229. fi
  230. dfl_data="$data"
  231. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]; then
  232. if [ -n "$usr_data" ]; then
  233. data="$usr_data"
  234. obegin="<" oend=">"
  235. else
  236. unset $usr_name
  237. fi
  238. fi
  239. eval "$name=\"\$data\""
  240. item="$name"
  241. bprof set_data stop
  242. }
  243. choice() {
  244. bprof choice start
  245. local obegin="(" oend=")"
  246. local q="'"
  247. local name="$1" default="$2"
  248. set_data "$name" "$default"
  249. # if data is not in list, leave usr_data unmodified
  250. # but set the current value to the default
  251. local fallback_hack=0
  252. eval $(
  253. shift 2
  254. while [ "$#" != 0 ] ; do
  255. [ "$1" = "$default" ] && exit
  256. shift 2
  257. done
  258. echo "fallback_hack=1"
  259. )
  260. if [ "$fallback_hack" = 1 ]; then
  261. obegin="?"; oend="?"; data="$dfl_data"; eval "$name=\"\$data\""
  262. fi
  263. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  264. then
  265. { echo -en "$item\tchoice_action '$usr_name' '$usr_data'"
  266. echo -n " '' 'Reset_this_switch_to_default_value'"
  267. shift 2 ; printf " '%s'" "$@" ; echo
  268. } >> $swpdir/config.data.$menu_this
  269. xdata="$obegin$data$oend"
  270. while [ "$1" -a "$1" != "$data" ] ; do shift 2 ; done
  271. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" "$xdata" \
  272. >> $swpdir/config.dialog.$menu_this
  273. fi
  274. bprof choice stop
  275. }
  276. choice_action() {
  277. item="$1" ; default="$2" ; shift 2
  278. command="./src/rockdialog.bin --title 'Build Config' \
  279. --backtitle '$configtitle' \
  280. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  281. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  282. while [ "$#" -gt 1 ] ; do
  283. command="$command '$1' '${2//_/ }'"
  284. if [ "$1" = "$default" ]
  285. then command="$command ON"
  286. else command="$command OFF" ; fi
  287. shift 2
  288. done
  289. eval "$command" 2> $swpdir/config.out
  290. case "$?" in
  291. 0|6)
  292. eval "$item='`cat $swpdir/config.out`'"
  293. set_data "${item/ROCKCFGUSR/ROCKCFG}" "$default"
  294. ;;
  295. 1|255) return 0 ;;
  296. 2) echo "No help." ; sleep 1 ;;
  297. *) echo "unknown returncode: $?" ; exit 1 ;;
  298. esac
  299. }
  300. text() {
  301. local name="$1" id="$2" default="$3" help="$4"
  302. bprof text start
  303. local q="'" obegin="(" oend=")"
  304. set_data "$id" "$default"
  305. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  306. then
  307. echo -e "$id\ttext_action '$name' '$usr_name'" \
  308. "'${data//$q/$q\\$q$q}'" >> $swpdir/config.data.$menu_this
  309. xdata="${obegin}$( printf "%-${tabspace}s" \
  310. "$(echo $data | cut -c1-20)")${oend}"
  311. printf "'$id' '$spacer%s $name'\n" \
  312. "${xdata//$q/$q\\$q$q}" >> $swpdir/config.dialog.$menu_this
  313. set_help "$id" "$help"
  314. fi
  315. bprof text stop
  316. }
  317. text_action() {
  318. local label="$1" usrvar="$2" data="$3"
  319. ./src/rockdialog.bin --title 'Build Config' \
  320. --backtitle "$configtitle" \
  321. --inputbox "$label" 9 $(( $columns - 5 )) "$data" 2> $swpdir/config.out
  322. if [ "$?" -eq 0 -o "$?" -eq 1 ] ; then
  323. eval "$usrvar=\"\$(cat $swpdir/config.out)\""
  324. set_data "${usrvar/ROCKCFGUSR/ROCKCFG}" "$data"
  325. fi
  326. }
  327. bool() {
  328. local name="$1" id="$2" default="$3" help="$4"
  329. local x obegin="[" oend="]"
  330. bprof bool start
  331. set_data "$id" "$default"
  332. if [ "$ROCKCFG_EXPERT" -eq 1 -o "$expert" -eq 0 ]
  333. then
  334. if [ $data -eq 0 ] ; then
  335. x="${obegin} ${oend}"
  336. else
  337. x="${obegin}*${oend}"
  338. fi
  339. echo -e "$id\tbool_action '$usr_name' '$usr_data' '$default'" \
  340. >> $swpdir/config.data.$menu_this
  341. printf "$id '$spacer%-${tabspace}s ${name//_/ }'\n" "$x" \
  342. >> $swpdir/config.dialog.$menu_this
  343. set_help "$id" "$help"
  344. fi
  345. bprof bool stop
  346. }
  347. bool_action() {
  348. local usrvar=$1 origval=$3
  349. case "${!usrvar}" in
  350. "") [ "$origval" == "0" ] && eval "$usrvar=1"
  351. [ "$origval" == "1" ] && eval "$usrvar=0"
  352. ;;
  353. 1) [ "$origval" == "0" ] && eval "$usrvar=0"
  354. [ "$origval" == "1" ] && eval "$usrvar="
  355. ;;
  356. 0) [ "$origval" == "0" ] && eval "$usrvar="
  357. [ "$origval" == "1" ] && eval "$usrvar=1"
  358. ;;
  359. esac
  360. set_data "${usrvar/ROCKCFGUSR/ROCKCFG}" "$3"
  361. }
  362. editfile() {
  363. local id="$1" file="$2" label="$3"
  364. bprof editfile start
  365. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ] ; then
  366. local x="$spacer" q="'"
  367. comment ",----< $label >----."
  368. block_begin 0 ; spacer="${spacer%??}| "
  369. touch "$file"
  370. line_nr=1
  371. while read line ; do
  372. line="${line//$q/$q\\$q$q}"
  373. printf "$id:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  374. `printf "%03d:" $line_nr` "$line" >> $swpdir/config.dialog.$menu_this
  375. echo -e "$id:${editfilenr}\teditfile_action $file" \
  376. "$line_nr '$label'" >> $swpdir/config.data.$menu_this
  377. editfilenr=$(( $editfilenr + 1 ))
  378. line_nr=$(( $line_nr + 1 ))
  379. done < "$file"
  380. printf "$id:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  381. `printf "%03d:" $line_nr` "<add new rule>" >> $swpdir/config.dialog.$menu_this
  382. echo -e "$id:${editfilenr}\teditfile_action $file" \
  383. "$line_nr '$label'" >> $swpdir/config.data.$menu_this
  384. editfilenr=$(( $editfilenr + 1 ))
  385. block_end
  386. comment "\`------${label//?/-}------'\''"
  387. spacer="$x"
  388. fi
  389. bprof editfile stop
  390. }
  391. editfile_action() {
  392. local filename="$1"
  393. cp -a "$filename"{,.orig}
  394. ${EDITOR:-vim} "$filename" && rm -f "$filename.orig" \
  395. || mv "$filename"{.orig,}
  396. }
  397. startprog() {
  398. local id="$1" label="$2" prog="$3"
  399. bprof startprog start
  400. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ]
  401. then
  402. printf "$id '$spacer%-${tabspace}s %s'\n" \
  403. "-->" "$label" >> $swpdir/config.dialog.$menu_this
  404. echo -e "$id\t$prog" >> $swpdir/config.data.$menu_this
  405. fi
  406. bprof startprog stop
  407. }
  408. block_begin() {
  409. bprof block_begin start
  410. [ "$tabspace_list" ] && spacer="$spacer "
  411. tabspace_list="$tabspace $tabspace_list"
  412. tabspace="$(( $tabspace + $1 - 2 ))"
  413. bprof block_begin stop
  414. }
  415. block_end() {
  416. bprof block_end start
  417. spacer="${spacer%??}"
  418. tabspace="${tabspace_list%% *}"
  419. tabspace_list="${tabspace_list#* }"
  420. bprof block_end stop
  421. }
  422. # has to be called at the beginning of each config cycle
  423. config_cycle() {
  424. expert=0
  425. menu_counter=0 ; commentnr=0 ; editfilenr=0
  426. spacer="" ; tabspace="5" ; tabspace_list=""
  427. }
  428. expert_begin() {
  429. expert=$(( $expert + 1 ))
  430. }
  431. expert_end() {
  432. expert=$(( $expert - 1 ))
  433. }
  434. menu_begin() {
  435. local id="$1" name="$2"
  436. bprof menu_begin start
  437. menu_counter=$(( $menu_counter + 1 ))
  438. if [ "$ROCKCFG_EXPERT" -eq 1 -o $expert -eq 0 ]
  439. then
  440. printf "$id '$spacer%-${tabspace}s %s'\n" \
  441. "===>" "$name" >> $swpdir/config.dialog.$menu_this
  442. echo -e "$id\tmenu_current=$menu_counter" \
  443. >> $swpdir/config.data.$menu_this
  444. echo "$id '===> $name'" >> $swpdir/config.dialog.$menu_counter
  445. echo -e "$id\tmenu_current=$menu_this current=$id" \
  446. >> $swpdir/config.data.$menu_counter
  447. echo -e "MENU_BACK\tmenu_current=$menu_this current=$id" \
  448. >> $swpdir/config.data.$menu_counter
  449. fi
  450. menu_stack="$menu_this $menu_stack"
  451. menu_this=$menu_counter
  452. block_begin 3
  453. bprof menu_begin stop
  454. }
  455. menu_end() {
  456. bprof menu_end start
  457. block_end
  458. menu_this="${menu_stack%% *}"
  459. menu_stack="${menu_stack#* }"
  460. bprof menu_end stop
  461. }
  462. set_help() {
  463. local id="$1" help="$2"
  464. bprof set_help start
  465. if [ "$help" != "" ] ; then
  466. echo -e "$id $help\n\n" >> $swpdir/config.help
  467. fi
  468. bprof set_help stop
  469. }
  470. get_help() {
  471. local item_name="$1" tmp_text hlp_text default_text
  472. bprof get_help start
  473. cat << EOT
  474. This is the ROCK Linux $rockver Configuration Tool.
  475. Config option types:
  476. [*] [ ] Unmodified bool value (set and unset)
  477. <*> < > User-modified bool value (set and unset)
  478. (foobar) Unmodified selection or text field
  479. <foobar> User-modified selection or text field
  480. Note that e.g. bool value are in fact tristate options:
  481. user set, user unset and and the unmodified default value
  482. This is because one option might change the default value
  483. of another option. You might need a while to get used to
  484. the concept, but in the end it really makes sense.
  485. -----
  486. EOT
  487. # Create standard help output ...
  488. default_text="
  489. There is no help on '$item_name' available.
  490. Please read the build Documentation (Documentation/BUILD)
  491. before building ROCK Linux.
  492. More information can be found on the ROCK Linux Homepage:
  493. http://www.rocklinux.org/
  494. Information about the ROCK Linux mailing lists and the mailing
  495. list archive can be found at:
  496. http://www.rocklinux.org/wiki/Mailing_Lists and
  497. http://www.rocklinux.net/lurker/splash"
  498. # Ok let us find a help for the current item ...
  499. hlp_text="$( sed -e "/^$item_name\$/,/^\$/ p ; d" \
  500. misc/*/{,*/}config*.hlp package/*/*/{sub,}config-*.hlp \
  501. {scripts,target/*}/config*.hlp 2>/dev/null )"
  502. # Get help strings out of the temporary file.
  503. tmp_text="$( sed -e "/^[ ]*$item_name\([ ]\|\$\)/,/^\$/ p ; d" \
  504. $swpdir/config.help 2>/dev/null )"
  505. # Let us see what we have ...
  506. if [ "$hlp_text" -a "$tmp_text" ] ; then
  507. echo "
  508. There are two help text's... one in one of the config.in files and one
  509. in one of the config.hlp files. Please remove one of them to get rid of
  510. this message here.
  511. Here the one out of config.in:
  512. $tmp_text
  513. Here the one out of config.hlp:
  514. $hlp_text"
  515. elif [ "$hlp_text" ] ; then
  516. echo "config.hlp: $hlp_text"
  517. elif [ "$tmp_text" ] ; then
  518. echo "config.in: $tmp_text"
  519. else
  520. echo "$default_text"
  521. fi
  522. bprof get_help stop
  523. }