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.

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