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.

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