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