This allows us to track what the differences are to the git version We also include it into .gitignore.
281 lines
9.2 KiB
Bash
Executable File
281 lines
9.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
|
|
# Author: Douglas Clowes (dcl@ansto.gov.au)
|
|
|
|
# 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, lyrebird ... (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
|
|
}
|
|
|
|
init_file_map() {
|
|
echo -n "" >$FILEMAP
|
|
echo "TEMPDIR=$TEMPDIR" >>$FILEMAP
|
|
echo "SRCDIR=$PWD" >>$FILEMAP
|
|
echo "DESTDIR=$DESTDIR" >>$FILEMAP
|
|
echo "SICS_SITE=$(bash ../extract_version.sh SITE)" >>$FILEMAP
|
|
echo "SICS_VERSION=$(bash ../extract_version.sh VERSION)" >>$FILEMAP
|
|
echo "SICS_REVISION=$(bash ../extract_version.sh REVISION)" >>$FILEMAP
|
|
}
|
|
# Copy sics server configuration files to a given destination
|
|
# Usage: copy_server_config SERVER_DIRECTORY
|
|
copy_server_config() {
|
|
sicserver_path=$1
|
|
cp -v -a --preserve=timestamps $COMMON $INSTSPEC $TEMPDIR/$DESTDIR/$sicserver_path >>$FILEMAP
|
|
if [ -e $INSTCFDIR/INSTCFCOMMON.TXT ]; then
|
|
for fpath in $(cat $INSTCFDIR/INSTCFCOMMON.TXT); do
|
|
if [ -f $fpath ]; then
|
|
cp -v --parents --preserve=timestamps $fpath $TEMPDIR/$DESTDIR/$sicserver_path >>$FILEMAP
|
|
else
|
|
for fn in `find $fpath -name '*.tcl'`; do
|
|
cp -v --parents --preserve=timestamps $fn $TEMPDIR/$DESTDIR/$sicserver_path >>$FILEMAP
|
|
done
|
|
fi
|
|
done
|
|
fi
|
|
}
|
|
|
|
# Set shell matches to be case insensitive
|
|
shopt -s nocasematch
|
|
|
|
# If the first argument is "-n" then it is a dry-run only
|
|
if [[ "$1" = "-n" ]]
|
|
then
|
|
DEPLOY="NO"
|
|
shift
|
|
else
|
|
DEPLOY="YES"
|
|
fi
|
|
|
|
# If the wrong number of arguments is given, print usage info and exit
|
|
if [ $# -eq 0 -o $# -gt 3 ]
|
|
then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
# Allow test/animal or animal/test or just animal
|
|
# animal produces TESTING=".", INSTRUMENT=animal
|
|
# test/animal produces TESTING=test, INSTRUMENT=animal
|
|
# animal/test produces TESTING=animal, INSTRUMENT=test (we then swap them)
|
|
TESTING=$(dirname "$1")
|
|
INSTRUMENT=$(basename "$1")
|
|
if [[ "$INSTRUMENT" = "test" ]]
|
|
then
|
|
TESTING=$(basename "$1")
|
|
INSTRUMENT=$(dirname "$1")
|
|
fi
|
|
|
|
SRCDIR="."
|
|
TEMPDIR=$HOME/tmp
|
|
NEWSERVER="server_$(date +%Y%m%d_%H%M)"
|
|
|
|
# We allow the instrument to be specified as either the animal name or the
|
|
# mnemonic as we have to map between the two. This is because the source
|
|
# directory is named by the mnemonic and the destination directory is named by
|
|
# the animal. Any instrument-specific processing should be done within the case.
|
|
|
|
# Set the destination host
|
|
# instrument name and the
|
|
# instrument src directory
|
|
|
|
SICSDIR=sics
|
|
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|pelican)
|
|
INSTRUMENT=pelican
|
|
DESTHOST=${2:-ics1-pelican.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/pelican;;
|
|
lyrebird|lyrebird)
|
|
INSTRUMENT=lyrebird
|
|
DESTHOST=${2:-ics1-taipan.nbi.ansto.gov.au}
|
|
SICSDIR=nbi/sics/lyrebird
|
|
INSTSRC=$SRCDIR/lyrebird;;
|
|
taipan|tas)
|
|
INSTRUMENT=taipan
|
|
DESTHOST=${2:-ics1-taipan.nbi.ansto.gov.au}
|
|
SICSDIR=nbi/sics/taipan
|
|
INSTSRC=$SRCDIR/tas;;
|
|
kookaburra|kookaburra)
|
|
INSTRUMENT=kookaburra
|
|
DESTHOST=${2:-ics1-kookaburra.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/kookaburra;;
|
|
dingo|dingo)
|
|
INSTRUMENT=dingo
|
|
DESTHOST=${2:-ics1-dingo.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/dingo;;
|
|
bilby|bilby)
|
|
INSTRUMENT=bilby
|
|
DESTHOST=${2:-ics1-bilby.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/bilby;;
|
|
emu|emu)
|
|
INSTRUMENT=emu
|
|
DESTHOST=${2:-ics1-emu.nbi.ansto.gov.au}
|
|
INSTSRC=$SRCDIR/emu;;
|
|
esac
|
|
INSTCFDIR=$INSTSRC/config
|
|
|
|
# Perform any instrument-specific make processing
|
|
make -C ../ $INSTRUMENT || exit $?
|
|
|
|
# Set up the staging directories and, if testing, the testing parts
|
|
if [[ "$TESTING" = "test" ]]
|
|
then
|
|
DESTHOST=${2:-ics1-test.nbi.ansto.gov.au}
|
|
DESTDIR=${3:-/usr/local}/TEST_SICS/$INSTRUMENT
|
|
TARDIR=${DESTDIR:1}
|
|
# step down to the sics directory
|
|
DESTDIR=$DESTDIR/$SICSDIR
|
|
else
|
|
DESTDIR=${3:-/usr/local}/$SICSDIR
|
|
TARDIR=${DESTDIR:1}
|
|
fi
|
|
|
|
# remove and recreate the temporary directory
|
|
rm -fr $TEMPDIR/$DESTDIR
|
|
mkdir -p $TEMPDIR/$DESTDIR/${NEWSERVER}
|
|
ln -s ${NEWSERVER} $TEMPDIR/$DESTDIR/newserver
|
|
FILEMAP=$TEMPDIR/$DESTDIR/${NEWSERVER}/FILEMAP.TXT
|
|
init_file_map
|
|
|
|
# Notify progress and intention
|
|
echo "Deploying $INSTRUMENT to $DESTHOST:$DESTDIR"
|
|
|
|
# Set up the commands that we will be using for the "deploy" phase
|
|
EXTRACT_CMDS="tar vxzp -C /; touch /$DESTDIR/{DataNumber,extraconfig.tcl,${NEWSERVER}/config/nexus/nexus.dic,script_validator/DataNumber}"
|
|
if [[ "$DESTHOST" = "localhost" ]]
|
|
then
|
|
EXTRACT=$EXTRACT_CMDS
|
|
EXTRACT_NODEPLOY=$EXTRACT_CMDS
|
|
elif [[ "$TESTING" != "test" ]]
|
|
then
|
|
EXTRACT="ssh $DESTHOST $EXTRACT_CMDS; chown -R root:root /$DESTDIR/${NEWSERVER}; chown ${INSTRUMENT}_sics. /$DESTDIR/{DataNumber,${NEWSERVER}/config/nexus/nexus.dic,script_validator/{DataNumber,data}}; chown ${INSTRUMENT}. /$DESTDIR/extraconfig.tcl"
|
|
EXTRACT_NODEPLOY="ssh $DESTHOST $EXTRACT_CMDS; chown -R root:root /$DESTDIR/${NEWSERVER}; chown ${INSTRUMENT}_sics. /$DESTDIR/{DataNumber,${NEWSERVER}/config/nexus/nexus.dic}; chown ${INSTRUMENT}. /$DESTDIR/extraconfig.tcl"
|
|
else
|
|
EXTRACT="ssh $DESTHOST $EXTRACT_CMDS"
|
|
EXTRACT_NODEPLOY="ssh $DESTHOST $EXTRACT_CMDS"
|
|
fi
|
|
|
|
# Ensure that we have the needed manifest files
|
|
if [ ! -e $SRCDIR/MANIFEST.TXT ]
|
|
then
|
|
echo "$SRCDIR/MANIFEST.TXT not found"
|
|
exit 1
|
|
fi
|
|
if [ ! -e $INSTSRC/MANIFEST.TXT ]
|
|
then
|
|
echo "$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 and prepend directory name
|
|
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)
|
|
|
|
# Create Instrument Control Server directories and copy SICS configs to the 'server' directory
|
|
mkdir -p $TEMPDIR/$DESTDIR/{batch,${NEWSERVER},log,tmp}
|
|
copy_server_config ${NEWSERVER}
|
|
cp -v -a --preserve=timestamps ../SICServer $TEMPDIR/$DESTDIR/${NEWSERVER} >>$FILEMAP
|
|
|
|
# Create Script Validator directories
|
|
mkdir -p $TEMPDIR/$DESTDIR/script_validator/{data,log,tmp}
|
|
|
|
# Create a manifest of the files installed on the IC host
|
|
echo "Date: $(date -Iminutes)" > $TEMPDIR/$DESTDIR/${NEWSERVER}/DEPLOYMENT.TXT
|
|
echo "User: $USER" >> $TEMPDIR/$DESTDIR/${NEWSERVER}/DEPLOYMENT.TXT
|
|
DEPLOYED_VERSION="$(bash ../extract_version.sh all)"
|
|
echo "Version:" $DEPLOYED_VERSION >> $TEMPDIR/$DESTDIR/${NEWSERVER}/DEPLOYMENT.TXT
|
|
if [ -e PATCH.TXT ]
|
|
then
|
|
cat PATCH.TXT > $TEMPDIR/$DESTDIR/${NEWSERVER}/PATCH.TXT
|
|
fi
|
|
cat $SRCDIR/MANIFEST.TXT $SRCDIR/$INSTSRC/MANIFEST.TXT > $TEMPDIR/$DESTDIR/${NEWSERVER}/MANIFEST.TXT
|
|
|
|
cd $TEMPDIR
|
|
# remove any .svn directories
|
|
rm -rf $(find $TARDIR -type d -name .svn)
|
|
# remove any unit test directories
|
|
find $TARDIR -type d -name _trial_temp\* -exec rm -rf {} \;
|
|
# remove any temporary .orig files
|
|
find $TARDIR -type f -name \*.orig -exec rm {} \;
|
|
# remove any temporary editor files
|
|
find $TARDIR -type f -name .\*.sw\? -exec rm {} \;
|
|
# remove any editor backup files directories
|
|
find $TARDIR -type f -name \*~ -exec rm {} \;
|
|
# remove any compiled python files
|
|
find $TARDIR -type f -name \*.pyc -exec rm {} \;
|
|
# set modes for files
|
|
find $TARDIR -type f -exec chmod u-s,g-x+wr,o-wx+r {} \;
|
|
find $TARDIR -type f -perm -100 -exec chmod go+x {} \;
|
|
# set modes for directories
|
|
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
|
|
if [[ "$DESTHOST" = "localhost" ]]
|
|
then
|
|
eval "tar -cz ${TARDIR} | $EXTRACT"
|
|
else
|
|
tar -cz ${TARDIR} | $EXTRACT
|
|
fi
|
|
else
|
|
echo "tar -cz -C $TEMPDIR $TARDIR | $EXTRACT_NODEPLOY"
|
|
fi
|