#!/bin/bash -e exec 100> $HOME/homepage.lock flock 100 src=/srv/data/tsc-cloud/homepage/hugo-page dst=/srv/http/tsc/hugo cmd="$SSH_ORIGINAL_COMMAND" # echo "$cmd" publishToStage= publishToProduction=y parseCMD() { while [ $# -gt 0 ] do part="$1" shift case "$part" in stage) publishToStage=y publishToProduction= ;; *) echo "Unknown command $part" exit 1 ;; esac done } parseCMD $cmd doPublishToStage() { rsync -ah --delete --delete-delay public/ "$dst/" } doPublishToProduction() { rclone sync --stats 3s -c public/ ionos:/ rclone rmdirs ionos:/ } # exit 1 cd "$src" echo "Fetching the latest git commits" git fetch echo "Switching tothe latest branch commit" git reset --hard origin/develop echo "Updating NPM packages" npm ci echo "Dropping old public folder" rm -rf public echo "Building the page" npm run build echo "Synchronizing files to web server" if [ -n "$publishToStage" ] then echo "Pushing to stage" time doPublishToStage fi if [ -n "$publishToProduction" ] then echo "Publishing to production server" time doPublishToProduction fi echo "Deployment done"