Difference between revisions of "base-upld"

From GeneWeb
Jump to: navigation, search
Line 10: Line 10:
 
# This shell script executes scp and ssh commands with the remote server
 
# This shell script executes scp and ssh commands with the remote server
 
# This requires (?) that you have installed a pair of private/public keys on both machines
 
# This requires (?) that you have installed a pair of private/public keys on both machines
# See "ssh with key pairs" on the web
+
# See "how to create a key pair" on teh web
  
 
# An alternative to key pairs is to send password information with the commands
 
# An alternative to key pairs is to send password information with the commands
# To do this, add ":password" after the username in each occurence of USER@SERVER
+
# To do this, add ":password" after username in each occurence of USER@SERVER  
# as in my_user_name:my_password@my_server_name
+
 
# Be aware that password is sent in cleartext !!
 
# Be aware that password is sent in cleartext !!
  
SERVER="your server name"
+
SERVER="ssh.tuxfamily.org"
USER="your user name on your server"
+
USER="your user name"
ADDRESS="your e-mail address"  # to which error report will be sent
+
ADDRESS="Your mail address"  # to which error report will be sent
 
LANGUE="fr"
 
LANGUE="fr"
 
BASE=""
 
BASE=""
  
VERS="7.00-Mac"                            # GeneWeb version
+
BASES_PC="$HOME/Genea/GeneWeb-Bases"            # Bases location on PC
VERS_S="7.00"                              # GeneWeb version on server
+
BASES_SERVER="~/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/bases"   # Bases location on server
GENEA="$HOME/Genea"                        # Home for genealogy files
+
BIN_DIR="$HOME/Genea/GeneWeb/GeneWeb-7.00-Mac/gw"  # Binaries (gwd, gwc, ...) location on PC
BASES_PC="$GENEA/GeneWeb-Bases"            # Bases location on PC
+
BIN_DIR_SERVER="~/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/gw"  # Binaries (gwd, gwc, ...) on Server
BASES_SERVER="GeneWeb/bases"               # Bases location on server
+
BIN_DIR="$GENEA/GeneWeb/GeneWeb-$VERS/gw"  # Binaries (gwd, gwc, ...) location
+
  
 
check_errs()
 
check_errs()
Line 59: Line 56:
 
   echo "Sending $FILES for $BASE to $SERVER"
 
   echo "Sending $FILES for $BASE to $SERVER"
 
   cd $BASES_PC/$FILES
 
   cd $BASES_PC/$FILES
   sed s/BASE/$BASE/g < $GENEA/remote-files.txt | \
+
   sed s:BASES_SERVER:$BASES_SERVER:g < $HOME/Genea/remote-files.txt | \
   sed s/ADDRESS/$ADDRESS/g   > ./remote.sh
+
   sed s:BASE:$BASE:g | \
 +
  sed s:ADDRESS:$ADDRESS:g > ./remote.sh
 
   touch ./$FILES.tmp
 
   touch ./$FILES.tmp
 
   tar cf ./$BASE-files.tar $BASE ./remote.sh ./$FILES.tmp
 
   tar cf ./$BASE-files.tar $BASE ./remote.sh ./$FILES.tmp
Line 94: Line 92:
 
fi
 
fi
  
echo "Producing a fresh $BASE.gw in *BASES_PC (gwu)"
+
echo "Producing a fresh $BASE.gw in $BASES_PC (gwu)"
 
cd $BASES_PC
 
cd $BASES_PC
 
$BIN_DIR/gwu ./$BASE -o $BASE.gw > comm.log
 
$BIN_DIR/gwu ./$BASE -o $BASE.gw > comm.log
Line 113: Line 111:
 
   
 
   
 
# Build a command file to be executed on the server
 
# Build a command file to be executed on the server
sed s/BASE/$BASE/g < $GENEA/remote-base.txt | \
+
sed s:BASES_SERVER:$BASES_SERVER:g < $HOME/Genea/remote-base.txt | \
sed s/VERS_S/$VERS_S/g | \
+
sed s:BASE:$BASE:g | \
sed s/ADDRESS/$ADDRESS/g > ./remote.sh
+
sed s:BIN_DIR_SERVER:$BIN_DIR_SERVER:g | \
 +
sed s:ADDRESS:$ADDRESS:g > ./remote.sh
  
 
echo "Building remote.tar (remote.sh $BASE.gw history s-personnes.txt ls-images.txt ls-src-files.txt)"
 
echo "Building remote.tar (remote.sh $BASE.gw history s-personnes.txt ls-images.txt ls-src-files.txt)"
 
tar cf ./$BASE.tar ./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt
 
tar cf ./$BASE.tar ./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt
  
echo "Sending remote.tar"
+
echo "Sending remote.tar to $SERVER"
 
scp ./$BASE.tar $USER@$SERVER:$BASE.tar
 
scp ./$BASE.tar $USER@$SERVER:$BASE.tar
 
echo "$BASE.tar sent"
 
echo "$BASE.tar sent"

Revision as of 09:56, 26 October 2015

150px-Geographylogo svg.png Language: English
#!/bin/sh
# Version 1, 24/10/2015, Henri

