#! /bin/bash #******************************************************************************* # E.S.O. - ACS project # # "@(#) $Id: acsMakeLogInstallation,v 1.2 2010/07/09 15:15:24 rtobar Exp $" # # who when what # -------- ---------- ---------------------------------------------- # eallaert 2014-10-07 copied over from Kit/vlt/src, and adjusted for acs #******************************************************************************* # ALMA - Atacama Large Millimeter Array # Copyright (c) ESO - European Southern Observatory, 2014 # (in the framework of the ALMA collaboration). # All rights reserved. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #******************************************************************************* #************************************************************************ # NAME # acsMakeLogInstallation - record make install in PRJTOP. # # SYNOPSIS # # acsMakeLogInstallation # # # DESCRIPTION # Utility used by acsMakefile to record at every "make install": # # - in $PRJTOP/acsMakeInstall.config # - module name (the directory name) # - module number ( # - username that is installing # - current date # # - in $PRJTOP/acsMakeInstall.log # - username # - pwd # - date # # It is not intended to be used as a standalone command. # # directory target of the install operation # # # FILES # $ACSROOT/include/acsMakefile is using this # $PRJTOP/acsMakeInstall.log where to log # # ENVIRONMENT # # RETURN VALUES # # SEE ALSO # acsMakefile, Makefile # # BUGS # #---------------------------------------------------------------------- # if Linux: disable the bash builtin command 'echo'. if [ "`uname`" = "Linux" ] then enable -n echo elif [ "`uname`" = "$CYGWIN_VER" ] then alias echo="echo -e" fi # # check input parameter # if [ ! -d "$1" ] then echo "" >&2 echo " ERROR: acsMakeLogInstallation: the first parameter is not a directory." >&2 echo "" >&2 exit 1 else PRJTOP=$1 LOGFILE=$PRJTOP/acsMakeInstall.log CONFIGFILE=$PRJTOP/acsMakeInstall.config LOCKFILE=$PRJTOP/acsMakeInstall.lock fi # # retrive identification of the current module # # # - module name # There are two cases: # - normal modules: the module name is the parent directory # - multiplatform modules: the module is structured as more than one # submodules. Each submodule has the normal module # directory tree but fixed names are used: # /lcu for the LCU part # /ws for the ws part PWD=`pwd` PARENT_DIR=`dirname $PWD` MODULE_NAME=`basename $PARENT_DIR` if [ "$MODULE_NAME" = "lcu" -o "$MODULE_NAME" = "ws" ] then GRANDPARENT_DIR=`dirname $PARENT_DIR` MODULE_NAME="`basename $GRANDPARENT_DIR`-`basename $PARENT_DIR`" fi # # - module version # I take it from the $ID in the Makefile, that should be always present if [ -f Makefile ] then MODULE_VERSION=`grep Makefile,v Makefile | \ awk '{ if ( $4 == "Makefile,v" ) \ printf("%s %s %s %s\n", $5, $6, $7, $8);\ else \ print "0.0 the Makefile does not contain the standard configuration string (see Makefile template)"\ } '` else MODULE_VERSION="0.0 the module does not contain a Makefile file" fi # # Check the lock, if nobody is Set a lock file (if currently locked, allows a 5 sec delay) # if [ -f $LOCKFILE ] then sleep 5 fi if [ -f $LOCKFILE ] then echo "\n ERROR: acsMakeLogInstallation: files currently locked by: `cat $LOCKFILE`" >&2 echo " Lock file is $LOCKFILE" >&2 echo " Probably a make install operation was interrupted while recording the operatiom." >&2 echo " Check with the person and remove the lock file." >&2 echo "\n ---> installation NOT recorded\n" >&2 echo "" >&2 exit 1 else echo "`whoami` since `date '+%y/%m/%d-%H:%M'` while was installing: ${MODULE_NAME} ${MODULE_VERSION}" > $LOCKFILE fi # # if not already existing, create the log file # if [ ! -f $LOGFILE ] then if touch $LOGFILE then chmod 664 $LOGFILE echo "# E.S.O. - ACS project - INSTALLATION LOG - created by acsMakeLogInstallation `date '+%y/%m/%d-%H:%M'`" >> $LOGFILE else echo "" >&2 echo "ERROR: acsMakeLogInstallation: cannot create $LOGFILE." >&2 echo "" >&2 rm $LOCKFILE exit 1 fi fi # # record date, username, current directory ... # if [ -w $LOGFILE ] then # ... in the file ... echo "`date '+%y/%m/%d-%H:%M'` module: ${MODULE_NAME} ${MODULE_VERSION}, installed by:`whoami`\t from:`pwd`" >> $LOGFILE else echo "\n ERROR: acsMakeLogInstallation: cannot write into $LOGFILE." >&2 echo "\n cannot write into $LOGFILE." >&2 echo "\n ---> installation NOT recorded\n" >&2 echo "" >&2 rm $LOCKFILE exit 1 fi # # if not already existing, create the configuration file # if [ ! -f $CONFIGFILE ] then if touch $CONFIGFILE then chmod 664 $CONFIGFILE echo "# E.S.O. - ACS project - INSTALLED MODULES - created by acsMakeLogInstallation `date '+%y/%m/%d-%H:%M'`" >> $CONFIGFILE else echo "" >&2 echo "ERROR: acsMakeLogInstallation: cannot create $CONFIGFILE." >&2 echo "" >&2 rm $LOCKFILE exit 1 fi fi # # record module name, version, etc. ... # if [ -w $CONFIGFILE ] then # ... at the end of the file ... cat $CONFIGFILE | grep -v "^$MODULE_NAME " > $CONFIGFILE.tmp if [ -f ${CONFIGFILE}.tmp ] then mv ${CONFIGFILE}.tmp ${CONFIGFILE} chmod 664 $CONFIGFILE fi echo "$MODULE_NAME $MODULE_VERSION \t installed by: `whoami` (`date '+%y/%m/%d-%H:%M'`)" >> $CONFIGFILE # ... sort the file and eliminate duplication: sort -r -k 1,1 ${CONFIGFILE} | awk '{ if ( $1 == "#" ) \ { print $0 ; last = $1 } \ else \ { current= $1 ; \ if ( current != last)\ print $0;\ last = current } \ } ' | sort -k 1,1 > ${CONFIGFILE}.BCK if [ -f ${CONFIGFILE}.BCK ] then mv ${CONFIGFILE}.BCK ${CONFIGFILE} chmod 664 $CONFIGFILE fi else echo "\n ERROR: acsMakeLogInstallation: cannot write into $CONFIGFILE." >&2 echo "\n cannot write into $CONFIGFILE." >&2 echo "\n ---> installation NOT recorded\n" >&2 echo "" >&2 rm $LOCKFILE exit 1 fi # remove the lock ... rm $LOCKFILE # ... and notify the user echo "\n\n ---> installation recorded in $PRJTOP\n" # # ___oOo___