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.

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