OpenSDE Framework (without history before r20070)
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.

283 lines
7.7 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Config
  6. # Copyright (C) 2006 - 2010 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ] ; then
  18. if [ "$( type -p stty )" ] ; then
  19. lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
  20. columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
  21. fi
  22. [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
  23. [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
  24. fi
  25. . "lib/libsde.in"
  26. config=default
  27. do_config_cycle=0
  28. delete_mode=0
  29. oldconfig=
  30. nobashmod=
  31. cfgtmpdir=
  32. profile=
  33. show_usage() {
  34. echo
  35. echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
  36. echo
  37. echo "Other options:"
  38. echo " -profile create a config.profile with profiling data"
  39. echo " -nobashmod don't use the bash config helper plugin"
  40. echo
  41. }
  42. while [ "$1" ] ; do
  43. case "$1" in
  44. -cycle) do_config_cycle=1 ; shift ;;
  45. -delete) delete_mode=1 ; shift ;;
  46. -profile) profile='-profile' ; shift ;;
  47. -oldconfig) oldconfig='-oldconfig' ; shift ;;
  48. -nobashmod) nobashmod='-nobashmod' ; shift ;;
  49. -cfg) config="$2" ; shift ; shift ;;
  50. *) show_usage
  51. exit 1 ;;
  52. esac
  53. done
  54. if [ -z "$config" ]; then
  55. show_usage
  56. exit 1
  57. fi
  58. if [ ! -d config/$config -a -n "$oldconfig" ]; then
  59. echo "Abort: -oldconfig is not supported for new configs"
  60. echo
  61. exit 1
  62. fi
  63. if [ $delete_mode = 1 ] ; then
  64. rm -rv config/$config
  65. exit $?
  66. fi
  67. cfgtmpdir=tmp/$config
  68. if [ $do_config_cycle = 0 ] ; then
  69. rm -rf $cfgtmpdir
  70. mkdir -p $cfgtmpdir # src
  71. if [ -z "$oldconfig" -a ! -f tmp/confdialog.bin ] ; then
  72. echo "Creating confdialog tool."
  73. command="gcc src/confdialog/*.c `
  74. `-Isrc/confdialog -lncurses -o tmp/confdialog.bin"
  75. set -e
  76. echo "$command" ; eval "$command.$$"
  77. mv tmp/confdialog.bin.$$ tmp/confdialog.bin
  78. set +e
  79. fi
  80. # don't accept Ctrl-C because it destroy the configurations
  81. trap '' INT
  82. if [ -d "config/$config" ]; then
  83. if ./lib/sde-config/migrate.sh "$config"; then
  84. mkdir -p $cfgtmpdir/config/
  85. cp -a config/$config/* $cfgtmpdir/config/
  86. if [ $? -ne 0 ]; then
  87. echo "Copy of config failed, aborting."
  88. exit 1
  89. fi
  90. fi
  91. fi
  92. echo "Starting OpenSDE ($sdever) configuration ..."
  93. while "$0" -cfg $config $oldconfig $profile $nobashmod -cycle ; do : ; done
  94. trap INT
  95. exit 0
  96. fi
  97. if [ -z "$nobashmod" ]; then
  98. if [ ! -f tmp/config_helper.so -o src/tools-source/config_helper.c -nt tmp/config_helper.so ]; then
  99. echo "Building tmp/config_helper.so."
  100. gcc -shared -fPIC -Wall -o tmp/config_helper.so src/tools-source/config_helper.c || exit 1
  101. fi
  102. enable -f tmp/config_helper.so cfghlp || exit 1
  103. fi
  104. if [ -z "$profile" ]; then
  105. bprof() { :; }
  106. bprof_print() { :; }
  107. else
  108. if [ ! -f tmp/bash_profiler.so -o src/tools-source/bash_profiler.c -nt tmp/bash_profiler.so ]; then
  109. echo "Building tmp/bash_profiler.so."
  110. gcc -shared -fPIC -Wall -o tmp/bash_profiler.so src/tools-source/bash_profiler.c || exit 1
  111. fi
  112. enable -f tmp/bash_profiler.so bprof || exit 1
  113. bprof_print() {
  114. local cprof=$cfgtmpdir/config.profile
  115. bprof all print >> $cprof
  116. awk '
  117. $4 == "profiled" { next; }
  118. $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
  119. { count[$4]+=$1; time[$4]+=$2; }
  120. END {
  121. for (id in count)
  122. printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
  123. }
  124. ' < $cprof | sort -n -k2 > $cprof.new
  125. mv $cprof.net $cprof
  126. }
  127. fi
  128. bprof main start
  129. . lib/sde-config/functions.in
  130. arch=`uname -m | uname2arch`
  131. current= ; export SDECFG_ARCH="$arch" ; export SDECFG_EXPERT=0
  132. menu_this=0 ; menu_current=0 ; menu_counter=0
  133. menu_stack=x ; menu_back=-1 ; menu_backpos=-1
  134. set -e
  135. mkdir -p $cfgtmpdir/config
  136. touch $cfgtmpdir/config/{config,packages}
  137. set +e
  138. configtitle="$(printf ' %-50s %6s active packages ]' \
  139. "OpenSDE ($sdever) Configuration - $config" \
  140. "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
  141. bprof main stop
  142. . $cfgtmpdir/config/config
  143. bprof main start
  144. rm -f $cfgtmpdir/config.{dialog,data,help}
  145. touch $cfgtmpdir/config.{dialog,data,help}
  146. $ECHO_E "#\n# OpenSDE ($sdever) Config File\n#" > $cfgtmpdir/config/config
  147. spacer= ; expert=0 ; tabspace="5" ; tabspace_list=
  148. commentnr=0 ; editfilenr=0
  149. bprof mkpkglist start
  150. cmd="./bin/sde-list package --arch '$SDECFG_ARCH'"
  151. if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ] ; then
  152. eval "$cmd" | tee $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
  153. echo "$cmd" > $cfgtmpdir/config.pcache.cmd
  154. else
  155. cat $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
  156. fi
  157. bprof mkpkglist stop
  158. # Create lists of .in files
  159. create_dot_in_lists
  160. export SDECFG_ID="$sdever"; pkgin; . lib/sde-config/main.in; pkgout
  161. echo "export SDECFG_ID='$SDECFG_ID'" >> $cfgtmpdir/config/config
  162. rm -f $cfgtmpdir/*.tmp
  163. cut -f1,2,4,5,8- -d' ' $cfgtmpdir/config/packages | sed 's, [^ ]*$,,' | \
  164. tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
  165. configtitle="$(printf ' %-50s %6s active packages ]' \
  166. "OpenSDE ($sdever) Configuration - $config" \
  167. "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
  168. bprof main stop
  169. if [ -z "$oldconfig" ] ; then
  170. eval "./tmp/confdialog.bin --title 'Build Config' \
  171. --backtitle '$configtitle' \
  172. --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
  173. $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
  174. '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
  175. returncode=$? ; item="`cat $cfgtmpdir/config.out`"
  176. else
  177. returncode=1
  178. fi
  179. bprof main start
  180. [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
  181. case "$returncode" in
  182. 0|6)
  183. command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
  184. { $ECHO_E "\n# Remember menu position:\ncurrent='$item'"
  185. $ECHO_E "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  186. $ECHO_E "\n# Execute this config command:\n$command"
  187. } >> $cfgtmpdir/config/config
  188. ;;
  189. menu-back)
  190. { $ECHO_E "\n# New menu position:\ncurrent='$menu_backpos'"
  191. $ECHO_E "\n# New sub-menu:\nmenu_current='$menu_back'"
  192. } >> $cfgtmpdir/config/config
  193. ;;
  194. 1|255)
  195. mkdir -p config/$config
  196. # sync
  197. # TODO: make this nicer, but still sudo-friendly
  198. for x in config/$config/*; do
  199. y="$cfgtmpdir/config/${x##*/}"
  200. if [ ! -e "$y" ]; then
  201. rm -f "$x"
  202. else
  203. # to not change the permissions (sudo-friendliness)
  204. cat "$y" > "$x"
  205. rm -f "$y"
  206. fi
  207. done
  208. for y in "$cfgtmpdir/config"/* ; do 2> /dev/null
  209. if [ -e "$y" ]; then
  210. cp -a "$y" config/$config/
  211. rm -f "$y"
  212. fi
  213. done
  214. rmdir $cfgtmpdir/config && rm -rf $cfgtmpdir/
  215. echo "New config written to config/$config/*."
  216. echo "Cleaning up. Configuration finished."
  217. bprof main stop
  218. bprof_print
  219. exit 1 ;;
  220. 2)
  221. tempitem=$item
  222. item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
  223. { $ECHO_E "\n# Remember menu position:\ncurrent='$item'"
  224. $ECHO_E "\n# Remember sub-menu:\nmenu_current='$menu_current'"
  225. } >> $cfgtmpdir/config/config
  226. get_help $item > $cfgtmpdir/config.dialog
  227. bprof main stop
  228. ./tmp/confdialog.bin --title 'OpenSDE Config - Help' \
  229. --backtitle "OpenSDE ($sdever) Configuration" \
  230. --textbox $cfgtmpdir/config.dialog \
  231. $(( $lines - 4 )) $(( $columns - 5 ))
  232. bprof main start
  233. ;;
  234. *)
  235. echo "unknown returncode: $returncode"
  236. bprof main stop
  237. bprof_print
  238. exit 1 ;;
  239. esac
  240. bprof main stop
  241. bprof_print
  242. exit 0