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