Difference between revisions of "base-upld"

From GeneWeb
Jump to: navigation, search
m
(New version of base-upload)
 
Line 3: Line 3:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
#!/bin/sh
 
#!/bin/sh
# Version 1, 16/06/2016, Henri
+
# Version 2, 24/11/2016, Henri
  
 
# Usage : update-base base_name [ images | src ]
 
# Usage : update-base base_name [ images | src ]
Line 17: Line 17:
 
# Be aware that in this case, password is sent in cleartext !!
 
# Be aware that in this case, password is sent in cleartext !!
  
SERVER="ssh.tuxfamily.org"
+
S=tuxf
USER="your user name"
+
 
ADDRESS="Your mail address"  # to which error report will be sent
+
if [ "$S" = "tuxf" ]
 +
then
 +
  SERVER="ssh.tuxfamily.org"
 +
  HOME_S="/home/geneweb/geneweb-repository/demo"
 +
  USER="aaaaa"
 +
  WUSR="www-data"
 +
  WGRP="www-data"
 +
  P1=""
 +
  P2=""
 +
  BASES_S="/home/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/gw7/bases"    # Bases location on server
 +
  GW_DIR_S="/home/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/gw7/gw"  # Binaries (gwd, gwc, ...) on Server
 +
elif [ "$S" = "ovh" ]
 +
then
 +
SERVER="vps664433.ovh.net"
 +
HOME_S="/root"
 +
USER="root"
 +
WUSR="www-data"
 +
WGRP="www-data"
 +
P1=""
 +
P2=""
 +
BASES_S="~/GW/bases7"              # Bases location on server hgouraud.fr
 +
GW_DIR_S="~/GW/GeneWeb-7.0x/gw"    # Binaries (gwd, gwc, ...) on Server
 +
elif [ "$S" = "phpn" ]
 +
then
 +
  SERVER="p5678.phpnet.org"
 +
  HOME_S=""
 +
  USER="p5678"
 +
  WUSR="www-data"
 +
  WGRP="www-data"
 +
  P1="-p 25678"
 +
  P2="-P 25678"
 +
  BASES_S="~/GeneWeb/bases"              # Bases location on server
 +
  GW_DIR_S="~/GeneWeb/geneweb-7.00/gw"    # Binaries (gwd, gwc, ...) on Server
 +
elif [ "$S" = "roglo" ]
 +
then
 +
  SERVER="roglo.eu"
 +
  HOME_S="/data/wiz/Wizzard"
 +
  USER="Wizzard"
 +
  WUSR="www-data"
 +
  WGRP="www-data"
 +
  P1=""
 +
  P2=""
 +
  BASES_S="/data/wiz/Wizzard/bases-v7"              # Bases location on server
 +
  GW_DIR_S="/data/src/geneweb-7.00/GeneWeb-7.00/gw"    # Binaries (gwd, gwc, ...) on Server
 +
  LOGS="/data/wiz/Wizzard"
 +
else
 +
  echo "Bad remote server definition"
 +
  exit
 +
fi
 +
 
 +
ADDRESS="my.address@gmail.com"  # to which error report will be sent
 
LANGUE="fr"
 
LANGUE="fr"
 
BASE=""
 
BASE=""
 
 
BASES_PC="$HOME/Genea/GeneWeb-Bases"            # Bases location on PC
 
BASES_PC="$HOME/Genea/GeneWeb-Bases"            # Bases location on PC
BASES_SERVER="~/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/bases"    # Bases location on server
+
GW_DIR_PC="$HOME/Genea/GeneWeb/GeneWeb-7.00-Mac/gw"  # Binaries (gwd, gwc, ...) location on PC
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()
 
check_errs()
Line 43: Line 90:
 
FILES=$2
 
FILES=$2
  
if [ "$BASE" = "" ] || [ "$BASE" = "-h" ] || [ "$BASE" = "-help" ]
+
if [ "$BASE" = "" ] || [ "$BASE" = "-h" ] || [ "$BASE" = "-help" ] ; then
then
+
 
   echo "Usage : update-base base_name [ images | src ]"
 
   echo "Usage : update-base base_name [ images | src ]"
 
   echo "    if 'images' or 'src' are present, only the corresponding folders will"
 
   echo "    if 'images' or 'src' are present, only the corresponding folders will"
