From b90c16708d231d048249b550a220c69d0860482d Mon Sep 17 00:00:00 2001 From: ryoya-hayase Date: Fri, 17 Jul 2026 18:59:47 +0900 Subject: [PATCH] Improvements to the switch script --- tools/disable_restricted_access.sh | 40 ++++++++++++++++++++-- tools/restricted_upadate.sh | 35 +++++++++++++++++++ tools/update_restricted_access_property.py | 3 ++ tools/verify_restricted_update.sh | 4 +-- 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/tools/disable_restricted_access.sh b/tools/disable_restricted_access.sh index c5411cf37b..63310ac00e 100644 --- a/tools/disable_restricted_access.sh +++ b/tools/disable_restricted_access.sh @@ -13,14 +13,39 @@ PG_MASTER=$(kubectl get po -n weko3pg -l spilo-role=master --no-headers | awk '{ DATABASE=$(echo ${REPO} | tr .- _) GITHUB_PATH=https://raw.githubusercontent.com/RCOSDP/weko/refs/heads/${BRANCH} -set -euo pipefail +###set -euo pipefail IFS=$'\n\t' -trap 'rc=$?; echo "Error: ${BASH_COMMAND} (line $LINENO) exited with ${rc}" >&2; exit ${rc}' ERR +###trap 'rc=$?; echo "Error: ${BASH_COMMAND} (line $LINENO) exited with ${rc}" >&2; exit ${rc}' ERR ###SETTING_FILE=scripts/instance.cfg SETTING_FILE=${CONFIG_PATH}/${REPO}/instance.cfg RESTRICTED_ACCESS_PROPERTY=30015 +FILE_ERRORS=0 +if [ ! -f "$SETTING_FILE" ]; then + echo "Error: ${SETTING_FILE} not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "scripts/demo/disable_restricted_access.sql" ]; then + echo "Error: scripts/demo/disable_restricted_access.sql not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "tools/update_restricted_access_property.py" ]; then + echo "Error: tools/update_restricted_access_property.py not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "tools/verify_restricted_update.sh" ]; then + echo "Error: tools/verify_restricted_update.sh not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "tools/verify_restricted_records.py" ]; then + echo "Error: tools/verify_restricted_records.py not found" >&2 + FILE_ERRORS=1 +fi +if [ $FILE_ERRORS -ne 0 ]; then + exit 2 +fi + # echo Backup file # cp $SETTING_FILE `date +${SETTING_FILE}_%Y%m%d` @@ -100,15 +125,24 @@ fi ###docker-compose exec postgresql psql -U invenio -d invenio -v ON_ERROR_STOP=1 -f /tmp/disable_restricted_access.sql kubectl cp -n weko3pg -c postgres scripts/demo/disable_restricted_access.sql ${PG_MASTER}:/tmp/disable_restricted_access.sql kubectl exec -n weko3pg -c postgres ${PG_MASTER} -- psql -U invenio -d ${DB} -v ON_ERROR_STOP=1 -f /tmp/disable_restricted_access.sql +if [ $? -ne 0 ]; then + echo "Error: Failed to execute disable_restricted_access.sql" >&2 + kubectl exec -n weko3pg -c postgres ${PG_MASTER} -- rm /tmp/disable_restricted_access.sql + exit 1 +fi kubectl exec -n weko3pg -c postgres ${PG_MASTER} -- rm /tmp/disable_restricted_access.sql ###docker-compose exec web invenio shell tools/update_restricted_access_property.py $RESTRICTED_ACCESS_PROPERTY disable kubectl exec -n weko3 -c web ${WEB_POD} -- invenio shell tools/update_restricted_access_property.py $RESTRICTED_ACCESS_PROPERTY disable +if [ $? -ne 0 ]; then + echo "Error: Failed to execute update_restricted_access_property.py" >&2 + exit 1 +fi # verify the update tools/verify_restricted_update.sh $SETTING_FILE False ###docker compose exec web invenio shell tools/verify_restricted_records.py disable -kubectl exec -n weko3 -c web ${WEB_POD} -- invenio shell tools/verify_restricted_records.py enable +kubectl exec -n weko3 -c web ${WEB_POD} -- invenio shell tools/verify_restricted_records.py disable # docker-compose exec web bash -c "jinja2 /code/scripts/instance.cfg > /home/invenio/.virtualenvs/invenio/var/instance/invenio.cfg" # docker-compose down diff --git a/tools/restricted_upadate.sh b/tools/restricted_upadate.sh index 1d4704bb54..7336fd83a0 100755 --- a/tools/restricted_upadate.sh +++ b/tools/restricted_upadate.sh @@ -21,6 +21,32 @@ IFS=$'\n\t' SETTING_FILE=${CONFIG_PATH}/${REPO}/instance.cfg RESTRICTED_ACCESS_PROPERTY=30015 +# check if required files exist +FILE_ERRORS=0 +if [ ! -f "$SETTING_FILE" ]; then + echo "Error: ${SETTING_FILE} not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "scripts/demo/resticted_access.sql" ]; then + echo "Error: scripts/demo/resticted_access.sql not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "tools/update_restricted_access_property.py" ]; then + echo "Error: tools/update_restricted_access_property.py not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "tools/verify_restricted_update.sh" ]; then + echo "Error: tools/verify_restricted_update.sh not found" >&2 + FILE_ERRORS=1 +fi +if [ ! -f "tools/verify_restricted_records.py" ]; then + echo "Error: tools/verify_restricted_records.py not found" >&2 + FILE_ERRORS=1 +fi +if [ $FILE_ERRORS -ne 0 ]; then + exit 2 +fi + # echo Backup file #cp $SETTING_FILE `date +${SETTING_FILE}_%Y%m%d` @@ -111,10 +137,19 @@ fi ###docker-compose exec postgresql psql -U invenio -d invenio -v ON_ERROR_STOP=1 -f /tmp/resticted_access.sql kubectl cp -n weko3pg -c postgres scripts/demo/resticted_access.sql ${PG_MASTER}:/tmp/resticted_access.sql kubectl exec -n weko3pg -c postgres ${PG_MASTER} -- psql -U invenio -d ${DB} -v ON_ERROR_STOP=1 -f /tmp/resticted_access.sql +if [ $? -ne 0 ]; then + echo "Error: Failed to execute resticted_access.sql" >&2 + kubectl exec -n weko3pg -c postgres ${PG_MASTER} -- rm /tmp/resticted_access.sql + exit 1 +fi kubectl exec -n weko3pg -c postgres ${PG_MASTER} -- rm /tmp/resticted_access.sql ###docker-compose exec web invenio shell tools/update_restricted_access_property.py $RESTRICTED_ACCESS_PROPERTY enable kubectl exec -n weko3 -c web ${WEB_POD} -- invenio shell tools/update_restricted_access_property.py $RESTRICTED_ACCESS_PROPERTY enable +if [ $? -ne 0 ]; then + echo "Error: Failed to execute update_restricted_access_property.py" >&2 + exit 1 +fi # verify the update tools/verify_restricted_update.sh $SETTING_FILE True diff --git a/tools/update_restricted_access_property.py b/tools/update_restricted_access_property.py index 49674ee5b0..cbfdad028c 100644 --- a/tools/update_restricted_access_property.py +++ b/tools/update_restricted_access_property.py @@ -116,3 +116,6 @@ def _check_restricted_item_type(item_type): target_item_type_property_id = int(args[1]) update_type = args[2] main(target_item_type_property_id, update_type) + else: + print("This script requires two arguments: ") + sys.exit(1) diff --git a/tools/verify_restricted_update.sh b/tools/verify_restricted_update.sh index 07267814d2..8e371afbc5 100755 --- a/tools/verify_restricted_update.sh +++ b/tools/verify_restricted_update.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -set -euo pipefail +###set -euo pipefail IFS=$'\n\t' -trap 'rc=$?; echo "Error: ${BASH_COMMAND} (line ${LINENO}) exited with ${rc}" >&2; exit ${rc}' ERR +###trap 'rc=$?; echo "Error: ${BASH_COMMAND} (line ${LINENO}) exited with ${rc}" >&2; exit ${rc}' ERR SETTING_FILE="$1" ENABLE_FLAG="$2"