#!/bin/bash
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: scripts/Config
|
|
# Copyright (C) 2006 - 2010 The OpenSDE Project
|
|
# Copyright (C) 2004 - 2006 The T2 SDE Project
|
|
# Copyright (C) 1998 - 2003 Clifford Wolf
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ] ; then
|
|
if [ "$( type -p stty )" ] ; then
|
|
lines="$( stty size 2> /dev/null | cut -d' ' -f1 )"
|
|
columns="$( stty size 2> /dev/null | cut -d' ' -f2 )"
|
|
fi
|
|
[ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
|
|
[ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
|
|
fi
|
|
|
|
. "lib/libsde.in"
|
|
|
|
config=default
|
|
do_config_cycle=0
|
|
delete_mode=0
|
|
oldconfig=
|
|
nobashmod=
|
|
cfgtmpdir=
|
|
profile=
|
|
|
|
show_usage() {
|
|
echo
|
|
echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ]"
|
|
echo
|
|
echo "Other options:"
|
|
echo " -profile create a config.profile with profiling data"
|
|
echo " -nobashmod don't use the bash config helper plugin"
|
|
echo
|
|
}
|
|
|
|
while [ "$1" ] ; do
|
|
case "$1" in
|
|
-cycle) do_config_cycle=1 ; shift ;;
|
|
-delete) delete_mode=1 ; shift ;;
|
|
-profile) profile='-profile' ; shift ;;
|
|
-oldconfig) oldconfig='-oldconfig' ; shift ;;
|
|
-nobashmod) nobashmod='-nobashmod' ; shift ;;
|
|
-cfg) config="$2" ; shift ; shift ;;
|
|
|
|
*) show_usage
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$config" ]; then
|
|
show_usage
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d config/$config -a -n "$oldconfig" ]; then
|
|
echo "Abort: -oldconfig is not supported for new configs"
|
|
echo
|
|
exit 1
|
|
fi
|
|
|
|
if [ $delete_mode = 1 ] ; then
|
|
rm -rv config/$config
|
|
exit $?
|
|
fi
|
|
|
|
cfgtmpdir=tmp/$config
|
|
|
|
if [ $do_config_cycle = 0 ] ; then
|
|
rm -rf $cfgtmpdir
|
|
mkdir -p $cfgtmpdir # src
|
|
|
|
if [ -z "$oldconfig" -a ! -f tmp/confdialog.bin ] ; then
|
|
echo "Creating confdialog tool."
|
|
command="gcc src/confdialog/*.c `
|
|
`-Isrc/confdialog -lncurses -o tmp/confdialog.bin"
|
|
set -e
|
|
echo "$command" ; eval "$command.$$"
|
|
mv tmp/confdialog.bin.$$ tmp/confdialog.bin
|
|
set +e
|
|
fi
|
|
|
|
# don't accept Ctrl-C because it destroy the configurations
|
|
trap '' INT
|
|
|
|
if [ -d "config/$config" ]; then
|
|
if ./lib/sde-config/migrate.sh "$config"; then
|
|
mkdir -p $cfgtmpdir/config/
|
|
cp -a config/$config/* $cfgtmpdir/config/
|
|
if [ $? -ne 0 ]; then
|
|
echo "Copy of config failed, aborting."
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
echo "Starting OpenSDE ($sdever) configuration ..."
|
|
while "$0" -cfg $config $oldconfig $profile $nobashmod -cycle ; do : ; done
|
|
|
|
trap INT
|
|
|
|
exit 0
|
|
fi
|
|
|
|
if [ -z "$nobashmod" ]; then
|
|
if [ ! -f tmp/config_helper.so -o src/tools-source/config_helper.c -nt tmp/config_helper.so ]; then
|
|
echo "Building tmp/config_helper.so."
|
|
gcc -shared -fPIC -Wall -o tmp/config_helper.so src/tools-source/config_helper.c || exit 1
|
|
fi
|
|
enable -f tmp/config_helper.so cfghlp || exit 1
|
|
fi
|
|
|
|
if [ -z "$profile" ]; then
|
|
bprof() { :; }
|
|
bprof_print() { :; }
|
|
else
|
|
if [ ! -f tmp/bash_profiler.so -o src/tools-source/bash_profiler.c -nt tmp/bash_profiler.so ]; then
|
|
echo "Building tmp/bash_profiler.so."
|
|
gcc -shared -fPIC -Wall -o tmp/bash_profiler.so src/tools-source/bash_profiler.c || exit 1
|
|
fi
|
|
enable -f tmp/bash_profiler.so bprof || exit 1
|
|
bprof_print() {
|
|
local cprof=$cfgtmpdir/config.profile
|
|
bprof all print >> $cprof
|
|
awk '
|
|
$4 == "profiled" { next; }
|
|
$4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
|
|
{ count[$4]+=$1; time[$4]+=$2; }
|
|
END {
|
|
for (id in count)
|
|
printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
|
|
}
|
|
' < $cprof | sort -n -k2 > $cprof.new
|
|
mv $cprof.net $cprof
|
|
}
|
|
fi
|
|
|
|
bprof main start
|
|
|
|
. lib/sde-config/functions.in
|
|
arch=`uname -m | uname2arch`
|
|
current= ; export SDECFG_ARCH="$arch" ; export SDECFG_EXPERT=0
|
|
menu_this=0 ; menu_current=0 ; menu_counter=0
|
|
menu_stack=x ; menu_back=-1 ; menu_backpos=-1
|
|
|
|
set -e
|
|
mkdir -p $cfgtmpdir/config
|
|
touch $cfgtmpdir/config/{config,packages}
|
|
set +e
|
|
|
|
configtitle="$(printf ' %-50s %6s active packages ]' \
|
|
"OpenSDE ($sdever) Configuration - $config" \
|
|
"[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
|
|
|
|
bprof main stop
|
|
|
|
. $cfgtmpdir/config/config
|
|
bprof main start
|
|
|
|
rm -f $cfgtmpdir/config.{dialog,data,help}
|
|
touch $cfgtmpdir/config.{dialog,data,help}
|
|
$ECHO_E "#\n# OpenSDE ($sdever) Config File\n#" > $cfgtmpdir/config/config
|
|
spacer= ; expert=0 ; tabspace="5" ; tabspace_list=
|
|
commentnr=0 ; editfilenr=0
|
|
|
|
bprof mkpkglist start
|
|
cmd="./bin/sde-list package --arch '$SDECFG_ARCH'"
|
|
|
|
if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ] ; then
|
|
eval "$cmd" | tee $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
|
|
echo "$cmd" > $cfgtmpdir/config.pcache.cmd
|
|
else
|
|
cat $cfgtmpdir/config.pcache.data > $cfgtmpdir/config/packages
|
|
fi
|
|
bprof mkpkglist stop
|
|
|
|
# Create lists of .in files
|
|
create_dot_in_lists
|
|
|
|
export SDECFG_ID="$sdever"; pkgin; . lib/sde-config/main.in; pkgout
|
|
echo "export SDECFG_ID='$SDECFG_ID'" >> $cfgtmpdir/config/config
|
|
rm -f $cfgtmpdir/*.tmp
|
|
|
|
cut -f1,2,4,5,8- -d' ' $cfgtmpdir/config/packages | sed 's, [^ ]*$,,' | \
|
|
tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
|
|
|
|
configtitle="$(printf ' %-50s %6s active packages ]' \
|
|
"OpenSDE ($sdever) Configuration - $config" \
|
|
"[ $(echo `grep '^X' $cfgtmpdir/config/packages | wc -l`)" )"
|
|
|
|
bprof main stop
|
|
|
|
if [ -z "$oldconfig" ] ; then
|
|
eval "./tmp/confdialog.bin --title 'Build Config' \
|
|
--backtitle '$configtitle' \
|
|
--menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
|
|
$(( $lines - 4 )) $(( $columns - 5 )) $(( $lines - 12 )) \
|
|
'$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
|
|
returncode=$? ; item="`cat $cfgtmpdir/config.out`"
|
|
else
|
|
returncode=1
|
|
fi
|
|
|
|
bprof main start
|
|
|
|
[ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
|
|
|
|
case "$returncode" in
|
|
0|6)
|
|
command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
|
|
{ $ECHO_E "\n# Remember menu position:\ncurrent='$item'"
|
|
$ECHO_E "\n# Remember sub-menu:\nmenu_current='$menu_current'"
|
|
$ECHO_E "\n# Execute this config command:\n$command"
|
|
} >> $cfgtmpdir/config/config
|
|
;;
|
|
menu-back)
|
|
{ $ECHO_E "\n# New menu position:\ncurrent='$menu_backpos'"
|
|
$ECHO_E "\n# New sub-menu:\nmenu_current='$menu_back'"
|
|
} >> $cfgtmpdir/config/config
|
|
;;
|
|
1|255)
|
|
mkdir -p config/$config
|
|
# sync
|
|
# TODO: make this nicer, but still sudo-friendly
|
|
for x in config/$config/*; do
|
|
y="$cfgtmpdir/config/${x##*/}"
|
|
if [ ! -e "$y" ]; then
|
|
rm -f "$x"
|
|
else
|
|
# to not change the permissions (sudo-friendliness)
|
|
cat "$y" > "$x"
|
|
rm -f "$y"
|
|
fi
|
|
done
|
|
for y in "$cfgtmpdir/config"/* ; do 2> /dev/null
|
|
if [ -e "$y" ]; then
|
|
cp -a "$y" config/$config/
|
|
rm -f "$y"
|
|
fi
|
|
done
|
|
rmdir $cfgtmpdir/config && rm -rf $cfgtmpdir/
|
|
echo "New config written to config/$config/*."
|
|
echo "Cleaning up. Configuration finished."
|
|
bprof main stop
|
|
bprof_print
|
|
exit 1 ;;
|
|
2)
|
|
tempitem=$item
|
|
item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
|
|
{ $ECHO_E "\n# Remember menu position:\ncurrent='$item'"
|
|
$ECHO_E "\n# Remember sub-menu:\nmenu_current='$menu_current'"
|
|
} >> $cfgtmpdir/config/config
|
|
|
|
get_help $item > $cfgtmpdir/config.dialog
|
|
|
|
bprof main stop
|
|
./tmp/confdialog.bin --title 'OpenSDE Config - Help' \
|
|
--backtitle "OpenSDE ($sdever) Configuration" \
|
|
--textbox $cfgtmpdir/config.dialog \
|
|
$(( $lines - 4 )) $(( $columns - 5 ))
|
|
bprof main start
|
|
;;
|
|
*)
|
|
echo "unknown returncode: $returncode"
|
|
bprof main stop
|
|
bprof_print
|
|
exit 1 ;;
|
|
esac
|
|
|
|
bprof main stop
|
|
bprof_print
|
|
|
|
exit 0
|