Uploading a base on a shared hosting account
Language: | English |
---|
<syntaxhighlight lang="bash">
- !/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
- 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 !!
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
if [ -f ./$BASE.gwb/history ] then
cp -f ./$BASE.gwb/history .
else
touch ./history
fi
- 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" </syntaxhighlight