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.

293 lines
8.9 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. nobashmod=''
  38. profile=""
  39. while [ "$1" ] ; do
  40. case "$1" in
  41. -cycle) do_config_cycle=1 ; shift ;;
  42. -delete) delete_mode=1 ; shift ;;
  43. -profile) profile='-profile' ; shift ;;
  44. -oldconfig) oldconfig='-oldconfig' ; shift ;;
  45. -nobashmod) nobashmod='-nobashmod' ; shift ;;
  46. -cfg) config="$2" ; shift ; shift ;;
  47. *)
  48. echo
  49. echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
  50. echo " Create and modify build configurations for the other"
  51. echo " scripts, e.g. Download, Build-Target, and Emerge-Pkg."
  52. echo
  53. echo " -cfg <config> use <config> as the configuration name. If this option"
  54. echo " is not set the name 'default' is used. If no"
  55. echo " configuration by this name exists, one with default"
  56. echo " settings is created."
  57. echo " -delete delete the specified configuration"
  58. echo " -oldconfig run without a menu-based interface; changes to settings"
  59. echo " in configuration files have to be made manually before"
  60. echo " ./scripts/Config recreates the whole configuration"
  61. echo
  62. echo "Other options:"
  63. echo " -profile create a config.profile with profiling data"
  64. echo " -nobashmod don't use the bash config helper plugin"
  65. echo
  66. exit 1 ;;
  67. esac
  68. done
  69. if [ $delete_mode = 1 ] ; then
  70. rm -rv config/$config
  71. exit $?
  72. fi
  73. if [ $do_config_cycle = 0 ] ; then
  74. rm -f config.data config.dialog config.out config.help
  75. rm -f config.pcache.data config.pcache.cmd
  76. rm -f rockdialog.scrltmp # src/rockdialog.bin
  77. mkdir -p src
  78. if [ -z "$oldconfig" -a ! -f src/rockdialog.bin ] ; then
  79. echo "Creating rockdialog tool."
  80. command="gcc misc/rockdialog/*.c `
  81. `-Imisc/rockdialog -lncurses -o src/rockdialog.bin"
  82. echo "$command" ; eval "$command.$$"
  83. mv src/rockdialog.bin.$$ src/rockdialog.bin
  84. fi
  85. echo "Creating configuration script."
  86. cat << EOT > src/rockconfig.awk.$$
  87. #!/usr/bin/awk -f
  88. FNR == 1 {
  89. if ( lastfile ) {
  90. print "### END of " lastfile;
  91. }
  92. print "### BEGIN of " FILENAME;
  93. lastfile = FILENAME;
  94. }
  95. END {
  96. print "### END of " FILENAME;
  97. }
  98. \$1 == "%include" {
  99. \$1 = "awk -f src/rockconfig.awk";
  100. system(\$0);
  101. next;
  102. }
  103. \$1 == "#" { next; }
  104. { print; }
  105. EOT
  106. mv src/rockconfig.awk.$$ src/rockconfig.awk
  107. awk -f src/rockconfig.awk scripts/config.in > src/rockconfig.in.$$ 2> /dev/null
  108. mv src/rockconfig.in.$$ src/rockconfig.in
  109. echo "Running ROCK Linux $rockver configuration ..."
  110. while "$0" -cfg $config $oldconfig $profile $nobashmod -cycle ; do : ; done
  111. exit 0
  112. fi
  113. if [ -z "$nobashmod" ]; then
  114. if [ ! -f src/config_helper.so -o misc/tools-source/config_helper.c -nt src/config_helper.so ]; then
  115. echo "Building src/config_helper.so."
  116. gcc -shared -fPIC -Wall -o src/config_helper.so misc/tools-source/config_helper.c || exit 1
  117. fi
  118. enable -f src/config_helper.so cfghlp || exit 1
  119. fi
  120. if [ -z "$profile" ]; then
  121. bprof() { :; }
  122. bprof_print() { :; }
  123. else
  124. if [ ! -f src/bash_profiler.so -o misc/tools-source/bash_profiler.c -nt src/bash_profiler.so ]; then
  125. echo "Building src/bash_profiler.so."
  126. gcc -shared -fPIC -Wall -o src/bash_profiler.so misc/tools-source/bash_profiler.c || exit 1
  127. fi
  128. enable -f src/bash_profiler.so bprof || exit 1
  129. bprof_print() {
  130. bprof all print >> config.profile
  131. awk '
  132. $4 == "profiled" { next; }
  133. $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
  134. { count[$4]+=$1; time[$4]+=$2; }
  135. END {
  136. for (id in count)
  137. printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
  138. }
  139. ' < config.profile | sort -n -k2 > config.profile.new
  140. mv config.profile.new config.profile
  141. }
  142. fi
  143. bprof main start
  144. . scripts/config.func
  145. arch=none
  146. if expr "`uname -m`" : "i.86" > /dev/null ; then arch=x86 ; fi
  147. if expr "`uname -m`" : "alpha" > /dev/null ; then arch=alpha ; fi
  148. if expr "`uname -m`" : "ppc" > /dev/null ; then arch=powerpc ; fi
  149. if expr "`uname -m`" : "powerpc" > /dev/null ; then arch=powerpc ; fi
  150. current="" ; export ROCKCFG_ARCH="$arch" ; export ROCKCFG_EXPERT=0
  151. menu_this=0 ; menu_current=0 ; menu_counter=0
  152. menu_stack=x ; menu_back=-1 ; menu_backpos=-1
  153. mkdir -p config/$config
  154. touch config/$config/config
  155. touch config/$config/packages
  156. configtitle="$(printf ' %-50s %6s active packages ]' \
  157. "ROCK Linux $rockver Configuration - $config" \
  158. "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
  159. bprof main stop
  160. . ./config/$config/config
  161. if [ -f config/$config/config_usr ]; then
  162. nousrconfig=0
  163. . ./config/$config/config_usr
  164. else
  165. nousrconfig=1
  166. fi
  167. bprof main start
  168. rm -f config.dialog config.data config.help
  169. touch config.dialog config.data config.help
  170. echo -e "#\n# ROCK Linux $rockver Config File\n#" > config/$config/config
  171. echo -e "#\n# ROCK Linux $rockver User Config File\n#" > config/$config/config_usr
  172. spacer="" ; expert=0 ; tabspace="5" ; tabspace_list=""
  173. commentnr=0 ; editfilenr=0
  174. bprof mkpkglist start
  175. cmd="./scripts/Create-PkgList"
  176. [ "$ROCKCFG_DISABLE_BROKEN" = 1 ] && cmd="$cmd -nobroken"
  177. cmd="$cmd $ROCKCFG_ARCH"
  178. if [ "$cmd" != "`cat config.pcache.cmd 2> /dev/null`" ] ; then
  179. eval "$cmd" | tee config.pcache.data > config/$config/packages
  180. echo "$cmd" > config.pcache.cmd
  181. else
  182. cat config.pcache.data > config/$config/packages
  183. fi
  184. bprof mkpkglist stop
  185. export ROCKCFG_ID="$rockver"; pkgin; . src/rockconfig.in; pkgout
  186. echo "export ROCKCFG_ID='$ROCKCFG_ID'" >> config/$config/config
  187. rm -f config/$config/*.tmp
  188. cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \
  189. tr ' ' '\t' | expand -t2,15,35, > config/$config/packages.txt
  190. for x in ${!ROCKCFGUSR_*}; do
  191. eval "echo \"$x='\$$x'\""
  192. done >> config/$config/config_usr
  193. configtitle="$(printf ' %-50s %6s active packages ]' \
  194. "ROCK Linux $rockver Configuration - $config" \
  195. "[ $(echo `grep '^X' config/$config/packages | wc -l`)" )"
  196. bprof main stop
  197. if [ -z "$oldconfig" ] ; then
  198. eval "./src/rockdialog.bin --title 'Build Config' \
  199. --backtitle '$configtitle' \
  200. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  201. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  202. '$current' `tr '\n' ' ' < config.dialog`" 2> config.out
  203. returncode=$? ; item="`cat config.out`"
  204. else
  205. returncode=1
  206. fi
  207. bprof main start
  208. [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
  209. case "$returncode" in
  210. 0|6)
  211. command="`grep "^$item " config.data | cut -f2-`"
  212. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  213. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  214. echo -e "\n# Execute this config command:\n$command"
  215. } >> config/$config/config_usr
  216. ;;
  217. menu-back)
  218. { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
  219. echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
  220. } >> config/$config/config_usr
  221. ;;
  222. 1|255)
  223. rm -f config.data config.dialog config.out config.help
  224. rm -f config.pcache.data config.pcache.cmd
  225. rm -f rockdialog.scrltmp # src/rockdialog.bin
  226. echo "New config written to config/$config/*."
  227. echo "Cleaning up. Configuration finished."
  228. bprof main stop
  229. bprof_print
  230. exit 1 ;;
  231. 2)
  232. tempitem=$item
  233. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  234. { echo -e "\n# Remember menu position:\ncurrent='$item'"
  235. echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  236. } >> config/$config/config_usr
  237. get_help $item > config.dialog
  238. bprof main stop
  239. ./src/rockdialog.bin --title 'ROCK Linux Config - Help' \
  240. --backtitle "ROCK Linux $rockver Configuration" \
  241. --textbox config.dialog \
  242. $(( $lines - 4 )) $(( $columns - 5 ))
  243. bprof main start
  244. ;;
  245. *)
  246. echo "unknown returncode: $returncode"
  247. bprof main stop
  248. bprof_print
  249. exit 1 ;;
  250. esac
  251. bprof main stop
  252. bprof_print
  253. exit 0