[initramfs] Enhanced output format to run `ldconfig` if etc/ld.so.conf is present
[opensde-nopast.git] / scripts / Config
blob1a50b1c150502b765b1cadec0aa28e3b90483035
1 #!/bin/bash
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: scripts/Config
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
7 # Copyright (C) 2004 - 2006 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 Clifford Wolf
10 # More information can be found in the files COPYING and README.
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 ---
18 if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ] ; then
19 if [ "$( type -p stty )" ] ; then
20 lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
21 columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
23 [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
24 [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
27 eval "$( egrep '^sdever=' lib/libsde.in )"
29 config=default
30 do_config_cycle=0
31 delete_mode=0
32 oldconfig=
33 nobashmod=
34 cfgtmpdir=
35 profile=
37 show_usage() {
38 echo
39 echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
40 echo
41 echo "Other options:"
42 echo " -profile create a config.profile with profiling data"
43 echo " -nobashmod don't use the bash config helper plugin"
44 echo
47 while [ "$1" ] ; do
48 case "$1" in
49 -cycle) do_config_cycle=1 ; shift ;;
50 -delete) delete_mode=1 ; shift ;;
51 -profile) profile='-profile' ; shift ;;
52 -oldconfig) oldconfig='-oldconfig' ; shift ;;
53 -nobashmod) nobashmod='-nobashmod' ; shift ;;
54 -cfg) config="$2" ; shift ; shift ;;
56 *) show_usage
57 exit 1 ;;
58 esac
59 done
61 if [ -z "$config" ]; then
62 show_usage
63 exit 1
66 if [ ! -d config/$config -a -n "$oldconfig" ]; then
67 echo "Abort: -oldconfig is not supported for new configs"
68 echo
69 exit 1
72 if [ $delete_mode = 1 ] ; then
73 rm -rv config/$config
74 exit $?
77 cfgtmpdir=tmp/$config
79 if [ $do_config_cycle = 0 ] ; then
80 rm -rf $cfgtmpdir
81 mkdir -p $cfgtmpdir # src
83 if [ -z "$oldconfig" -a ! -f tmp/confdialog.bin ] ; then
84 echo "Creating confdialog tool."
85 command="gcc src/confdialog/*.c `
86 `-Isrc/confdialog -lncurses -o tmp/confdialog.bin"
87 set -e
88 echo "$command" ; eval "$command.$$"
89 mv tmp/confdialog.bin.$$ tmp/confdialog.bin
90 set +e
93 # don't accept Ctrl-C because it destroy the configurations
94 trap '' INT
96 if [ -d "config/$config" ]; then
97 if ./lib/sde-config/migrate.sh "$config"; then
98 mkdir -p $cfgtmpdir/config/
99 cp -a config/$config/* $cfgtmpdir/config/
100 if [ $? -ne 0 ]; then
101 echo "Copy of config failed, aborting."
102 exit 1
107 echo "Starting OpenSDE ($sdever) configuration ..."
108 while "$0" -cfg $config $oldconfig $profile $nobashmod -cycle ; do : ; done
110 trap INT
112 exit 0
115 if [ -z "$nobashmod" ]; then
116 if [ ! -f tmp/config_helper.so -o src/tools-source/config_helper.c -nt tmp/config_helper.so ]; then
117 echo "Building tmp/config_helper.so."
118 gcc -shared -fPIC -Wall -o tmp/config_helper.so src/tools-source/config_helper.c || exit 1
120 enable -f tmp/config_helper.so cfghlp || exit 1
123 if [ -z "$profile" ]; then
124 bprof() { :; }
125 bprof_print() { :; }
126 else
127 if [ ! -f tmp/bash_profiler.so -o src/tools-source/bash_profiler.c -nt tmp/bash_profiler.so ]; then
128 echo "Building tmp/bash_profiler.so."
129 gcc -shared -fPIC -Wall -o tmp/bash_profiler.so src/tools-source/bash_profiler.c || exit 1
131 enable -f tmp/bash_profiler.so bprof || exit 1
132 bprof_print() {
133 local cprof=$cfgtmpdir/config.profile
134 bprof all print >> $cprof
135 awk '
136 $4 == "profiled" { next; }
137 $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
138 { count[$4]+=$1; time[$4]+=$2; }
139 END {
140 for (id in count)
141 printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
143 ' < $cprof | sort -n -k2 > $cprof.new
144 mv $cprof.net $cprof
148 bprof main start
150 . lib/sde-config/functions.in
151 arch=`uname -m | uname2arch`
152 current= ; export SDECFG_ARCH="$arch" ; export SDECFG_EXPERT=0
153 menu_this=0 ; menu_current=0 ; menu_counter=0
154 menu_stack=x ; menu_back=-1 ; menu_backpos=-1
156 set -e
157 mkdir -p $cfgtmpdir/config
158 touch $cfgtmpdir/config/{config,packages}
159 set +e
161 configtitle="$(printf ' %-50s %6s active packages ]' \
162 "The OpenSDE ($sdever) Configuration - $config" \
163 "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
165 bprof main stop
167 . $cfgtmpdir/config/config
168 bprof main start
170 rm -f $cfgtmpdir/config.{dialog,data,help}
171 touch $cfgtmpdir/config.{dialog,data,help}
172 echo -e "#\n# OpenSDE ($sdever) Config File\n#" > $cfgtmpdir/config/config
173 spacer= ; expert=0 ; tabspace="5" ; tabspace_list=
174 commentnr=0 ; editfilenr=0
176 bprof mkpkglist start
177 cmd="./bin/sde-list package --arch '$SDECFG_ARCH'"
179 if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ] ; then
180 eval "$cmd" | tee $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
181 echo "$cmd" > $cfgtmpdir/config.pcache.cmd
182 else
183 cat $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
185 bprof mkpkglist stop
187 # Create lists of .in files
188 create_dot_in_lists
190 export SDECFG_ID="$sdever"; pkgin; . lib/sde-config/main.in; pkgout
191 echo "export SDECFG_ID='$SDECFG_ID'" >> $cfgtmpdir/config/config
192 rm -f $cfgtmpdir/*.tmp
194 cut -f1,2,4,5,8- -d' ' $cfgtmpdir/config/packages | sed 's, [^ ]*$,,' | \
195 tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
197 configtitle="$(printf ' %-50s %6s active packages ]' \
198 "The OpenSDE ($sdever) Configuration - $config" \
199 "[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
201 bprof main stop
203 if [ -z "$oldconfig" ] ; then
204 eval "./tmp/confdialog.bin --title 'Build Config' \
205 --backtitle '$configtitle' \
206 --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
207 $(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
208 '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
209 returncode=$? ; item="`cat $cfgtmpdir/config.out`"
210 else
211 returncode=1
214 bprof main start
216 [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
218 case "$returncode" in
219 0|6)
220 command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
221 { echo -e "\n# Remember menu position:\ncurrent='$item'"
222 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
223 echo -e "\n# Execute this config command:\n$command"
224 } >> $cfgtmpdir/config/config
226 menu-back)
227 { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
228 echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
229 } >> $cfgtmpdir/config/config
231 1|255)
232 mkdir -p config/$config
233 # sync
234 for x in config/$config/*; do
235 if [ ! -e "$cfgtmpdir/config/${x##*/}" ]; then
236 rm -f "$x"
238 done
239 cp -a $cfgtmpdir/config/* config/$config/
240 rm -rf $cfgtmpdir
241 echo "New config written to config/$config/*."
242 echo "Cleaning up. Configuration finished."
243 bprof main stop
244 bprof_print
245 exit 1 ;;
247 tempitem=$item
248 item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
249 { echo -e "\n# Remember menu position:\ncurrent='$item'"
250 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
251 } >> $cfgtmpdir/config/config
253 get_help $item > $cfgtmpdir/config.dialog
255 bprof main stop
256 ./tmp/confdialog.bin --title 'The OpenSDE Config - Help' \
257 --backtitle "The OpenSDE ($sdever) Configuration" \
258 --textbox $cfgtmpdir/config.dialog \
259 $(( $lines - 4 )) $(( $columns - 5 ))
260 bprof main start
263 echo "unknown returncode: $returncode"
264 bprof main stop
265 bprof_print
266 exit 1 ;;
267 esac
269 bprof main stop
270 bprof_print
272 exit 0