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.

608 lines
15 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 - 2006 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.$swpid
  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' '$3'" >> 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. local usrvar=$1
  336. local origval=$3
  337. local usrval
  338. eval "usrval=\${$usrvar}"
  339. case "$usrval" in
  340. "") [ "$origval" == "0" ] && eval "$usrvar=1"
  341. [ "$origval" == "1" ] && eval "$usrvar=0"
  342. ;;
  343. 1) [ "$origval" == "0" ] && eval "$usrvar=0"
  344. [ "$origval" == "1" ] && eval "$usrvar="
  345. ;;
  346. 0) [ "$origval" == "0" ] && eval "$usrvar="
  347. [ "$origval" == "1" ] && eval "$usrvar=1"
  348. ;;
  349. esac
  350. }
  351. editfile() {
  352. bprof editfile start
  353. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  354. local x="$spacer" q="'"
  355. comment ",----< $3 >----."
  356. block_begin 0 ; spacer="${spacer%??}| "
  357. touch "$2"
  358. line_nr=1
  359. while read line ; do
  360. line="${line//$q/$q\\$q$q}"
  361. if [ $menu_current = $menu_this ] ; then
  362. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  363. `printf "%03d:" $line_nr` "$line" >> config.dialog.$swpid
  364. echo -e "$1:${editfilenr}\teditfile_action $2" \
  365. "$line_nr '$3'" >> config.data.$swpid
  366. fi
  367. editfilenr=$(( $editfilenr + 1 ))
  368. line_nr=$(( $line_nr + 1 ))
  369. done < "$2"
  370. if [ $menu_current = $menu_this ] ; then
  371. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  372. `printf "%03d:" $line_nr` "<add new rule>" >> config.dialog.$swpid
  373. echo -e "$1:${editfilenr}\teditfile_action $2" \
  374. "$line_nr '$3'" >> config.data.$swpid
  375. fi
  376. editfilenr=$(( $editfilenr + 1 ))
  377. block_end
  378. comment "\`------${3//?/-}------'\''"
  379. spacer="$x"
  380. else
  381. rm -f "$2"
  382. fi
  383. bprof editfile stop
  384. }
  385. editfile_action() {
  386. line="`tail -n +$2 $1 | head -n 1`"
  387. ./src/rockdialog.bin --title 'Build Config' \
  388. --backtitle "$configtitle" \
  389. --inputbox "$3 - Line $3" \
  390. 9 $(( $columns - 5 )) "$line" 2> config.out.$swpid
  391. head -n $(( $2 - 1 )) $1 > $1.new
  392. [ -s config.out.$swpid ] && echo "`cat config.out.$swpid`" >> $1.new
  393. tail -n +$(( $2 + 1 )) $1 >> $1.new
  394. mv $1.new $1
  395. }
  396. startprog() {
  397. bprof startprog start
  398. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  399. [ $menu_current = $menu_this ] ; then
  400. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  401. "-->" "$2" >> config.dialog.$swpid
  402. echo -e "$1\t$3" >> config.data.$swpid
  403. fi
  404. bprof startprog stop
  405. }
  406. block_begin() {
  407. bprof block_begin start
  408. if [ $menu_current = $menu_this ] ; then
  409. [ "$tabspace_list" ] && spacer="$spacer "
  410. tabspace_list="$tabspace $tabspace_list"
  411. tabspace="$(( $tabspace + $1 - 2 ))"
  412. fi
  413. bprof block_begin stop
  414. }
  415. block_end() {
  416. bprof block_end start
  417. if [ $menu_current = $menu_this ] ; then
  418. spacer="${spacer%??}"
  419. tabspace="${tabspace_list%% *}"
  420. tabspace_list="${tabspace_list#* }"
  421. fi
  422. bprof block_end stop
  423. }
  424. expert_begin() {
  425. expert=$(( $exprt + 1 ))
  426. }
  427. expert_end() {
  428. expert=$(( $exprt - 1 ))
  429. }
  430. menu_begin() {
  431. bprof menu_begin start
  432. menu_counter=$(( $menu_counter + 1 ))
  433. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  434. [ $menu_current = $menu_this ] ; then
  435. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  436. "===>" "$2" >> config.dialog.$swpid
  437. echo -e "$1\tmenu_current=$menu_counter" >> config.data.$swpid
  438. fi
  439. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  440. [ $menu_current = $menu_counter ] ; then
  441. echo "$1 '===> $2'" >> config.dialog.$swpid
  442. echo -e "$1\tmenu_current=$menu_this" >> config.data.$swpid
  443. fi
  444. if [ $menu_current = $menu_counter ] ; then
  445. menu_back=$menu_this
  446. menu_backpos=$1
  447. fi
  448. menu_stack="$menu_this $menu_stack"
  449. menu_this=$menu_counter
  450. block_begin 3
  451. bprof menu_begin stop
  452. }
  453. menu_end() {
  454. bprof menu_end start
  455. block_end
  456. menu_this="${menu_stack%% *}"
  457. menu_stack="${menu_stack#* }"
  458. bprof menu_end stop
  459. }
  460. set_help() {
  461. bprof set_help start
  462. (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  463. tr -d '\n' | sed 's,\\n$,,'; echo ) >> config.help.$swpid
  464. bprof set_help stop
  465. }
  466. get_help() {
  467. bprof get_help start
  468. cat << EOT
  469. This is the ROCK Linux $rockver Configuration Tool.
  470. Config option types:
  471. [*] [ ] Unmodified bool value (set and unset)
  472. <*> < > User-modified bool value (set and unset)
  473. (foobar) Unmodified selection or text field
  474. <foobar> User-modified selection or text field
  475. Note that e.g. bool value are in fact tristate options:
  476. user set, user unset and and the unmodified default value
  477. This is because one option might change the default value
  478. of another option. You might need a while to get used to
  479. the concept, but in the end it really makes sense.
  480. -----
  481. EOT
  482. # Create standard help output ...
  483. default_text="
  484. There is no help on '$1' available.
  485. Please read the build Documentation (Documentation/BUILD)
  486. before building ROCK Linux.
  487. More information can be found on the ROCK Linux Homepage:
  488. http://www.rocklinux.org/
  489. Information about the ROCK Linux mailing lists and the mailing
  490. list archive can be found at:
  491. http://www.rocklinux.org/mail.html and
  492. http://www.rocklinux.net/lurker/splash"
  493. # Ok let us find a help for the current item ...
  494. # First of all mask all special chars in the item name
  495. # Comment: this is sick. You can't get any \n this way !!!
  496. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  497. # Now search *.hlp files
  498. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  499. /^$item_name[ ]*\$/c\\
  500. $item_name:\\
  501. /^#/d
  502. /^[^ ]/q
  503. s/^ //
  504. p
  505. }" scripts/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp misc/*/config*.hlp misc/*/*/config*.hlp 2>/dev/null )
  506. # Get help strings out of the temporary file.
  507. tmp_text=$(grep "^$item_name" config.help.$swpid | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  508. # Let us see what we have ...
  509. if [ "$hlp_text" -a "$tmp_text" ] ; then
  510. echo "
  511. There are two help text's... one in one of the config.in files and one
  512. in one of the config.hlp files. Please remove one of them to get rid of
  513. this message here.
  514. Here the one out of config.in:
  515. $tmp_text
  516. Here the one out of config.hlp:
  517. $hlp_text"
  518. elif [ "$hlp_text" ] ; then
  519. echo "$hlp_text"
  520. elif [ "$tmp_text" ] ; then
  521. echo "$tmp_text"
  522. else
  523. echo "$default_text"
  524. fi
  525. bprof get_help stop
  526. }