From a1bfd25b29d6fea20872dc4a571c6e9e4c20a805 Mon Sep 17 00:00:00 2001 From: TSC competition notification bot Date: Wed, 14 Feb 2024 15:48:34 +0100 Subject: [PATCH] Create initial commands for automations --- mailpipe | 56 +++++++++++++++++++++++++++++++++++ update-cron.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100755 mailpipe create mode 100755 update-cron.sh diff --git a/mailpipe b/mailpipe new file mode 100755 index 0000000..23cfad5 --- /dev/null +++ b/mailpipe @@ -0,0 +1,56 @@ +#!/bin/bash -e + +logfile=$(mktemp) +exec &>> $logfile +exec 100> $HOME/homepage.lock + +#pwd +#whoami + +file=$(mktemp) +cat > $file + +finish() { + code=$? + + cat $logfile >> /tmp/mailpipe.log + + if [ $code -gt 0 ] + then + sendmail vizesportwart@tsc-vfl.de << EOF +From: TSC Homepage Bot +To: Vizesportwart +Date: $(date) +Subject: Failed to parse ESV mail + +The parsing of the competition notification failed. Please see also the logs! + +The output of the script: + +$(cat $logfile) + +The offending mail was this one: + +$(cat $file) +EOF + fi + exit $? +} +trap finish EXIT + +flock 100 + +cd $HOME/hugo-page +git fetch +git reset --hard origin/develop + +. ~/venv-homepage/bin/activate +pip install -r scripts/read-competition-notification/requirements.txt + +./scripts/read-competition-notification/run.sh -o content/turniermeldung --read-mbox $file -vv + +git add content/turniermeldung +git commit -m "Automatic commit to create new competition notification" +git push origin develop + +rm $file diff --git a/update-cron.sh b/update-cron.sh new file mode 100755 index 0000000..ec17a62 --- /dev/null +++ b/update-cron.sh @@ -0,0 +1,79 @@ +#!/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" +