Remote script for base upload

From GeneWeb
Jump to navigation Jump to search


#!/bin/sh
# BASE, BASES_S, GW_DIR_S, WUSR, WGRP, LOGS and ADDRESS 
# will be replaced by the appropriate values by sed
cd HOME_S
DATE=$(date +"%Y-%m-%d-%T")

echo "Error log of update for base: BASE"   #### > LOGS/remote.log
echo "$DATE"   #### >> LOGS/remote.log

# Save current version 
if [ -d BASES_S/BASE.gwb ] ; then # do it only if folder exists
  mv BASES_S/BASE.gwb  BASES_S/BASE-$DATE.gwb    ####2>> LOGS/remote.log                    
fi

# rebuild BASE from .gw file
echo "Building  BASE.gwb"      #### >> LOGS/remote.log
GW_DIR_S/gwc1 -f -o BASES_S/BASE HOME_S/BASE.gw  ####2>> LOGS/remote.log   

if [ -f GW_DIR_S/updnldb ] ; then
  echo "Updating notes links"   #### >> LOGS/remote.log         
  GW_DIR_S/updnldb BASES_S/BASE     ####2>> LOGS/remote.log         
fi

if [ -f GW_DIR_S/update_nldb ] ; then
  GW_DIR_S/update_nldb BASES_S/BASE    ####2>> LOGS/remote.log      
fi

if [ -f BASES_S/BASE-$DATE.gwb/history ] ; then # do it only if file exists
  cp -f BASES_S/BASE-$DATE.gwb/history BASES_S/BASE.gwb ####2>> LOGS/remote.log         
fi

if [ -f BASES_S/BASE-$DATE.gwb/forum ] ; then # do it only if file exists
  cp -f BASES_S/BASE-$DATE.gwb/forum   BASES_S/BASE.gwb ####2>> LOGS/remote.log        
fi

if [ ! -d BASES_S/etc/BASE ] ; then # do it only if folder exists
  echo "0/ Creating folder BASES_S/etc/BASE" #### >> LOGS/remote.log
  mkdir -p BASES_S/etc/BASE     ####2>> LOGS/remote.log
fi

# compute diffs between server and personal computer for image folders
if [ -d BASES_S/images/BASE ] ; then  # do it only if folder exists
  ls BASES_S/images/BASE/*.jpg  > HOME_S/ls-personnes-serveur.txt  ####2>> LOGS/remote.log
  echo "\nPersonnes diff serveur vs local"  #### >> LOGS/remote.log  
  # If >> ~/remote.log does not work on your server, 
  # or if you do not have a /usr/bin/mail capability, global replace it by ####
  # If the diff above fails, replace it by the wc command below which 
  # provides a first level indication of discrepancies betwen the two folders 
  # Do the same operation for the other diff occurences.
  #diff HOME_S/ls-personnes-serveur.txt HOME_S/ls-personnes.txt ####2>> LOGS/remote.log  
  wc HOME_S/ls-personnes*  ####
else
  echo "1/ Creating folder BASES_S/images/BASE"    #### >> LOGS/remote.log
  mkdir -p BASES_S/images/BASE     ####2>> LOGS/remote.log
fi

if [ -d BASES_S/src/BASE/ ] ; then  # do it only if folder exists
  ls BASES_S/src/BASE/*.txt    > HOME_S/ls-src-files-serveur.txt   ####2>> LOGS/remote.log
  echo "\nSrc files diff serveur vs local"    #### >> LOGS/remote.log      
  #diff HOME_S/ls-src-files-serveur.txt HOME_S/ls-src-files.txt    ####2>> LOGS/remote.log 
  wc HOME_S/ls-src-files*      ####2>> LOGS/remote.log
else
  echo "2/ Creating folder BASES_S/src/BASE"     #### >> LOGS/remote.log
  mkdir -p BASES_S/src/BASE     ####2>> LOGS/remote.log
fi

if [ -d BASES_S/src/BASE/images ] ; then # do it only if folder exists
  ls BASES_S/src/BASE/images/*.jpg  > HOME_S/ls-images-serveur.txt ####2>> LOGS/remote.log
  echo "\nImages diff serveur vs local"     #### >> LOGS/remote.log      
  #diff HOME_S/ls-images-serveur.txt HOME_S/ls-images.txt     ####2>> LOGS/remote.log   
  wc HOME_S/ls-images*   ####2>> LOGS/remote.log
else
  echo "3/ Creating folder BASES_S/src/BASE/images"   #### >> LOGS/remote.log
  mkdir -p BASES_S/src/BASE/images    ####2>> LOGS/remote.log
fi

mv -f HOME_S/tags.txt GW_DIR_S/     ####2>> LOGS/remote.log    

#chown -R WUSR  BASES_S    ####2>> LOGS/remote.log
#chgrp -R WGRP  BASES_S    ####2>> LOGS/remote.log
#chown -R WUSR  GW_DIR_S   ####2>> LOGS/remote.log
#chgrp -R WGRP  GW_DIR_S   ####2>> LOGS/remote.log

rm -f    HOME_S/ls-*.txt      ####2>> LOGS/remote.log
rm -f    HOME_S/remote.*      ####2>> LOGS/remote.log
rm -f    HOME_S/history       ####2>> LOGS/remote.log
rm -f    HOME_S/BASE*.tar     ####2>> LOGS/remote.log
rm -f    HOME_S/BASE.gw*      ####2>> LOGS/remote.log
rm -f -R HOME_S/gw_tmp        ####2>> LOGS/remote.log
rm -f -R HOME_S/*tmp          ####2>> LOGS/remote.log
rm -f    HOME_S/._*           ####2>> LOGS/remote.log

echo "End remote.sh"  ####2>> LOGS/remote.logcat tmp.	
#/usr/bin/mail -s 'Update error log' 'ADDRESS' < LOGS/remote.log