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.

522 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. comment() {
  130. bprof comment start
  131. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && \
  132. [ $menu_current = $menu_this ] ; then
  133. commentnr=$(( $commentnr + 1 ))
  134. echo "COMMENT_$commentnr '$spacer$1'" >> config.dialog
  135. # Hi, esden here, very ill stuff here I save the help
  136. # strings here to a temporary file named config.help
  137. # this sed tr sandwitch formats the string so that
  138. # \n are masked and the Help strings are not killed some way
  139. if [ "$2" != "" ] ; then
  140. set_help "COMMENT_$commentnr" "$2"
  141. fi
  142. fi
  143. bprof comment stop
  144. }
  145. comment_id() {
  146. bprof comment_id start
  147. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  148. [ $menu_current = $menu_this ] ; then
  149. echo "$2 '$spacer$1'" >> config.dialog
  150. # If you do not know what mighty esden
  151. # is doing here see comment()
  152. if [ "$3" != "" ] ; then
  153. set_help "$2" "$3"
  154. fi
  155. fi
  156. bprof comment_id stop
  157. }
  158. const() {
  159. bprof const start
  160. local q="'"
  161. local v="${2//$q/$q\\$q$q}"
  162. eval "$1=\"\$2\""
  163. echo "export $1='$v'" >> config/$config/config
  164. bprof const stop
  165. }
  166. # Usage: set_data NAME DEFAULT
  167. #
  168. set_data() {
  169. bprof set_data start
  170. local q="'" set_name="ROCKCFGSET_${1#ROCKCFG_}"
  171. if eval "[ \"\$$set_name\" ]" ; then
  172. eval "data=\"\$$set_name\""
  173. eval "$1=\"\$data\""
  174. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  175. then menumode=2 ; else menumode=0 ; fi
  176. elif [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  177. eval "data=\"\${$1:-$2}\""
  178. eval "$1=\"\$data\""
  179. menumode=1
  180. else
  181. data="$2" ; eval "$1=\"\$data\""
  182. menumode=0
  183. fi
  184. item="$1"
  185. echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config/config
  186. bprof set_data stop
  187. }
  188. choice() {
  189. bprof choice start
  190. # reset to default if current value is not in list
  191. #
  192. eval $(
  193. eval "value=\$$1" ; name=$1 ; shift ; shift
  194. while [ "$#" != 0 ] ; do
  195. [ "$value" = "$1" ] && name="" ; shift ; shift
  196. done
  197. [ "$name" ] && echo "unset $name"
  198. )
  199. set_data "$1" "$2"
  200. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  201. { echo -en "$item\tchoice_action '$1' '$data'" ; shift ; shift
  202. for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data
  203. fi
  204. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  205. if [ "$menumode" -eq 1 ] ; then xdata="($data)"
  206. else xdata="=$data=" ; fi
  207. while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done
  208. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \
  209. "$xdata" >> config.dialog
  210. fi
  211. bprof choice stop
  212. }
  213. choice_action() {
  214. command="./src/rockdialog.bin --title 'Build Config' \
  215. --backtitle '$configtitle' \
  216. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  217. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  218. default=$2 ; item=$1 ; shift ; shift
  219. while [ "$1" ] ; do
  220. if [ "$1" = "$default" ]
  221. then command="$command '$1' '${2//_/ }' ON"
  222. else command="$command '$1' '${2//_/ }' OFF" ; fi
  223. shift ; shift
  224. done
  225. eval "$command" 2> config.out
  226. case "$?" in
  227. 0|6)
  228. eval "$item='`cat config.out`'"
  229. ;;
  230. 1|255) return 0 ;;
  231. 2) echo "No help." ; sleep 1 ;;
  232. *) echo "unknown returncode: $?" ; exit 1 ;;
  233. esac
  234. }
  235. text() {
  236. bprof text start
  237. local q="'"
  238. set_data "$2" "$3"
  239. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  240. echo -e "$2\ttext_action '$1' '$2'" \
  241. "'${data//$q/$q\\$q$q}'" >> config.data
  242. fi
  243. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  244. xdata="$( printf "%-${tabspace}s" \
  245. "$(echo $data | cut -c1-20)")"
  246. if [ "$menumode" -eq 1 ] ; then xdata="($xdata)"
  247. else xdata="=$xdata=" ; fi
  248. printf "'$2' '$spacer%s $1'\n" \
  249. "${xdata//$q/$q\\$q$q}" >> config.dialog
  250. # If you do not know what mighty esden
  251. # is doin here see comment()
  252. if [ "$4" != "" ] ; then
  253. set_help "$2" "$4"
  254. fi
  255. fi
  256. bprof text stop
  257. }
  258. text_action() {
  259. ./src/rockdialog.bin --title 'Build Config' \
  260. --backtitle "$configtitle" \
  261. --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> config.out
  262. [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat config.out)\""
  263. }
  264. bool() {
  265. bprof bool start
  266. local x
  267. set_data "$2" "$3"
  268. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  269. echo -e "$2\tbool_action '$1' '$2' '$data'" >> config.data
  270. fi
  271. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  272. if [ "$menumode" -eq 1 ] ; then
  273. if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi
  274. else
  275. if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi
  276. fi
  277. printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \
  278. "$x" >> config.dialog
  279. # If you do not know what mighty esden is doin here see comment()
  280. if [ "$4" != "" ] ; then
  281. set_help "$2" "$4"
  282. fi
  283. fi
  284. bprof bool stop
  285. }
  286. bool_action() {
  287. if [ $3 -eq 0 ] ; then eval "$2=1"
  288. else eval "$2=0" ; fi
  289. }
  290. editfile() {
  291. bprof editfile start
  292. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  293. local x="$spacer" q="'"
  294. comment ",----< $3 >----."
  295. block_begin 0 ; spacer="${spacer%??}| "
  296. touch "$2"
  297. line_nr=1
  298. while read line ; do
  299. line="${line//$q/$q\\$q$q}"
  300. if [ $menu_current = $menu_this ] ; then
  301. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  302. `printf "%03d:" $line_nr` "$line" >> config.dialog
  303. echo -e "$1:${editfilenr}\teditfile_action $2" \
  304. "$line_nr '$3'" >> config.data
  305. fi
  306. editfilenr=$(( $editfilenr + 1 ))
  307. line_nr=$(( $line_nr + 1 ))
  308. done < "$2"
  309. if [ $menu_current = $menu_this ] ; then
  310. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  311. `printf "%03d:" $line_nr` "<add new rule>" >> config.dialog
  312. echo -e "$1:${editfilenr}\teditfile_action $2" \
  313. "$line_nr '$3'" >> config.data
  314. fi
  315. editfilenr=$(( $editfilenr + 1 ))
  316. block_end
  317. comment "\`------${3//?/-}------'\''"
  318. spacer="$x"
  319. else
  320. rm -f "$2"
  321. fi
  322. bprof editfile stop
  323. }
  324. editfile_action() {
  325. line="`tail -n +$2 $1 | head -n 1`"
  326. ./src/rockdialog.bin --title 'Build Config' \
  327. --backtitle "$configtitle" \
  328. --inputbox "$3 - Line $3" \
  329. 9 $(( $columns - 5 )) "$line" 2> config.out
  330. head -n $(( $2 - 1 )) $1 > $1.new
  331. [ -s config.out ] && echo "`cat config.out`" >> $1.new
  332. tail -n +$(( $2 + 1 )) $1 >> $1.new
  333. mv $1.new $1
  334. }
  335. startprog() {
  336. bprof startprog start
  337. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  338. [ $menu_current = $menu_this ] ; then
  339. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  340. "-->" "$2" >> config.dialog
  341. echo -e "$1\t$3" >> config.data
  342. fi
  343. bprof startprog stop
  344. }
  345. block_begin() {
  346. bprof block_begin start
  347. if [ $menu_current = $menu_this ] ; then
  348. [ "$tabspace_list" ] && spacer="$spacer "
  349. tabspace_list="$tabspace $tabspace_list"
  350. tabspace="$(( $tabspace + $1 - 2 ))"
  351. fi
  352. bprof block_begin stop
  353. }
  354. block_end() {
  355. bprof block_end start
  356. if [ $menu_current = $menu_this ] ; then
  357. spacer="${spacer%??}"
  358. tabspace="${tabspace_list%% *}"
  359. tabspace_list="${tabspace_list#* }"
  360. fi
  361. bprof block_end stop
  362. }
  363. expert_begin() {
  364. expert=$(( $exprt + 1 ))
  365. }
  366. expert_end() {
  367. expert=$(( $exprt - 1 ))
  368. }
  369. menu_begin() {
  370. bprof menu_begin start
  371. menu_counter=$(( $menu_counter + 1 ))
  372. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  373. [ $menu_current = $menu_this ] ; then
  374. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  375. "===>" "$2" >> config.dialog
  376. echo -e "$1\tmenu_current=$menu_counter" >> config.data
  377. fi
  378. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  379. [ $menu_current = $menu_counter ] ; then
  380. echo "$1 '===> $2'" >> config.dialog
  381. echo -e "$1\tmenu_current=$menu_this" >> config.data
  382. fi
  383. if [ $menu_current = $menu_counter ] ; then
  384. menu_back=$menu_this
  385. menu_backpos=$1
  386. fi
  387. menu_stack="$menu_this $menu_stack"
  388. menu_this=$menu_counter
  389. block_begin 3
  390. bprof menu_begin stop
  391. }
  392. menu_end() {
  393. bprof menu_end start
  394. block_end
  395. menu_this="${menu_stack%% *}"
  396. menu_stack="${menu_stack#* }"
  397. bprof menu_end stop
  398. }
  399. set_help() {
  400. bprof set_help start
  401. (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  402. tr -d '\n' | sed 's,\\n$,,'; echo ) >> config.help
  403. bprof set_help stop
  404. }
  405. get_help() {
  406. bprof get_help start
  407. # Create standard help output ...
  408. default_text="
  409. There is no help on '$1' available.
  410. This is the ROCK Linux $rockver Configuration Tool.
  411. Please read the build Documentation (Documentation/BUILD)
  412. and the ROCK Linux Guide (Documentation/Guide/GUIDE.txt)
  413. before building ROCK Linux.
  414. More information can be found on the ROCK Linux Homepage:
  415. http://www.rocklinux.org/
  416. Subscribe to the mailing list by sending an e-mail with the
  417. subject 'subscribe rock-linux' to <minimalist@rocklinux.org>."
  418. # Ok let us find a help for the current item ...
  419. # First of all mask all special chars in the item name
  420. # Comment: this is sick. You can't get any \n this way !!!
  421. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  422. # Now search *.hlp files
  423. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  424. /^$item_name[ ]*\$/c\\
  425. $item_name:\\
  426. /^#/d
  427. /^[^ ]/q
  428. s/^ //
  429. p
  430. }" scripts/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp misc/config/config*.hlp 2>/dev/null )
  431. # Get help strings out of the temporary file.
  432. tmp_text=$(grep "^$item_name" config.help | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  433. # Let us see what we have ...
  434. if [ "$hlp_text" -a "$tmp_text" ] ; then
  435. echo "
  436. There are two help text's... one in one of the config.in files and one
  437. in one of the config.hlp files. Please remove one of them to get rid of
  438. this message here.
  439. Here the one out of config.in:
  440. $tmp_text
  441. Here the one out of config.hlp:
  442. $hlp_text"
  443. elif [ "$hlp_text" ] ; then
  444. echo "$hlp_text"
  445. elif [ "$tmp_text" ] ; then
  446. echo "$tmp_text"
  447. else
  448. echo "$default_text"
  449. fi
  450. bprof get_help stop
  451. }