Line 51: Line 97:
 
fi
 
fi
  
 
+
if [ "$FILES" = "images" ] || [ "$FILES" = "src" ] ; then
if [ "$FILES" = "images" ] || [ "$FILES" = "src" ]  
+
then
+
 
   # copy images files to server
 
   # copy images files to server
 
   echo "Sending $FILES for $BASE to $SERVER"
 
   echo "Sending $FILES for $BASE to $SERVER"
 
   cd $BASES_PC/$FILES
 
   cd $BASES_PC/$FILES
   sed s:BASES_SERVER:$BASES_SERVER:g < $HOME/Genea/remote-files.txt | \
+
   sed s:BASES_S:$BASES_S:g < $HOME/Genea/remote-files.txt | \
 
   sed s:BASE:$BASE:g | \
 
   sed s:BASE:$BASE:g | \
 +
  sed s:HOME_S:$HOME_S:g | \
 +
  sed s:WUSR:$WUSR:g | \
 +
  sed s:WGRP:$WGRP:g | \
 +
  sed s:LOGS:$LOGS:g | \
 
   sed s:ADDRESS:$ADDRESS:g  > ./remote.sh
 
   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
   scp ./$BASE-files.tar $USER@$SERVER:$BASE-files.tar
+
   scp $P2 ./$BASE-files.tar $USER@$SERVER:$HOME_S
   ssh $USER@$SERVER "tar xf $BASE-files.tar; chmod +x ./remote.sh; ./remote.sh"
+
   ssh $P1 $USER@$SERVER "cd $HOME_S; tar xf $BASE-files.tar; chmod +x ./remote.sh; ./remote.sh"
 
   rm -f ./remote.sh
 
   rm -f ./remote.sh
 
   echo "Done sending $FILES for $BASE to $SERVER"
 
   echo "Done sending $FILES for $BASE to $SERVER"
Line 69: Line 117:
 
fi
 
fi
  
 
+
#mot="o" # default is "oui"
 
+
HEB=${HEB:-"ovh"}
mot="n" # default is "no"
+
 
# Verify that the images and src/images folder are up to date.  
 
# Verify that the images and src/images folder are up to date.  
if [ $LANGUE = "fr" ]  
+
if [ $LANGUE = "fr" ] ; then
then
+
 
   echo "Cette procédure ne met pas à jour les deux dossiers images"
 
   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 "Le message de compte-rendu signale les différences dans les dossiers images du serveur et du PC"
   echo "Vous pouvez cependant continuer"
+
   echo "Vous pouvez cependant continuer."
 +
  echo "Executez ./update-base basename images et/ou ./update-base basename src pour copier ces dossiers"
 
   echo "Pensez aussi à installer $BASE.gwf sur votre serveur"
 
   echo "Pensez aussi à installer $BASE.gwf sur votre serveur"
   echo "Continuer? [o/n]"
+
   #read -p "Continuer (o/n)[o] :" mot
 
else
 
else
 
   echo "This procedure does not update the two images folders"
 
   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 "It returns through mail a report indicating differences between the server and the PC"
 +
  echo "Run ./update-base basename images and/or ./update-base basename src to upload a fresh copy of these folders."
 
   echo "You may nonetheless proceed"
 
   echo "You may nonetheless proceed"
 
   echo "Make sure you install the proper $BASE.gwf parameters on your server"
 
   echo "Make sure you install the proper $BASE.gwf parameters on your server"
   echo "Proceed? [y/n]"
+
   #read -p "Proceed? (y/n)[y] :" mot
fi
+
read mot
+
if [ "$mot" = "n" ] # or "$mot" = ""
+
then
+
  exit
+
 
fi
 
fi
 +
 +
#if [ "$mot" = "y" ] ; then
 +
#  mot="o"
 +
#fi
 +
#mot=${mot:-"o"}
 +
