From 2d20e7e86fa8f8e8f94d6df33d881a15d711a37e Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 9 Feb 2024 02:19:04 +0200 Subject: [PATCH] initial commit --- sync.sh | 21 ++++++++++++ tmp/.gitignore | 2 ++ update.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ upgrade.sh | 17 ++++++++++ 4 files changed, 127 insertions(+) create mode 100644 sync.sh create mode 100644 tmp/.gitignore create mode 100755 update.sh create mode 100644 upgrade.sh diff --git a/sync.sh b/sync.sh new file mode 100644 index 0000000..4ebd3fd --- /dev/null +++ b/sync.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Sync local database with howto-db repository + +# ========================================================================= +# Configuration +# ========================================================================= + +cd /home/bdoku/howto-db + +CommitMessage=$(date -d "$date -1 days" +"%F")-23-30 + +# ========================================================================= +# Begin upgrade +# ========================================================================= + +git add . + +git commit -m $CommitMessage + +git push diff --git a/tmp/.gitignore b/tmp/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/tmp/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..e8b5abb --- /dev/null +++ b/update.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# Download latest howto database to destination directory +# Features: +# - check for valid SHA-256 +# - skip download on remote data match local version (up to date) + +# ========================================================================= +# Configuration +# ========================================================================= + +ThisDir="/home/bdoku/howtools" +DataDir="/home/bdoku/howto-db" + +RemoteHost="http://[222:a8e4:50cd:55c:788e:b0a5:4e2f:a92c]" +RemoteVersion=$(date -d "$date -1 days" +"%F")-23-30 + +RemoteDataURL="${RemoteHost}/howto-wiki_${RemoteVersion}.tar.gz" +RemoteSHA256URL="${RemoteHost}/howto-wiki_${RemoteVersion}.tar.gz.sha-256" + +RemoteSHA256TMP="${ThisDir}/tmp/remote.sha-256" +LocalSHA256TMP="${ThisDir}/tmp/local.sha-256" +LocalDataTMP="${ThisDir}/tmp/data.tar.gz" + +# ========================================================================= +# Compare versions +# ========================================================================= + +# Get remote SHA-256 +wget $RemoteSHA256URL -O $RemoteSHA256TMP + +# Remote SHA-256 valid +RemoteSHA256=$(<$RemoteSHA256TMP) + +if ! [[ ${RemoteSHA256:0:64} =~ ^([0-9a-f]{64})$ ]]; then + echo Invalid remote SHA-256 + exit +fi + +# Get local SHA-256 +if [[ -f $LocalSHA256TMP ]]; then + LocalSHA256=$(<$LocalSHA256TMP) +else + LocalSHA256="" +fi + +# Compare versions +if [[ ${LocalSHA256:0:64} == ${RemoteSHA256:0:64} ]]; then + echo "DB up to date!" + exit +fi + +# ========================================================================= +# SHA-256 versions mismatch, begin update +# ========================================================================= + +echo "Begin update..." + +wget $RemoteDataURL -O $LocalDataTMP + +# Generate SHA-256 +sha256sum $LocalDataTMP > $LocalSHA256TMP + +if [[ -f $LocalSHA256TMP ]]; then + LocalSHA256=$(<$LocalSHA256TMP) +else + LocalSHA256="" +fi + +# Check for download contain valid SHA-256 +if ! [[ ${LocalSHA256:0:64} =~ ^([0-9a-f]{64})$ ]]; then + echo Invalid local SHA-256 + exit +fi + +# Check for download match remote SHA-256 +if ! [[ ${LocalSHA256:0:64} == ${RemoteSHA256:0:64} ]]; then + echo "SHA-256 mismatch!" + exit +fi + +# Begin update +echo "Unpack downloaded data to destination..." + +tar -xvf $LocalDataTMP -C $DataDir + +echo "Update completed!" diff --git a/upgrade.sh b/upgrade.sh new file mode 100644 index 0000000..5e30cf8 --- /dev/null +++ b/upgrade.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Download latest β-Doku codebase and upgrade composer dependencies + +# ========================================================================= +# Configuration +# ========================================================================= + +cd /home/bdoku/bdoku + +# ========================================================================= +# Begin upgrade +# ========================================================================= + +git pull + +composer update