Uploading a base on a shared hosting account
From GeneWeb
![]() |
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 "ssh with key pairs" on the web # 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 # as in my_user_name:my_password@my_server_name # Be aware that password is sent in cleartext !! SERVER="your server name" USER="your user name on your server" ADDRESS="your e-mail address" # to which error report will be sent LANGUE="fr" BASE="" VERS="7.00-Mac" # GeneWeb version VERS_S="7.00" # GeneWeb version on server GENEA="$HOME/Genea" # Home for genealogy files BASES_PC="$GENEA/GeneWeb-Bases" # Bases location on PC BASES_SERVER="GeneWeb/bases" # Bases location on server BIN_DIR="$GENEA/GeneWeb/GeneWeb-$VERS/gw" # Binaries (gwd, gwc, ...) location 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/BASE/$BASE/g < $GENEA/remote-files.txt | \ 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 "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 "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/BASE/$BASE/g < $GENEA/remote-base.txt | \ sed s/VERS_S/$VERS_S/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" 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"