#if [ "$mot" = "n" ] ; then # or "$mot" = ""
 +
#  exit
 +
#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
+
$GW_DIR_PC/gwu ./$BASE -o $BASE.gw > comm.log
 
check_errs $? "Gwu failed on $BASE, see $BASES_PC/comm.log for details "
 
check_errs $? "Gwu failed on $BASE, see $BASES_PC/comm.log for details "
  
 
# Take a copy of current change history to send to server
 
# Take a copy of current change history to send to server
if [ -f ./$BASE.gwb/history ]
+
if [ -f $BASES_PC/$BASE.gwb/history ] ; then
then
+
   cp -f $BASES_PC/$BASE.gwb/history .
   cp -f ./$BASE.gwb/history .
+
 
else
 
else
 
   touch ./history
 
   touch ./history
 +
fi
 +
 +
# tags.txt is where gwd.arg says it should be !!
 +
if [ -f $GW_DIR_PC/tags.txt ] ; then
 +
  cp -f $GW_DIR_PC/tags.txt .
 +
else
 +
  touch ./tags.txt
 
fi
 
fi
  
 
# Create a content listing for the images and person images folders
 
# Create a content listing for the images and person images folders
 
cd  $BASES_PC/src/$BASE
 
cd  $BASES_PC/src/$BASE
ls > $BASES_PC/ls-src-files.txt
+
ls *.txt > $BASES_PC/ls-src-files.txt
 
cd  $BASES_PC/src/$BASE/images
 
cd  $BASES_PC/src/$BASE/images
ls > $BASES_PC/ls-images.txt
+
ls *.jpg > $BASES_PC/ls-images.txt
 
cd  $BASES_PC/images/$BASE
 
cd  $BASES_PC/images/$BASE
ls > $BASES_PC/ls-personnes.txt
+
ls *.jpg > $BASES_PC/ls-personnes.txt
  
 
cd $BASES_PC
 
cd $BASES_PC
+
 
 +
aujourdhui=`date`
 +
sed s/basename/$BASE/g < $BASES_PC/etc/trl-template.txt > $BASES_PC/etc/trl-tmp.txt
 +
sed s/baseversion/"$aujourdhui"/g < $BASES_PC/etc/trl-tmp.txt > $BASES_PC/etc/trl-tmp2.txt
 +
mv $BASES_PC/etc/trl-tmp2.txt $BASES_PC/etc/$BASE/trl.txt
 +
rm $BASES_PC/etc/trl-tmp.txt
 +
cp $BASES_PC/etc/$BASE/trl.txt ./trl.txt
 +
 
 
# Build a command file to be executed on the server
 
# Build a command file to be executed on the server
sed s:BASES_SERVER:$BASES_SERVER:g < $HOME/Genea/remote-base.txt | \
+
sed s:GW_DIR_S:$GW_DIR_S:g < $HOME/Genea/remote-base.txt | \
 +
sed s:BASES_S:$BASES_S:g | \
 
sed s:BASE:$BASE:g | \
 
sed s:BASE:$BASE:g | \
sed s:BIN_DIR_SERVER:$BIN_DIR_SERVER:g | \
+
sed s:HOME_S:$HOME_S:g | \
 +
sed s:WUSR:$WUSR:g | \
 +
sed s:WGRP:$WGRP:g | \
 +
sed s:LOGS:$LOGS:g | \
 
sed s:ADDRESS:$ADDRESS:g > ./remote.sh
 
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)"
+
# suppressed trl.txt
tar cf ./$BASE.tar ./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt
+
echo "Building remote.tar (./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt ./tags.txt)"
 +
tar cf ./$BASE.tar         ./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt ./tags.txt  
  
 
echo "Sending remote.tar to $SERVER"
 
echo "Sending remote.tar to $SERVER"
scp ./$BASE.tar $USER@$SERVER:$BASE.tar
+
scp $P2 ./$BASE.tar $USER@$SERVER:$HOME_S
 
echo "$BASE.tar sent"
 
echo "$BASE.tar sent"
 
# Execute a remote command on the server
 
# Execute a remote command on the server
 
