Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions tools/disable_restricted_access.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions tools/restricted_upadate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tools/update_restricted_access_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <target_item_type_property_id> <update_type>")
sys.exit(1)
4 changes: 2 additions & 2 deletions tools/verify_restricted_update.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading