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.

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