203 lines
6.0 KiB
Bash
Executable File
203 lines
6.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# $Revision: 1.22 $
|
|
# $Date: 2007-03-05 07:13:49 $
|
|
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
|
|
# Last revision by $Author: ffr $
|
|
|
|
# Deploys SICServer and configuration files to
|
|
# an instrument control computer.
|
|
# It requires a MANIFEST.TXT file for each instrument
|
|
|
|
# INSTCFCOMMON.TXT file contains paths to the common configuration files
|
|
# used by the instrument specific configurations, it should be placed in
|
|
# the 'config' directory for each instrument. The paths are relative
|
|
# to the instrument source directory. This file is optional.
|
|
|
|
usage()
|
|
{
|
|
cat <<EOF
|
|
deploySICS.sh copies SICS and the files listed
|
|
in the MANIFEST.TXT files to the IC host.
|
|
Usage:
|
|
./deploySICS.sh [-n] INSTRUMENT [TARGET_HOST [TARGET_DIR]]
|
|
where
|
|
-n if present inhibits the actual deployment (for testing the script)
|
|
INSTRUMENT can be hrpd, echidna, hipd, wombat, ... (not "./xxx")
|
|
or test/INSTRUMENT or INSTRUMENT/test for test deployment
|
|
TARGET_HOST can be a remote host or 'localhost'
|
|
defaults to ics1-<instrument>.nbi... or ics1-test.nbi... for test
|
|
TARGET_DIR is the top part of the directory tree
|
|
defaults to /usr/local or /usr/local/TEST_SICS/<instrument> for test
|
|
tail directories in TARGET_DIR will be created on TARGET_HOST if necessary.
|
|
Examples:
|
|
./deploySICS.sh -n echidna
|
|
prepares deployment of echidna (./hrpd)
|
|
to directory /usr/local/sics on isc1-echidna.nbi.ansto.gov.au
|
|
./deploySICS.sh -n reflectometer/test
|
|
prepares deployment of platypus (./reflectometer)
|
|
to directory usr/local/TEST_SICS/platypus on isc1-test.nbi.ansto.gov.au
|
|
./deploySICS.sh -n test/echidna localhost $HOME
|
|
prepares deployment of echidna (./hrpd)
|
|
to directory $HOME/TEST_SICS/echidna on localhost
|
|
EOF
|
|
}
|
|
|
|
# Copy sics server configuration files to a given destination
|
|
# Usage: copy_server_config SERVER_DIRECTORY
|
|
copy_server_config() {
|
|
sicserver_path=$1
|
|
cp -a --preserve=timestamps $COMMON $INSTSPEC $TEMPDIR/$DESTDIR/$sicserver_path
|
|
if [ -e $INSTCFDIR/INSTCFCOMMON.TXT ]; then
|
|
for f in $(cat $INSTCFDIR/INSTCFCOMMON.TXT); do
|
|
cp --parents --preserve=timestamps $f $TEMPDIR/$DESTDIR/$sicserver_path
|
|
done
|
|
fi
|
|
}
|
|
|
|
if [ "$1" = "-n" ]
|
|
then
|
|
DEPLOY="NO"
|
|
shift
|
|
else
|
|
DEPLOY="YES"
|
|
fi
|
|
|
|
if [ $# -eq 0 -o $# -gt 3 ]
|
|
then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
TESTING=$(dirname "$1")
|
|
INSTRUMENT=$(basename "$1")
|
|
if [ "$INSTRUMENT" = "test" ]
|
|
then
|
|
TESTING=$(basename "$1")
|
|
INSTRUMENT=$(dirname "$1")
|
|
fi
|
|
|
|
SRCDIR="."
|
|
TEMPDIR=$HOME/tmp
|
|
|
|
|
|
|
|
# Set the destination host
|
|
# instrument name and the
|
|
# instrument src directory
|
|
|
|
case $INSTRUMENT in
|
|
echidna|hrpd)
|
|
INSTRUMENT=echidna
|
|
DESTHOST=${2:-ics1-echidna.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/hrpd;;
|
|
wombat|hipd)
|
|
INSTRUMENT=wombat
|
|
DESTHOST=${2:-ics1-wombat.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/hipd;;
|
|
koala|qld)
|
|
INSTRUMENT=koala
|
|
DESTHOST=${2:-ics1-koala.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/qld;;
|
|
platypus|reflectometer)
|
|
INSTRUMENT=platypus
|
|
DESTHOST=${2:-ics1-platypus.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/reflectometer;;
|
|
kowari|rsd)
|
|
INSTRUMENT=kowari
|
|
DESTHOST=${2:-ics1-kowari.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/rsd;;
|
|
quokka|sans)
|
|
INSTRUMENT=quokka
|
|
DESTHOST=${2:-ics1-quokka.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/sans;;
|
|
pelican|pas)
|
|
INSTRUMENT=pelican
|
|
DESTHOST=${2:-ics1-pelican.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/pas;;
|
|
taipan|tas)
|
|
INSTRUMENT=taipan
|
|
DESTHOST=${2:-ics1-taipan.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/tas;;
|
|
esac
|
|
INSTCFDIR=$INSTSRC/config
|
|
|
|
make -C ../ $INSTRUMENT || exit $?
|
|
|
|
if [ "$TESTING" = "test" ]
|
|
then
|
|
DESTHOST=${2:-ics1-test.nbi.ansto.gov.au}
|
|
DESTDIR=${3:-/usr/local}/TEST_SICS/$INSTRUMENT
|
|
TARDIR=${DESTDIR:1}
|
|
# remove and recreate the temporary directory
|
|
rm -fr $TEMPDIR/$DESTDIR
|
|
mkdir -p $TEMPDIR/$DESTDIR
|
|
#copy TEST_SICS/fakeDMC and remove CVS any directories
|
|
cp -a $SRCDIR/TEST_SICS/* $TEMPDIR/$DESTDIR
|
|
rm -fr $(find $TEMPDIR/$DESTDIR -name CVS)
|
|
# step down to the sics directory
|
|
DESTDIR=$DESTDIR/sics
|
|
mkdir -p $TEMPDIR/$DESTDIR
|
|
else
|
|
DESTDIR=${3:-/usr/local}/sics
|
|
TARDIR=${DESTDIR:1}
|
|
# remove and recreate the temporary directory
|
|
rm -fr $TEMPDIR/$DESTDIR
|
|
mkdir -p $TEMPDIR/$DESTDIR
|
|
fi
|
|
|
|
echo "Deploying $INSTRUMENT to $DESTHOST:$DESTDIR"
|
|
|
|
|
|
if [ "$DESTHOST" = "localhost" ]
|
|
then
|
|
EXTRACT="tar vxzp -C /"
|
|
else
|
|
EXTRACT="ssh $DESTHOST sg sics -c tar\ vxzp\ -C\ /"
|
|
fi
|
|
|
|
if [ ! -e $SRCDIR/MANIFEST.TXT ]
|
|
then
|
|
echo "$SRCDIR/MANIFEST.TXT not found"
|
|
exit 1
|
|
fi
|
|
if [ ! -e $SRCDIR/$INSTSRC/MANIFEST.TXT ]
|
|
then
|
|
echo "$SRCDIR/$INSTSRC/MANIFEST.TXT not found"
|
|
echo "You must list the files required for $INSTRUMENT in the manifest"
|
|
exit 1
|
|
fi
|
|
|
|
# Get list of files to copy
|
|
COMMON=$(for f in $(cat $SRCDIR/MANIFEST.TXT); do echo -n "$SRCDIR/$f "; done)
|
|
INSTSPEC=$(for f in $(cat $INSTSRC/MANIFEST.TXT); do echo -n "$INSTSRC/$f "; done)
|
|
SCRIPT_VALIDATOR=$(for f in $(cat $INSTSRC/script_validator/MANIFEST.TXT); do echo -n "$INSTSRC/script_validator/$f "; done)
|
|
|
|
# Create Instrument Control Server directories and copy SICS ronfigs to the 'server' directory
|
|
mkdir -p $TEMPDIR/$DESTDIR/{batch,server,data,log,tmp}
|
|
copy_server_config server
|
|
cp -a --preserve=timestamps ../SICServer $TEMPDIR/$DESTDIR/server
|
|
|
|
# Create Script Validator directories and copy SICS configs to the 'script_validator/server' directory
|
|
mkdir -p $TEMPDIR/$DESTDIR/script_validator/{batch,server,data,log,tmp}
|
|
copy_server_config script_validator/server
|
|
# Copy any script_validator configs
|
|
cp -a --preserve=timestamps $SCRIPT_VALIDATOR $TEMPDIR/$DESTDIR/script_validator/server
|
|
|
|
# Create a manifest of the files installed on the IC host
|
|
echo "Date: $(date -Iminutes)" > $TEMPDIR/$DESTDIR/server/MANIFEST.TXT
|
|
echo -e "The following files were installed by $USER\n" >> $TEMPDIR/$DESTDIR/server/MANIFEST.TXT
|
|
cat $SRCDIR/MANIFEST.TXT $SRCDIR/$INSTSRC/MANIFEST.TXT >> $TEMPDIR/$DESTDIR/server/MANIFEST.TXT
|
|
|
|
cd $TEMPDIR
|
|
find $TARDIR -type f -exec chmod u-s,g-x+wr,o-wx+r {} \;
|
|
find $TARDIR -type f -perm -100 -exec chmod go+x {} \;
|
|
find $TARDIR -type d -exec chmod u+rwx,g+rwxs,o-w+rx {} \;
|
|
|
|
# Strip leading / from DESTDIR and extract to destination
|
|
if [ "$DEPLOY" = "YES" ]
|
|
then
|
|
tar -cz $TARDIR | $EXTRACT
|
|
else
|
|
echo "tar -cz $TARDIR | $EXTRACT"
|
|
fi
|