#    un-tar the file just sent, make remote.sh executable and execute it
 
#    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"
+
ssh $P1 $USER@$SERVER "cd $HOME_S; tar xf $BASE.tar; chmod +x ./remote.sh; ./remote.sh"
 
echo "Tar xf done; remote.sh executed"
 
echo "Tar xf done; remote.sh executed"
  
 
echo "Cleanup (on local machine)"
 
echo "Cleanup (on local machine)"
rm -f ./remote.* ./history ./ls-*.txt
+
rm -f ./$BASE.tar ./remote.* ./history ./ls-*.txt ./tags.txt ./._tags.txt ./trl.txt  
  
 
echo "Done updating $BASE on $SERVER"
 
echo "Done updating $BASE on $SERVER"
 +
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 19:42, 24 November 2016


#!/bin/sh
# Version 2, 24/11/2016, Henri
 
# Usage : update-base base_name [ images | src ]
 
# This shell script executes scp and ssh commands with the remote server
# To facilitate these commands, you should install a pair of private/public keys on both machines
# See "how to create a key pair" on the web
 
# If you have not installed your public key on your server, each ssh request will prompt you for a password
 
# An alternative is to supply your password along with the request
# by adding ":password" after username in each occurence of USER@SERVER 
# Be aware that in this case, password is sent in cleartext !!
 
S=tuxf
 
if [ "$S" = "tuxf" ] 
then
  SERVER="ssh.tuxfamily.org"
  HOME_S="/home/geneweb/geneweb-repository/demo"
  USER="aaaaa"
  WUSR="www-data"
  WGRP="www-data"
  P1=""
  P2=""
  BASES_S="/home/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/gw7/bases"    # Bases location on server
  GW_DIR_S="/home/geneweb/demo.geneweb.tuxfamily.org-web/htdocs/gw7/gw"   # Binaries (gwd, gwc, ...) on Server
elif [ "$S" = "ovh" ] 
then
 SERVER="vps664433.ovh.net"
 HOME_S="/root"
 USER="root"
 WUSR="www-data"
 WGRP="www-data"
 P1=""
 P2=""
 BASES_S="~/GW/bases7"               # Bases location on server hgouraud.fr
 GW_DIR_S="~/GW/GeneWeb-7.0x/gw"     # Binaries (gwd, gwc, ...) on Server
elif [ "$S" = "phpn" ] 
then
  SERVER="p5678.phpnet.org"
  HOME_S=""
  USER="p5678"
  WUSR="www-data"
  WGRP="www-data"
  P1="-p 25678"
  P2="-P 25678"
  BASES_S="~/GeneWeb/bases"               # Bases location on server
  GW_DIR_S="~/GeneWeb/geneweb-7.00/gw"    # Binaries (gwd, gwc, ...) on Server
elif [ "$S" = "roglo" ] 
then
  SERVER="roglo.eu"
  HOME_S="/data/wiz/Wizzard"
  USER="Wizzard"
  WUSR="www-data"
  WGRP="www-data"
  P1=""
  P2=""
  BASES_S="/data/wiz/Wizzard/bases-v7"               # Bases location on server
  GW_DIR_S="/data/src/geneweb-7.00/GeneWeb-7.00/gw"    # Binaries (gwd, gwc, ...) on Server
  LOGS="/data/wiz/Wizzard"
else 
  echo "Bad remote server definition"
  exit
fi
 
ADDRESS="my.address@gmail.com"  # to which error report will be sent
LANGUE="fr"
BASE=""
BASES_PC="$HOME/Genea/GeneWeb-Bases"             # Bases location on PC
GW_DIR_PC="$HOME/Genea/GeneWeb/GeneWeb-7.00-Mac/gw"   # Binaries (gwd, gwc, ...) location on PC
 
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_S:$BASES_S:g < $HOME/Genea/remote-files.txt | \
  sed s:BASE:$BASE:g | \
  sed s:HOME_S:$HOME_S:g | \
  sed s:WUSR:$WUSR:g | \
  sed s:WGRP:$WGRP:g | \
  sed s:LOGS:$LOGS:g | \
  sed s:ADDRESS:$ADDRESS:g  > ./remote.sh
  touch ./$FILES.tmp
  tar cf ./$BASE-files.tar $BASE/ ./remote.sh ./$FILES.tmp
  scp $P2 ./$BASE-files.tar $USER@$SERVER:$HOME_S
  ssh $P1 $USER@$SERVER  "cd $HOME_S; 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="o" # default is "oui"
