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.

317 lines
8.8 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 - 2006 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. ./scripts/Check-System || exit 1
  70. if [ $delete_mode = 1 ] ; then
  71. rm -rv config/$config
  72. exit $?
  73. fi
  74. # hook for third-party targets that need to insert additional packages before config runs, for example.
  75. # for precnf in target/*/preconfig.sh ; do
  76. # [ -f $precnf ] && . $precnf
  77. # done
  78. swpid=swp$$
  79. swpdir="config/$config.$swpid"
  80. rm -f rockdialog.scrltmp # src/rockdialog.bin
  81. mkdir -p src
  82. if [ -z "$oldconfig" -a ! -f src/rockdialog.bin ] ; then
  83. echo "Creating rockdialog tool."
  84. command="gcc misc/rockdialog/*.c `
  85. `-Imisc/rockdialog -lncurses -o src/rockdialog.bin"
  86. eval "$command.$swpid"
  87. mv src/rockdialog.bin{.$swpid,}
  88. fi
  89. if [ -z "$nobashmod" ]; then
  90. if [ ! -f src/config_helper.so -o misc/tools-source/config_helper.c -nt src/config_helper.so ]; then
  91. echo "Building src/config_helper.so."
  92. gcc -shared -fPIC -Wall -o src/config_helper.so misc/tools-source/config_helper.c || exit 1
  93. fi
  94. enable -f src/config_helper.so cfghlp || exit 1
  95. fi
  96. if [ -z "$profile" ]; then
  97. bprof() { :; }
  98. bprof_print() { :; }
  99. else
  100. if [ ! -f src/bash_profiler.so -o misc/tools-source/bash_profiler.c -nt src/bash_profiler.so ]; then
  101. echo "Building src/bash_profiler.so."
  102. gcc -shared -fPIC -Wall -o src/bash_profiler.so misc/tools-source/bash_profiler.c || exit 1
  103. fi
  104. enable -f src/bash_profiler.so bprof || exit 1
  105. bprof_print() {
  106. bprof all print >> config.profile
  107. awk '
  108. $4 == "profiled" { next; }
  109. $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
  110. { count[$4]+=$1; time[$4]+=$2; }
  111. END {
  112. for (id in count)
  113. printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
  114. }
  115. ' < config.profile | sort -n -k2 > config.profile.new
  116. mv config.profile{.new,}
  117. }
  118. fi
  119. bprof main start
  120. echo "Running ROCK Linux $rockver configuration ..."
  121. if [ ! -e config/$config ] ; then
  122. mkdir -p config/$config
  123. echo "Creating new configuration $config ..."
  124. $0 -oldconfig $profile $nobashmod -cfg $config
  125. fi
  126. # From scripts/parse-config
  127. base=$(pwd -P)
  128. . scripts/functions
  129. . scripts/config.func
  130. mkdir -p config/$config
  131. touch config/$config/{config{,_usr},packages}
  132. rm -rf $swpdir
  133. cp -r config/$config $swpdir
  134. current=""
  135. menu_this=0 ; menu_current=0 ; menu_stack=x
  136. include ()
  137. {
  138. local x
  139. for x in $@ ; do
  140. [ -f "$x" ] && . "./$x"
  141. done
  142. }
  143. arch=none
  144. if expr "`uname -m`" : "x86_64" > /dev/null ; then arch=x86 ; fi
  145. if expr "`uname -m`" : "i.86" > /dev/null ; then arch=x86 ; fi
  146. if expr "`uname -m`" : "alpha" > /dev/null ; then arch=alpha ; fi
  147. if expr "`uname -m`" : "ppc" > /dev/null ; then arch=powerpc ; fi
  148. if expr "`uname -m`" : "powerpc" > /dev/null ; then arch=powerpc ; fi
  149. if expr "`uname -m`" : "sparc" > /dev/null ; then arch=sparc ; fi
  150. if expr "`uname -m`" : "mips" > /dev/null ; then arch=mips ; fi
  151. export ROCKCFG_EXPERT=0
  152. . $swpdir/config
  153. . $swpdir/config_usr
  154. old_pkg_cmd=""
  155. do_config_cycle=1
  156. recreate_packages=1
  157. while [ "$do_config_cycle" == 1 ] ; do
  158. pkg_cmd="$ROCKCFG_ARCH"
  159. [ "$ROCKCFG_DISABLE_BROKEN" = 1 ] && pkg_cmd="${pkg_cmd} -nobroken"
  160. pkg_cache="$swpdir/config.pcache.${pkg_cmd// }"
  161. if [ "$old_pkg_cmd" != "$pkg_cmd" ] ; then
  162. recreate_packages=1
  163. fi
  164. if [ "$recreate_packages" == 1 ] ; then
  165. recreate_packages=0
  166. if [ -f "$pkg_cache" ] ; then
  167. cp -a "$pkg_cache" "$swpdir/packages"
  168. pkgin
  169. else
  170. eval "./scripts/Create-PkgList $pkg_cmd" \
  171. > $swpdir/packages
  172. cp -a "$swpdir/packages" "$pkg_cache"
  173. fi
  174. old_pkg_cmd="$pkg_cmd"
  175. else
  176. cp -a "$pkg_cache" "$swpdir/packages"
  177. fi
  178. pkgin
  179. rm -f $swpdir/config.{dialog,data,help}{,.*}
  180. config_cycle
  181. bprof main stop
  182. bprof rockconfig start
  183. . scripts/config.in
  184. bprof rockconfig stop
  185. bprof main start
  186. pkgout
  187. configtitle="$(printf ' %-50s %6s active packages ]' \
  188. "ROCK Linux $rockver Configuration - $config" \
  189. "[ $(echo `grep '^X' $swpdir/packages | wc -l`)" )"
  190. do_dialog_cycle=1
  191. while [ "$do_dialog_cycle" = 1 ] ; do
  192. if [ -z "$oldconfig" ] ; then
  193. bprof main stop
  194. bprof rockdialog start
  195. eval "./src/rockdialog.bin --title 'Build Config' \
  196. --backtitle '$configtitle' \
  197. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  198. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  199. '$current' `tr '\n' ' ' \
  200. < $swpdir/config.dialog.$menu_current`" \
  201. 2> $swpdir/config.out
  202. returncode=$? ; item="`cat $swpdir/config.out`"
  203. bprof rockdialog stop
  204. bprof main start
  205. else
  206. returncode=1
  207. fi
  208. [ "$returncode" = 1 -a "$menu_current" -ne 0 ] && returncode="menu-back"
  209. case "$returncode" in
  210. 0|6)
  211. command="`grep "^$item " \
  212. $swpdir/config.data.$menu_current | cut -f2-`"
  213. if [[ "$command" != menu_current=* ]] ; then
  214. [ -n "$command" ] && do_dialog_cycle=0
  215. current="$item"
  216. fi
  217. eval "$command"
  218. ;;
  219. menu-back)
  220. command="`grep "^MENU_BACK " \
  221. $swpdir/config.data.$menu_current | cut -f2-`"
  222. eval "$command"
  223. ;;
  224. 1|255)
  225. do_dialog_cycle=0
  226. do_config_cycle=0
  227. rm -f $swpdir/config.{data,dialog,out,help}{,.*}
  228. rm -f $swpdir/config.pcache.*
  229. rm -f rockdialog.scrltmp # src/rockdialog.bin
  230. echo "New config written to config/$config/*."
  231. echo "Cleaning up. Configuration finished."
  232. ;;
  233. 2)
  234. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  235. current="$item"
  236. get_help $item > $swpdir/config.dialog
  237. bprof main stop
  238. ./src/rockdialog.bin --title 'ROCK Linux Config - Help' \
  239. --backtitle "ROCK Linux $rockver Configuration" \
  240. --textbox $swpdir/config.dialog \
  241. $(( $lines - 4 )) $(( $columns - 5 ))
  242. bprof main start
  243. ;;
  244. *)
  245. do_dialog_cycle=0
  246. do_config_cycle=0
  247. echo "unknown returncode: $returncode"
  248. ;;
  249. esac
  250. done
  251. bprof main stop
  252. bprof_print
  253. done
  254. pkgout
  255. rm -f $swpdir/*.tmp
  256. echo -e "#\n# ROCK Linux $rockver Config File\n#\n" \
  257. > $swpdir/config
  258. echo -e "#\n# ROCK Linux $rockver User Config File\n#" \
  259. > $swpdir/config_usr
  260. for x in ${!ROCKCFG_*}; do
  261. echo "export ${x}='${!x}'"
  262. done >> $swpdir/config
  263. for x in ${!ROCKCFGUSR_*}; do
  264. echo "${x}='${!x}'"
  265. done >> $swpdir/config_usr
  266. sort -k1,1r -k3,3 $swpdir/packages > $swpdir/packages.sorted
  267. mv -f $swpdir/packages{.sorted,}
  268. for x in $( ls $swpdir/ ); do
  269. cp $swpdir/{$x,__tmp}
  270. mv $swpdir/__tmp config/$config/$x
  271. done
  272. for x in $( ls config/$config ); do
  273. [ -e $swpdir/$x ] || rm -f config/$config/$x
  274. done
  275. rm -rf $swpdir