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.

314 lines
8.6 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. rm -f config.profile
  105. enable -f src/bash_profiler.so bprof || exit 1
  106. bprof_print() {
  107. { echo "--- `date` ---"; bprof all print | sort -k2; } >> config.profile
  108. }
  109. fi
  110. bprof main start
  111. echo "Running ROCK Linux $rockver configuration ..."
  112. if [ ! -e config/$config ] ; then
  113. mkdir -p config/$config
  114. echo "Creating new configuration $config ..."
  115. $0 -oldconfig $profile $nobashmod -cfg $config
  116. fi
  117. # From scripts/parse-config
  118. base=$(pwd -P)
  119. . scripts/functions
  120. . scripts/config.func
  121. mkdir -p config/$config
  122. touch config/$config/{config{,_usr},packages}
  123. rm -rf $swpdir
  124. cp -r config/$config $swpdir
  125. current=""
  126. menu_this=0 ; menu_current=0 ; menu_stack=x
  127. include ()
  128. {
  129. local x
  130. for x in $@ ; do
  131. [ -f "$x" ] && . "./$x"
  132. done
  133. }
  134. arch=none
  135. if expr "`uname -m`" : "x86_64" > /dev/null ; then arch=x86 ; fi
  136. if expr "`uname -m`" : "i.86" > /dev/null ; then arch=x86 ; fi
  137. if expr "`uname -m`" : "alpha" > /dev/null ; then arch=alpha ; fi
  138. if expr "`uname -m`" : "ppc" > /dev/null ; then arch=powerpc ; fi
  139. if expr "`uname -m`" : "powerpc" > /dev/null ; then arch=powerpc ; fi
  140. if expr "`uname -m`" : "sparc" > /dev/null ; then arch=sparc ; fi
  141. if expr "`uname -m`" : "mips" > /dev/null ; then arch=mips ; fi
  142. export ROCKCFG_EXPERT=0
  143. . $swpdir/config
  144. . $swpdir/config_usr
  145. old_pkg_cmd=""
  146. do_config_cycle=1
  147. recreate_packages=1
  148. while [ "$do_config_cycle" == 1 ] ; do
  149. pkg_cmd="$ROCKCFG_ARCH"
  150. [ "$ROCKCFG_DISABLE_BROKEN" = 1 ] && pkg_cmd="${pkg_cmd} -nobroken"
  151. pkg_cache="$swpdir/config.pcache.${pkg_cmd// }"
  152. if [ "$old_pkg_cmd" != "$pkg_cmd" ] ; then
  153. recreate_packages=1
  154. fi
  155. if [ "$recreate_packages" == 1 ] ; then
  156. recreate_packages=0
  157. if [ -f "$pkg_cache" ] ; then
  158. cp -a "$pkg_cache" "$swpdir/packages"
  159. pkgin
  160. else
  161. eval "./scripts/Create-PkgList $pkg_cmd" \
  162. > $swpdir/packages
  163. cp -a "$swpdir/packages" "$pkg_cache"
  164. fi
  165. old_pkg_cmd="$pkg_cmd"
  166. else
  167. cp -a "$pkg_cache" "$swpdir/packages"
  168. fi
  169. pkgin
  170. rm -f $swpdir/config.{dialog,data,help}{,.*}
  171. config_cycle
  172. bprof main stop
  173. bprof rockconfig start
  174. . scripts/config.in
  175. bprof rockconfig stop
  176. bprof main start
  177. pkgout
  178. configtitle="$(printf ' %-50s %6s active packages ]' \
  179. "ROCK Linux $rockver Configuration - $config" \
  180. "[ $(echo `grep '^X' $swpdir/packages | wc -l`)" )"
  181. do_dialog_cycle=1
  182. while [ "$do_dialog_cycle" = 1 ] ; do
  183. if [ -z "$oldconfig" ] ; then
  184. bprof main stop
  185. bprof rockdialog start
  186. eval "./src/rockdialog.bin --title 'Build Config' \
  187. --backtitle '$configtitle' \
  188. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  189. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  190. '$current' `tr '\n' ' ' \
  191. < $swpdir/config.dialog.$menu_current`" \
  192. 2> $swpdir/config.out
  193. returncode=$? ; item="`cat $swpdir/config.out`"
  194. bprof rockdialog stop
  195. bprof main start
  196. else
  197. returncode=1
  198. fi
  199. [ "$returncode" = 1 -a "$menu_current" -ne 0 ] && returncode="menu-back"
  200. case "$returncode" in
  201. 0|6)
  202. command="`grep "^$item " \
  203. $swpdir/config.data.$menu_current | cut -f2-`"
  204. if [[ "$command" != menu_current=* ]] ; then
  205. [ -n "$command" ] && do_dialog_cycle=0
  206. current="$item"
  207. fi
  208. eval "$command"
  209. ;;
  210. menu-back)
  211. command="`grep "^MENU_BACK " \
  212. $swpdir/config.data.$menu_current | cut -f2-`"
  213. eval "$command"
  214. ;;
  215. 1|255)
  216. do_dialog_cycle=0
  217. do_config_cycle=0
  218. rm -f $swpdir/config.{data,dialog,out,help}{,.*}
  219. rm -f $swpdir/config.pcache.*
  220. rm -f rockdialog.scrltmp # src/rockdialog.bin
  221. echo "New config written to config/$config/*."
  222. echo "Cleaning up. Configuration finished."
  223. ;;
  224. 2)
  225. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  226. current="$item"
  227. get_help $item > $swpdir/config.dialog
  228. bprof main stop
  229. ./src/rockdialog.bin --title 'ROCK Linux Config - Help' \
  230. --backtitle "ROCK Linux $rockver Configuration" \
  231. --textbox $swpdir/config.dialog \
  232. $(( $lines - 4 )) $(( $columns - 5 ))
  233. bprof main start
  234. ;;
  235. *)
  236. do_dialog_cycle=0
  237. do_config_cycle=0
  238. echo "unknown returncode: $returncode"
  239. ;;
  240. esac
  241. done
  242. bprof main stop
  243. done
  244. bprof finish start
  245. pkgout
  246. rm -f $swpdir/*.tmp
  247. echo -e "#\n# ROCK Linux $rockver Config File\n#\n" \
  248. > $swpdir/config
  249. echo -e "#\n# ROCK Linux $rockver User Config File\n#" \
  250. > $swpdir/config_usr
  251. for x in ${!ROCKCFG_*}; do
  252. echo "export ${x}='${!x}'"
  253. done >> $swpdir/config
  254. for x in ${!ROCKCFGUSR_*}; do
  255. echo "${x}='${!x}'"
  256. done >> $swpdir/config_usr
  257. sort -k1,1r -k3,3 $swpdir/packages > $swpdir/packages.sorted
  258. mv -f $swpdir/packages{.sorted,}
  259. for x in $( ls $swpdir/ ); do
  260. cp $swpdir/{$x,__tmp}
  261. mv $swpdir/__tmp config/$config/$x
  262. done
  263. for x in $( ls config/$config ); do
  264. [ -e $swpdir/$x ] || rm -f config/$config/$x
  265. done
  266. rm -rf $swpdir
  267. bprof finish stop
  268. bprof_print