HEB=${HEB:-"ovh"}
# 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 "Executez ./update-base basename images et/ou ./update-base basename src pour copier ces dossiers"
  echo "Pensez aussi à installer $BASE.gwf sur votre serveur"
  #read -p "Continuer (o/n)[o] :" mot
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 "Run ./update-base basename images and/or ./update-base basename src to upload a fresh copy of these folders."
  echo "You may nonetheless proceed"
  echo "Make sure you install the proper $BASE.gwf parameters on your server"
  #read -p "Proceed? (y/n)[y] :" mot
fi
 
#if [ "$mot" = "y" ] ; then
#  mot="o"
#fi
#mot=${mot:-"o"}
#if [ "$mot" = "n" ] ; then # or "$mot" = "" 
#  exit
#fi
 
echo "Producing a fresh $BASE.gw in $BASES_PC (gwu)"
cd $BASES_PC
$GW_DIR_PC/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
if [ -f $BASES_PC/$BASE.gwb/history ] ; then
  cp -f $BASES_PC/$BASE.gwb/history .
else
  touch ./history
fi
 
# tags.txt is where gwd.arg says it should be !!
if [ -f $GW_DIR_PC/tags.txt ] ; then
  cp -f $GW_DIR_PC/tags.txt .
else
  touch ./tags.txt
fi
 
# Create a content listing for the images and person images folders
cd   $BASES_PC/src/$BASE
ls *.txt > $BASES_PC/ls-src-files.txt
cd   $BASES_PC/src/$BASE/images
ls *.jpg > $BASES_PC/ls-images.txt
cd   $BASES_PC/images/$BASE
ls *.jpg > $BASES_PC/ls-personnes.txt
 
cd $BASES_PC
 
aujourdhui=`date`
sed s/basename/$BASE/g < $BASES_PC/etc/trl-template.txt > $BASES_PC/etc/trl-tmp.txt
sed s/baseversion/"$aujourdhui"/g < $BASES_PC/etc/trl-tmp.txt > $BASES_PC/etc/trl-tmp2.txt
mv $BASES_PC/etc/trl-tmp2.txt $BASES_PC/etc/$BASE/trl.txt
rm $BASES_PC/etc/trl-tmp.txt
cp $BASES_PC/etc/$BASE/trl.txt ./trl.txt
 
# Build a command file to be executed on the server
sed s:GW_DIR_S:$GW_DIR_S:g < $HOME/Genea/remote-base.txt | \
sed s:BASES_S:$BASES_S:g | \
sed s:BASE:$BASE:g | \
sed s:HOME_S:$HOME_S:g | \
sed s:WUSR:$WUSR:g | \
sed s:WGRP:$WGRP:g | \
sed s:LOGS:$LOGS:g | \
sed s:ADDRESS:$ADDRESS:g > ./remote.sh
 
# suppressed trl.txt
echo "Building remote.tar (./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt ./tags.txt)"
tar cf ./$BASE.tar         ./remote.sh ./$BASE.gw ./history ./ls-personnes.txt ./ls-images.txt ./ls-src-files.txt ./tags.txt 
 
echo "Sending remote.tar to $SERVER"
scp $P2 ./$BASE.tar $USER@$SERVER:$HOME_S
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 $P1 $USER@$SERVER "cd $HOME_S; tar xf $BASE.tar; chmod +x ./remote.sh; ./remote.sh"
echo "Tar xf done; remote.sh executed"
 
echo "Cleanup (on local machine)"
rm -f ./$BASE.tar ./remote.* ./history ./ls-*.txt ./tags.txt ./._tags.txt ./trl.txt 
 
echo "Done updating $BASE on $SERVER"