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.

566 lines
15 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Config
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ] ; then
  25. if [ "$( type -p stty )" ] ; then
  26. lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
  27. columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
  28. fi
  29. [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
  30. [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
  31. fi
  32. eval "$(egrep '^rockver=' scripts/parse-config)"
  33. config=default
  34. do_config_cycle=0
  35. delete_mode=0
  36. oldconfig=''
  37. while [ "$1" ] ; do
  38. case "$1" in
  39. -cycle) do_config_cycle=1 ; shift ;;
  40. -delete) delete_mode=1 ; shift ;;
  41. -oldconfig) oldconfig='-oldconfig' ; shift ;;
  42. -cfg) config="$2" ; shift ; shift ;;
  43. *)
  44. echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
  45. exit 1 ;;
  46. esac
  47. done
  48. if [ $delete_mode = 1 ] ; then
  49. rm -rv config/$config
  50. exit $?
  51. fi
  52. if [ $do_config_cycle = 0 ] ; then
  53. rm -f config.data config.dialog config.out config.help
  54. rm -f config.pcache.data config.pcache.cmd
  55. rm -f rockdialog.scrltmp # src/rockdialog.bin
  56. mkdir -p src
  57. if [ -z "$oldconfig" -a ! -f src/rockdialog.bin ] ; then
  58. echo "Creating rockdialog tool ..."
  59. command="gcc misc/rockdialog/*.c `
  60. `-Imisc/rockdialog -lncurses -o src/rockdialog.bin"
  61. echo "$command" ; eval "$command.$$"
  62. mv src/rockdialog.bin.$$ src/rockdialog.bin
  63. fi
  64. echo "Creating configuration script ..."
  65. cat << "EOT" > src/rockconfig.awk.$$
  66. #!/usr/bin/awk -f
  67. FNR == 1 {
  68. if ( lastfile ) {
  69. print "### END of " lastfile;
  70. }
  71. print "### BEGIN of " FILENAME;
  72. lastfile = FILENAME;
  73. }
  74. END {
  75. print "### END of " FILENAME;
  76. }
  77. $1 == "%include" {
  78. $1 = "awk -f src/rockconfig.awk";
  79. system($0);
  80. next;
  81. }
  82. $1 == "#" { next; }
  83. { print; }
  84. EOT
  85. mv src/rockconfig.awk.$$ src/rockconfig.awk
  86. awk -f src/rockconfig.awk scripts/config.in > src/rockconfig.in.$$ 2> /dev/null
  87. mv src/rockconfig.in.$$ src/rockconfig.in
  88. echo "Running ROCK Linux $rockver configuration ..."
  89. while "$0" -cfg $config $oldconfig -cycle ; do : ; done
  90. exit 0
  91. fi
  92. set_help() {
  93. (echo -ne "$1 '$1:\n\n$2'" | sed 's,$,\\n,' |
  94. tr -d '\n' | sed 's,\\n$,,'; echo ) >> config.help
  95. }
  96. comment() {
  97. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] && \
  98. [ $menu_current = $menu_this ] ; then
  99. commentnr=$(( $commentnr + 1 ))
  100. echo "COMMENT_$commentnr '$spacer$1'" >> config.dialog
  101. # Hi, esden here, very ill stuff here I save the help
  102. # strings here to a temporary file named config.help
  103. # this sed tr sandwitch formats the string so that
  104. # \n are masked and the Help strings are not killed some way
  105. if [ "$2" != "" ] ; then
  106. set_help "COMMENT_$commentnr" "$2"
  107. fi
  108. fi
  109. }
  110. comment_id() {
  111. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  112. [ $menu_current = $menu_this ] ; then
  113. echo "$2 '$spacer$1'" >> config.dialog
  114. # If you do not know what mighty esden
  115. # is doing here see comment()
  116. if [ "$3" != "" ] ; then
  117. set_help "$2" "$3"
  118. fi
  119. fi
  120. }
  121. const() {
  122. local q="'"
  123. local v="${2//$q/$q\\$q$q}"
  124. eval "$1=\"\$2\""
  125. echo "export $1='$v'" >> config/$config/config
  126. }
  127. # Usage: set_data NAME DEFAULT
  128. #
  129. set_data() {
  130. local q="'" set_name="ROCKCFGSET_${1#ROCKCFG_}"
  131. if eval "[ \"\$$set_name\" ]" ; then
  132. eval "data=\"\$$set_name\""
  133. eval "$1=\"\$data\""
  134. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ]
  135. then menumode=2 ; else menumode=0 ; fi
  136. elif [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  137. eval "data=\"\${$1:-$2}\""
  138. eval "$1=\"\$data\""
  139. menumode=1
  140. else
  141. data="$2" ; eval "$1=\"\$data\""
  142. menumode=0
  143. fi
  144. item="$1"
  145. echo "export $1='${data//$q/$q\\$q$q}'" >> config/$config/config
  146. }
  147. choice() {
  148. # reset to default if current value is not in list
  149. #
  150. eval $(
  151. eval "value=\$$1" ; name=$1 ; shift ; shift
  152. while [ "$#" != 0 ] ; do
  153. [ "$value" = "$1" ] && name="" ; shift ; shift
  154. done
  155. [ "$name" ] && echo "unset $name"
  156. )
  157. set_data "$1" "$2"
  158. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  159. { echo -en "$item\tchoice_action '$1' '$data'" ; shift ; shift
  160. for x ; do echo -n " '$x'" ; done ; echo ; } >> config.data
  161. fi
  162. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  163. if [ "$menumode" -eq 1 ] ; then xdata="($data)"
  164. else xdata="=$data=" ; fi
  165. while [ "$1" -a "$1" != "$data" ] ; do shift ; shift ; done
  166. printf "'$item' '$spacer%-${tabspace}s ${2//_/ }'\n" \
  167. "$xdata" >> config.dialog
  168. fi
  169. }
  170. choice_action() {
  171. command="./src/rockdialog.bin --title 'Build Config' \
  172. --backtitle '$configtitle' \
  173. --radiolist 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  174. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 ))"
  175. default=$2 ; item=$1 ; shift ; shift
  176. while [ "$1" ] ; do
  177. if [ "$1" = "$default" ]
  178. then command="$command '$1' '${2//_/ }' ON"
  179. else command="$command '$1' '${2//_/ }' OFF" ; fi
  180. shift ; shift
  181. done
  182. eval "$command" 2> config.out
  183. case "$?" in
  184. 0|6)
  185. eval "$item='`cat config.out`'"
  186. ;;
  187. 1|255) return 0 ;;
  188. 2) echo "No help." ; sleep 1 ;;
  189. *) echo "unknown returncode: $?" ; exit 1 ;;
  190. esac
  191. }
  192. text() {
  193. local q="'"
  194. set_data "$2" "$3"
  195. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  196. echo -e "$2\ttext_action '$1' '$2'" \
  197. "'${data//$q/$q\\$q$q}'" >> config.data
  198. fi
  199. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  200. xdata="$( printf "%-${tabspace}s" \
  201. "$(echo $data | cut -c1-20)")"
  202. if [ "$menumode" -eq 1 ] ; then xdata="($xdata)"
  203. else xdata="=$xdata=" ; fi
  204. printf "'$2' '$spacer%s $1'\n" \
  205. "${xdata//$q/$q\\$q$q}" >> config.dialog
  206. # If you do not know what mighty esden
  207. # is doin here see comment()
  208. if [ "$4" != "" ] ; then
  209. set_help "$2" "$4"
  210. fi
  211. fi
  212. }
  213. text_action() {
  214. ./src/rockdialog.bin --title 'Build Config' \
  215. --backtitle "$configtitle" \
  216. --inputbox "$1" 9 $(( $columns - 5 )) "$3" 2> config.out
  217. [ "$?" -eq 0 -o "$?" -eq 1 ] && eval "$2=\"\$(cat config.out)\""
  218. }
  219. bool() {
  220. local x
  221. set_data "$2" "$3"
  222. if [ "$menumode" -eq 1 -a $menu_current = $menu_this ] ; then
  223. echo -e "$2\tbool_action '$1' '$2' '$data'" >> config.data
  224. fi
  225. if [ "$menumode" -gt 0 -a $menu_current = $menu_this ] ; then
  226. if [ "$menumode" -eq 1 ] ; then
  227. if [ $data -eq 0 ] ; then x='[ ]' ; else x='[*]' ; fi
  228. else
  229. if [ $data -eq 0 ] ; then x='= =' ; else x='=*=' ; fi
  230. fi
  231. printf "$2 '$spacer%-${tabspace}s ${1//_/ }'\n" \
  232. "$x" >> config.dialog
  233. # If you do not know what mighty esden is doin here see comment()
  234. if [ "$4" != "" ] ; then
  235. set_help "$2" "$4"
  236. fi
  237. fi
  238. }
  239. bool_action() {
  240. if [ $3 -eq 0 ] ; then eval "$2=1"
  241. else eval "$2=0" ; fi
  242. }
  243. editfile() {
  244. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] ; then
  245. local x="$spacer" q="'"
  246. comment ",----< $3 >----."
  247. block_begin 0 ; spacer="${spacer%??}| "
  248. touch "$2"
  249. line_nr=1
  250. while read line ; do
  251. line="${line//$q/$q\\$q$q}"
  252. if [ $menu_current = $menu_this ] ; then
  253. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  254. `printf "%03d:" $line_nr` "$line" >> config.dialog
  255. echo -e "$1:${editfilenr}\teditfile_action $2" \
  256. "$line_nr '$3'" >> config.data
  257. fi
  258. editfilenr=$(( $editfilenr + 1 ))
  259. line_nr=$(( $line_nr + 1 ))
  260. done < "$2"
  261. if [ $menu_current = $menu_this ] ; then
  262. printf "$1:${editfilenr} '$spacer%-${tabspace}s %s'\n" \
  263. `printf "%03d:" $line_nr` "<add new rule>" >> config.dialog
  264. echo -e "$1:${editfilenr}\teditfile_action $2" \
  265. "$line_nr '$3'" >> config.data
  266. fi
  267. editfilenr=$(( $editfilenr + 1 ))
  268. block_end
  269. comment "\`------${3//?/-}------'\''"
  270. spacer="$x"
  271. else
  272. rm -f "$2"
  273. fi
  274. }
  275. editfile_action() {
  276. line="`tail -n +$2 $1 | head -n 1`"
  277. ./src/rockdialog.bin --title 'Build Config' \
  278. --backtitle "$configtitle" \
  279. --inputbox "$3 - Line $3" \
  280. 9 $(( $columns - 5 )) "$line" 2> config.out
  281. head -n $(( $2 - 1 )) $1 > $1.new
  282. [ -s config.out ] && echo "`cat config.out`" >> $1.new
  283. tail -n +$(( $2 + 1 )) $1 >> $1.new
  284. mv $1.new $1
  285. }
  286. startprog() {
  287. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  288. [ $menu_current = $menu_this ] ; then
  289. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  290. "-->" "$2" >> config.dialog
  291. echo -e "$1\t$3" >> config.data
  292. fi
  293. }
  294. block_begin() {
  295. if [ $menu_current = $menu_this ] ; then
  296. [ "$tabspace_list" ] && spacer="$spacer "
  297. tabspace_list="$tabspace $tabspace_list"
  298. tabspace="$(( $tabspace + $1 - 2 ))"
  299. fi
  300. }
  301. block_end() {
  302. if [ $menu_current = $menu_this ] ; then
  303. spacer="`echo "$spacer" | sed 's,..$,,'`" ;
  304. tabspace="`echo $tabspace_list | cut -f1 -d' '`"
  305. tabspace_list="`echo $tabspace_list | cut -s -f2- -d' '`"
  306. fi
  307. }
  308. expert_begin() {
  309. expert=$(( $exprt + 1 ))
  310. }
  311. expert_end() {
  312. expert=$(( $exprt - 1 ))
  313. }
  314. menu_begin() {
  315. menu_counter=$(( $menu_counter + 1 ))
  316. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  317. [ $menu_current = $menu_this ] ; then
  318. printf "$1 '$spacer%-${tabspace}s %s'\n" \
  319. "===>" "$2" >> config.dialog
  320. echo -e "$1\tmenu_current=$menu_counter" >> config.data
  321. fi
  322. if [ $ROCKCFG_EXPERT -eq 1 -o $expert -eq 0 ] &&
  323. [ $menu_current = $menu_counter ] ; then
  324. echo "$1 '===> $2'" >> config.dialog
  325. echo -e "$1\tmenu_current=$menu_this" >> config.data
  326. fi
  327. if [ $menu_current = $menu_counter ] ; then
  328. menu_back=$menu_this
  329. menu_backpos=$1
  330. fi
  331. menu_stack="$menu_this $menu_stack"
  332. menu_this=$menu_counter
  333. block_begin 3
  334. }
  335. menu_end() {
  336. block_end
  337. menu_this="`echo $menu_stack | cut -f1 -d' '`"
  338. menu_stack="`echo $menu_stack | cut -s -f2- -d' '`"
  339. }
  340. get_help() {
  341. # Create standard help output ...
  342. default_text="
  343. There is no help on '$1' available.
  344. This is the ROCK Linux $rockver Configuration Tool.
  345. Please read the build Documentation (Documentation/BUILD)
  346. and the ROCK Linux Guide (Documentation/Guide/GUIDE.txt)
  347. before building ROCK Linux.
  348. More information can be found on the ROCK Linux Homepage:
  349. http://www.rocklinux.org/
  350. Subscribe to the mailing list by sending an e-mail with the
  351. subject 'subscribe rock-linux' to <minimalist@rocklinux.org>."
  352. # Ok let us find a help for the current item ...
  353. # First of all mask all special chars in the item name
  354. # Comment: this is sick. You can't get any \n this way !!!
  355. item_name=$( echo "$1" | sed 's/[][\/.^$*]/\\&/g' )
  356. # Now search *.hlp files
  357. hlp_text=$( sed -n "/^$item_name[ ]*\$/,\${
  358. /^$item_name[ ]*\$/c\\
  359. $item_name:\\
  360. /^#/d
  361. /^[^ ]/q
  362. s/^ //
  363. p
  364. }" scripts/config*.hlp package/*/*/subconfig-*.hlp package/*/*/config*.hlp target/*/config*.hlp misc/config/config*.hlp 2>/dev/null )
  365. # Get help strings out of the temporary file.
  366. tmp_text=$(grep "^$item_name" config.help | cut -f2- -d' ' | sed -e "s,^',," -e "s,'$,," )
  367. # Let us see what we have ...
  368. if [ "$hlp_text" -a "$tmp_text" ] ; then
  369. echo "
  370. There are two help text's... one in one of the config.in files and one
  371. in one of the config.hlp files. Please remove one of them to get rid of
  372. this message here.
  373. Here the one out of config.in:
  374. $tmp_text
  375. Here the one out of config.hlp:
  376. $hlp_text"
  377. elif [ "$hlp_text" ] ; then
  378. echo "$hlp_text"
  379. elif [ "$tmp_text" ] ; then
  380. echo "$tmp_text"
  381. else
  382. echo "$default_text"
  383. fi
  384. }
  385. arch=none
  386. if expr "`uname -m`" : "i.86" > /dev/null ; then arch=x86 ; fi
  387. if expr "`uname -m`" : "alpha" > /dev/null ; then arch=alpha ; fi
  388. if expr "`uname -m`" : "ppc" > /dev/null ; then arch=powerpc ; fi
  389. if expr "`uname -m`" : "powerpc" > /dev/null ; then arch=powerpc ; fi
  390. current="" ; export ROCKCFG_ARCH="$arch" ; export ROCKCFG_EXPERT=0
  391. menu_this=0 ; menu_current=0 ; menu_counter=0
  392. menu_stack=-1 ; menu_back=-1 ; menu_backpos=-1
  393. mkdir -p config/$config
  394. touch config/$config/config config/$config/packages
  395. configtitle="$(printf ' %-50s %6s active packages ]' \
  396. "ROCK Linux $rockver Configuration - $config" \
  397. "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
  398. . ./config/$config/config
  399. rm -f config.dialog config.data config.help
  400. touch config.dialog config.data config.help
  401. echo -e "#\n# ROCK Linux $rockver Config File\n#" > config/$config/config
  402. spacer="" ; expert=0 ; tabspace="5" ; tabspace_list=""
  403. commentnr=0 ; editfilenr=0
  404. cmd="./scripts/Create-PkgList"
  405. [ "$ROCKCFG_DISABLE_BROKEN" = 1 ] && cmd="$cmd -nobroken"
  406. cmd="$cmd $ROCKCFG_ARCH"
  407. if [ "$cmd" != "`cat config.pcache.cmd 2> /dev/null`" ] ; then
  408. eval "$cmd" | tee config.pcache.data > config/$config/packages
  409. echo "$cmd" > config.pcache.cmd
  410. else
  411. cat config.pcache.data > config/$config/packages
  412. fi
  413. export ROCKCFG_ID="$rockver" ; . src/rockconfig.in
  414. echo "export ROCKCFG_ID='$ROCKCFG_ID'" >> config/$config/config
  415. cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \
  416. tr ' ' '\t' | expand -t2,15,35, > config/$config/packages.txt
  417. configtitle="$(printf ' %-50s %6s active packages ]' \
  418. "ROCK Linux $rockver Configuration - $config" \
  419. "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
  420. if [ -z "$oldconfig" ] ; then
  421. eval "./src/rockdialog.bin --title 'Build Config' \
  422. --backtitle '$configtitle' \
  423. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  424. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  425. '$current' `tr '\n' ' ' < config.dialog`" 2> config.out
  426. returncode=$? ; item="`cat config.out`"
  427. else
  428. returncode=1
  429. fi
  430. [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
  431. case "$returncode" in
  432. 0|6)
  433. command="`grep "^$item " config.data | cut -f2-`"
  434. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  435. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  436. echo -e "\n# Execute this config command:\n$command"
  437. } >> config/$config/config
  438. ;;
  439. menu-back)
  440. { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
  441. echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
  442. } >> config/$config/config
  443. ;;
  444. 1|255)
  445. rm -f config.data config.dialog config.out config.help
  446. rm -f config.pcache.data config.pcache.cmd
  447. rm -f rockdialog.scrltmp # src/rockdialog.bin
  448. echo "New config written to config/$config/*."
  449. echo "Cleaning up. Configuration finished."
  450. exit 1 ;;
  451. 2)
  452. tempitem=$item
  453. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  454. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  455. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  456. } >> config/$config/config
  457. get_help $item > config.dialog
  458. ./src/rockdialog.bin --title 'ROCK Linux Config - Help' \
  459. --backtitle "ROCK Linux $rockver Configuration" \
  460. --textbox config.dialog \
  461. $(( $lines - 4 )) $(( $columns - 5 ))
  462. ;;
  463. *)
  464. echo "unknown returncode: $returncode"
  465. exit 1 ;;
  466. esac
  467. exit 0