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.

559 lines
13 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="'" set_name="ROCKCFGSET_${1#ROCKCFG_}"
  207. if eval "[ \"\$$set_name\" ]" ; then
  208. eval "data=\"\$$set_name\""
  209. eval "$1=\"\$data\""
  210. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  211. then menumode=2 ; else menumode=0 ; fi
  212. elif [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  213. eval "data=\"\${$1:-$2}\""
  214. eval "$1=\"\$data\""
  215. menumode=1
  216. else
  217. data="$2" ; eval "$1=\"\$data\""
  218. menumode=0
  219. fi
  220. item="$1"
  221. echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config/config
  222. bprof set_data stop
  223. }
  224. choice() {
  225. bprof choice start
  226. # reset to default if current value is not in list
  227. #
  228. eval $(
  229. eval "value=\$$1" ; name=$1 ; shift ; shift
  230. while [ "$#" != 0 ] ; do
  231. [ "$value" = "$1" ] && name="" ; shift ; shift
  232. done
  233. [ "$name" ] && echo "unset $name"
  234. )
  235. set_data "$1" "$2"
  236. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  237. { echo -en "$item\tchoice_action '$1' '$data'" ; shift ; shift
  238. for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data
  239. fi
  240. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  241. if [ "$menumode" -eq 1 ] ; then xdata="($data)"
  242. else xdata="=$data=" ; fi
  243. while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done
  244. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \
  245. "$xdata" >> config.dialog
  246. fi
  247. bprof choice stop
  248. }
  249. choice_action() {
  250. command="./src/rockdialog.bin --title 'Build Config' \
  251. --backtitle '$configtitle' \
  252. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  253. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  254. default=$2 ; item=$1 ; shift ; shift
  255. while [ "$1" ] ; do
  256. if [ "$1" = "$default" ]
  257. then command="$command '$1' '${2//_/ }' ON"
  258. else command="$command '$1' '${2//_/ }' OFF" ; fi
  259. shift ; shift
  260. done
  261. eval "$command" 2> config.out
  262. case "$?" in
  263. 0|6)
  264. eval "$item='`cat config.out`'"
  265. ;;
  266. 1|255) return 0 ;;
  267. 2) echo "No help." ; sleep 1 ;;
  268. *) echo "unknown returncode: $?" ; exit 1 ;;
  269. esac
  270. }
  271. text() {
  272. bprof text start
  273. local q="'"
  274. set_data "$2" "$3"
  275. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  276. echo -e "$2\ttext_action '$1' '$2'" \
  277. "'${data//$q/$q\\$q$q}'" >> config.data
  278. fi
  279. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  280. xdata="$( printf "%-${tabspace}s" \
  281. "$(echo $data | cut -c1-20)")"
  282. if [ "$menumode" -eq 1 ] ; then xdata="($xdata)"
  283. else xdata="=$xdata=" ; fi
  284. printf "'$2' '$spacer%s $1'\n" \
  285. "${xdata//$q/$q\\$q$q}" >> config.dialog
  286. # If you do not know what mighty esden
  287. # is doin here see comment()
  288. if [ "$4" != "" ] ; then
  289. set_help "$2" "$4"
  290. fi
  291. fi
  292. bprof text stop
  293. }
  294. text_action() {
  295. ./src/rockdialog.bin --title 'Build Config' \
  296. --backtitle "$configtitle" \
  297. --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> config.out
  298. [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat config.out)\""
  299. }
  300. bool() {
  301. bprof bool start
  302. local x
  303. set_data "$2" "$3"
  304. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  305. echo -e "$2\tbool_action '$1' '$2' '$data'" >> config.data
  306. fi
  307. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  308. if [ "$menumode" -eq 1 ] ; then
  309. if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi
  310. else
  311. if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi
  312. fi
  313. printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \
  314. "$x" >> config.dialog
  315. # If you do not know what mighty esden is doin here see comment()
  316. if [ "$4" != "" ] ; then
  317. set_help "$2" "$4"
  318. fi
  319. fi
  320. bprof bool stop
  321. }
  322. bool_action() {
  323. if [ $3 -eq 0 ] ; then eval "$2=1"
  324. else eval "$2=0" ; fi
  325. }
  326. editfile() {
  327. bprof editfile start
  328. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  329. local x="$spacer" q="'"
  330. comment ",----< $3 >----."
  331. block_begin 0 ; spacer="${spacer%??}| "
  332. touch "$2"
  333. line_nr=1
  334. while read line ; do
  335. line="${line//$q/$q\\$q$q}"
  336. if [ $menu_current = $menu_this ] ; then
  337. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  338. `printf "%03d:" $line_nr` "$line" >> config.dialog
  339. echo -e "$1:${editfilenr}\teditfile_action $2" \
  340. "$line_nr '$3'" >> config.data
  341. fi
  342. editfilenr=$(( $editfilenr + 1 ))
  343. line_nr=$(( $line_nr + 1 ))
  344. done < "$2"
  345. if [ $menu_current = $menu_this ] ; then
  346. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  347. `printf "%03d:" $line_nr` "<add new rule>" >> config.dialog
  348. echo -e "$1:${editfilenr}\teditfile_action $2" \
  349. "$line_nr '$3'" >> config.data
  350. fi
  351. editfilenr=$(( $editfilenr + 1 ))
  352. block_end
  353. comment "\`------${3//?/-}------'\''"
  354. spacer="$x"
  355. else
  356. rm -f "$2"
  357. fi
  358. bprof editfile stop
  359. }
  360. editfile_action() {
  361. line="`tail -n +$2 $1 | head -n 1`"
  362. ./src/rockdialog.bin --title 'Build Config' \
  363. --backtitle "$configtitle" \
  364. --inputbox "$3 - Line $3" \
  365. 9 $(( $columns - 5 )) "$line" 2> config.out
  366. head -n $(( $2 - 1 )) $1 > $1.new
  367. [ -s config.out ] && echo "`cat config.out`" >> $1.new
  368. tail -n +$(( $2 + 1 )) $1 >> $1.new
  369. mv $1.new $1
  370. }
  371. startprog() {
  372. bprof startprog start
  373. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  374. [ $menu_current = $menu_this ] ; then
  375. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  376. "-->" "$2" >> config.dialog
  377. echo -e "$1\t$3" >> config.data
  378. fi
  379. bprof startprog stop
  380. }
  381. block_begin() {
  382. bprof block_begin start
  383. if [ $menu_current = $menu_this ] ; then
  384. [ "$tabspace_list" ] && spacer="$spacer "
  385. tabspace_list="$tabspace $tabspace_list"
  386. tabspace="$(( $tabspace + $1 - 2 ))"
  387. fi
  388. bprof block_begin stop
  389. }
  390. block_end() {
  391. bprof block_end start
  392. if [ $menu_current = $menu_this ] ; then
  393. spacer="${spacer%??}"
  394. tabspace="${tabspace_list%% *}"
  395. tabspace_list="${tabspace_list#* }"
  396. fi
  397. bprof block_end stop
  398. }
  399. expert_begin() {
  400. expert=$(( $exprt + 1 ))
  401. }
  402. expert_end() {
  403. expert=$(( $exprt - 1 ))
  404. }
  405. menu_begin() {
  406. bprof menu_begin start
  407. menu_counter=$(( $menu_counter + 1 ))
  408. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  409. [ $menu_current = $menu_this ] ; then
  410. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  411. "===>" "$2" >> config.dialog
  412. echo -e "$1\tmenu_current=$menu_counter" >> config.data
  413. fi
  414. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  415. [ $menu_current = $menu_counter ] ; then
  416. echo "$1 '===> $2'" >> config.dialog
  417. echo -e "$1\tmenu_current=$menu_this" >> config.data
  418. fi
  419. if [ $menu_current = $menu_counter ] ; then
  420. menu_back=$menu_this
  421. menu_backpos=$1
  422. fi
  423. menu_stack="$menu_this $menu_stack"
  424. menu_this=$menu_counter
  425. block_begin 3
  426. bprof menu_begin stop
  427. }
  428. menu_end() {
  429. bprof menu_end start
  430. block_end
  431. menu_this="${menu_stack%% *}"
  432. menu_stack="${menu_stack#* }"
  433. bprof menu_end stop
  434. }
  435. set_help() {
  436. bprof set_help start
  437. (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  438. tr -d '\n' | sed 's,\\n$,,'; echo ) >> config.help
  439. bprof set_help stop
  440. }
  441. get_help() {
  442. bprof get_help start
  443. # Create standard help output ...
  444. default_text="
  445. There is no help on '$1' available.
  446. This is the ROCK Linux $rockver Configuration Tool.
  447. Please read the build Documentation (Documentation/BUILD)
  448. and the ROCK Linux Guide (Documentation/Guide/GUIDE.txt)
  449. before building ROCK Linux.
  450. More information can be found on the ROCK Linux Homepage:
  451. http://www.rocklinux.org/
  452. Subscribe to the mailing list by sending an e-mail with the
  453. subject 'subscribe rock-linux' to <minimalist@rocklinux.org>."
  454. # Ok let us find a help for the current item ...
  455. # First of all mask all special chars in the item name
  456. # Comment: this is sick. You can't get any \n this way !!!
  457. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  458. # Now search *.hlp files
  459. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  460. /^$item_name[ ]*\$/c\\
  461. $item_name:\\
  462. /^#/d
  463. /^[^ ]/q
  464. s/^ //
  465. p
  466. }" scripts/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp misc/config/config*.hlp 2>/dev/null )
  467. # Get help strings out of the temporary file.
  468. tmp_text=$(grep "^$item_name" config.help | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  469. # Let us see what we have ...
  470. if [ "$hlp_text" -a "$tmp_text" ] ; then
  471. echo "
  472. There are two help text's... one in one of the config.in files and one
  473. in one of the config.hlp files. Please remove one of them to get rid of
  474. this message here.
  475. Here the one out of config.in:
  476. $tmp_text
  477. Here the one out of config.hlp:
  478. $hlp_text"
  479. elif [ "$hlp_text" ] ; then
  480. echo "$hlp_text"
  481. elif [ "$tmp_text" ] ; then
  482. echo "$tmp_text"
  483. else
  484. echo "$default_text"
  485. fi
  486. bprof get_help stop
  487. }