From 148a8b110ca52a55792fe923bc7ad36041c8b2b0 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Mon, 19 Oct 2020 14:25:13 +0200 Subject: [PATCH] Add blind-update.sh --- distillery/blind-update-all.sh | 16 ++++++++++++++++ distillery/blind-update.sh | 25 +++++++++++++++++++++++++ distillery/lib/20_sql.sh | 5 +++++ 3 files changed, 46 insertions(+) create mode 100644 distillery/blind-update-all.sh create mode 100644 distillery/blind-update.sh diff --git a/distillery/blind-update-all.sh b/distillery/blind-update-all.sh new file mode 100644 index 0000000..aedab13 --- /dev/null +++ b/distillery/blind-update-all.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +# read the lib/shared.sh and read the slug argument. +DISABLE_LOG=1 +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$DIR" +source "$DIR/lib/lib.sh" +DISABLE_LOG=0 + +# update all the instances +for slug in $(sql_bookkeep_list_updateable); do + log_info "=> /bin/bash $DIR/blind-update.sh '$slug'" + /bin/bash "$DIR/blind-update.sh" "$slug"; +done + diff --git a/distillery/blind-update.sh b/distillery/blind-update.sh new file mode 100644 index 0000000..81cabc8 --- /dev/null +++ b/distillery/blind-update.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +# read the lib/shared.sh and read the slug argument. +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +cd "$DIR" +source "$DIR/lib/lib.sh" +require_slug_argument + + +# if the site doesn't exist, I can't open a shell. +if ! sql_bookkeep_exists "$SLUG"; then + log_error "=> Site '$SLUG' does not exist in bookeeping table. " + echo "I can't rebuild it. " + exit 1 +fi; + +# Read everything from the database +read -r INSTANCE_BASE_DIR MYSQL_DATABASE MYSQL_USER GRAPHDB_REPO GRAPHDB_USER <<< "$(sql_bookkeep_load "${SLUG}" "filesystem_base,sql_database,sql_user,graphdb_repository,graphdb_user" | tail -n +2)" + +# cd into the right directory +cd "$INSTANCE_BASE_DIR" + +# and open a www-data shell +docker-compose exec barrel /user_shell.sh /utils/blind_update.sh \ No newline at end of file diff --git a/distillery/lib/20_sql.sh b/distillery/lib/20_sql.sh index 30c1a8b..0c21ae6 100644 --- a/distillery/lib/20_sql.sh +++ b/distillery/lib/20_sql.sh @@ -92,4 +92,9 @@ function sql_bookkeep_load() { # 'sql_bookkeep_list' lists all slugs from the bookkeeping table function sql_bookkeep_list() { dockerized_mysql -D "$DISTILLERY_BOOKKEEPING_DATABASE" -e "SELECT slug FROM \`$DISTILLERY_BOOKKEEPING_TABLE\`; " | tail -n +2 +} + +# 'sql_bookkeep_list' lists all slugs from the bookkeeping table which should be automatically updated +function sql_bookkeep_list_updateable() { + dockerized_mysql -D "$DISTILLERY_BOOKKEEPING_DATABASE" -e "SELECT slug FROM \`$DISTILLERY_BOOKKEEPING_TABLE\` WHERE auto_blind_update_enabled=1; " | tail -n +2 } \ No newline at end of file