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.

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