# Usage : update-base base_name [ images | src ]

# This shell script executes scp and ssh commands with the remote server
# This requires (?) that you have installed a pair of private/public keys on both machines
# See "how to create a key pair" on teh web

# An alternative to key pairs is to send password information with the commands
# To do this, add ":password" after username in each occurence of USER@SERVER 
# Be aware that password is sent in cleartext !!

SERVER="ssh.tuxfamily.org"
USER="your user name"
ADDRESS="Your mail address"  # to which error report will be sent
LANGUE="fr"
BASE=""

BASES_PC="$HOME/Genea/GeneWeb-Bases"             # Bases location on PC
BASES_SERVER="~/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/bases"    # Bases location on server
BIN_DIR="$HOME/Genea/GeneWeb/GeneWeb-7.00-Mac/gw"   # Binaries (gwd, gwc, ...) location on PC
BIN_DIR_SERVER="~/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/gw"   # Binaries (gwd, gwc, ...) on Server

check_errs()
{
  # Function. Parameter 1 is the return code
  # Para. 2 is text to display on failure.
  if [ "${1}" -ne "0" ]; then
    echo "ERROR # ${1} : ${2}"
    # as a bonus, make our script exit with the right error code.
    exit ${1}
  fi
}

# define BASE
BASE=$1
FILES=$2

if [ "$BASE" = "" ] || [ "$BASE" = "-h" ] || [ "$BASE" = "-help" ]
then
  echo "Usage : update-base base_name [ images | src ]"
  echo "    if 'images' or 'src' are present, only the corresponding folders will"
  echo "    be copied in totality to the server"
  exit
fi


if [ "$FILES" = "images" ] || [ "$FILES" = "src" ] 
then
  # copy images files to server
  echo "Sending $FILES for $BASE to $SERVER"
  cd $BASES_PC/$FILES
  sed s:BASES_SERVER:$BASES_SERVER:g < $HOME/Genea/remote-files.txt | \
  sed s:BASE:$BASE:g | \
  sed s:ADDRESS:$ADDRESS:g  > ./remote.sh
  touch ./$FILES.tmp
  tar cf ./$BASE-files.tar $BASE ./remote.sh ./$FILES.tmp
  scp ./$BASE-files.tar $USER@$SERVER:$BASE-files.tar
  ssh $USER@$SERVER "tar xf $BASE-files.tar; chmod +x ./remote.sh; ./remote.sh"
  rm -f ./remote.sh
  echo "Done sending $FILES for $BASE to $SERVER"
  exit
fi



mot="n" # default is "no"
# Verify that the images and src/images folder are up to date. 
if [ $LANGUE = "fr" ] 
then
  echo "Cette procédure ne met pas à jour les deux dossiers images"
  echo "Le message de compte-rendu signale les différences dans les dossiers images du serveur et du PC"
  echo "Vous pouvez cependant continuer"
  echo "Pensez aussi à installer $BASE.gwf sur votre serveur"
  echo "Continuer? [o/n]"
else
  echo "This procedure does not update the two images folders"
  echo "It returns through mail a report indicating differences between the server and the PC"
  echo "You may nonetheless proceed"
  echo "Make sure you install the proper $BASE.gwf parameters on your server"
  echo "Proceed? [y/n]"
fi
read mot
if [ "$mot" = "n" ] # or "$mot" = ""
then
  exit
fi

echo "Producing a fresh $BASE.gw in $BASES_PC (gwu)"
cd $BASES_PC
$BIN_DIR/gwu ./$BASE -o $BASE.gw > comm.log
check_errs $? "Gwu failed on $BASE, see $BASES_PC/comm.log for details "

# Take a copy of current change history to send to server
cp -f ./$BASE.gwb/history .

# Create a content listing for the images and person images folders
cd   $BASES_PC/src/$BASE
ls > $BASES_PC/ls-src-files.txt
cd   $BASES_PC/src/$BASE/images
ls > $BASES_PC/ls-images.txt
cd   $BASES_PC/images/$BASE
ls > $BASES_PC/ls-personnes.txt

cd $BASES_PC
 
# Build a command file to be executed on the server
sed s:BASES_SERVER:$BASES_SERVER:g < $HOME/Genea/remote-base.txt | \
sed s:BASE:$BASE:g | \
sed s:BIN_DIR_SERVER:$BIN_DIR_SERVER:g | \
sed s:ADDRESS:$ADDRESS:g > ./remote.sh

echo "Building remote.tar (remote.sh $BASE.gw history s-personnes.txt ls-images.txt ls-src-files.txt)"
tar cf ./$BASE.tar ./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt

echo "Sending remote.tar to $SERVER"
scp ./$BASE.tar $USER@$SERVER:$BASE.tar
echo "$BASE.tar sent"
# Execute a remote command on the server
#     un-tar the file just sent, make remote.sh executable and execute it
ssh $USER@$SERVER "tar xf $BASE.tar; chmod +x ./remote.sh; ./remote.sh"
echo "Tar xf done; remote.sh executed"

echo "Cleanup (on local machine)"
rm -f ./remote.* ./history ./ls-*.txt

echo "Done updating $BASE on $SERVER"