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.

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