From 5da08eab262e477ed2d0d59b01d49a11e73d2cbd Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Tue, 14 Mar 2023 11:37:33 -0400 Subject: [PATCH] Add --project scope. --- defaults.sh | 2 +- deployment/destroy.sh | 38 ++++++++++++++++++++++++++++++++++++-- deployment/project_env.sh | 7 +------ deployment/update.sh | 16 ++++++++++++++++ 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/defaults.sh b/defaults.sh index 93b99bd..438f099 100755 --- a/defaults.sh +++ b/defaults.sh @@ -101,4 +101,4 @@ export PRIMARY_DOMAIN= # this is the git commit of the project/ sub git repo. # used in the migration script to switch into past for backup # then back to present (TARGET_PROJECT_GIT_COMMIT) for restore. -export TARGET_PROJECT_GIT_COMMIT=2411067cd168aaa475f56179db26301b35194ce2 +export TARGET_PROJECT_GIT_COMMIT=72c4df897af0a054ad938a5badf94cd13ef45ec5 diff --git a/deployment/destroy.sh b/deployment/destroy.sh index 0bd08c8..584e486 100755 --- a/deployment/destroy.sh +++ b/deployment/destroy.sh @@ -22,6 +22,23 @@ if [ "$RESPONSE" != "y" ]; then exit 0 fi +USER_TARGET_PROJECT= + +# grab any modifications from the command line. +for i in "$@"; do + case $i in + --project=*) + USER_TARGET_PROJECT="${i#*=}" + shift + ;; + + *) + echo "Unexpected option: $1" + exit 1 + ;; + esac +done + . ../defaults.sh . ./remote_env.sh @@ -30,8 +47,25 @@ for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do NO_PARENS="${PROJECT_CHAIN:1:${#PROJECT_CHAIN}-2}" PROJECT_PREFIX=$(echo "$NO_PARENS" | cut -d'|' -f1) BITCOIN_CHAIN=$(echo "$NO_PARENS" | cut -d'|' -f2) - export PROJECT_PREFIX="$PROJECT_PREFIX" - export BITCOIN_CHAIN="$BITCOIN_CHAIN" + + PROJECT_NAME="$PROJECT_PREFIX-$BITCOIN_CHAIN" + PROJECT_PATH="$PROJECTS_DIR/$PROJECT_NAME" + + # if the user sets USER_TARGET_PROJECT, let's ensure the project exists. + if [ -n "$USER_TARGET_PROJECT" ]; then + if ! lxc project list | grep -q "$USER_TARGET_PROJECT"; then + echo "ERROR: the project does not exist! Nothing to destroy." + exit 1 + fi + + if [ "$PROJECT_NAME" != "$USER_TARGET_PROJECT" ]; then + echo "INFO: Skipping project '$PROJECT_NAME' since the system owner has used the --project switch." + exit + fi + fi + + export PROJECT_NAME="$PROJECT_NAME" + export PROJECT_PATH="$PROJECT_PATH" . ./project_env.sh diff --git a/deployment/project_env.sh b/deployment/project_env.sh index 0dacd48..70b809d 100755 --- a/deployment/project_env.sh +++ b/deployment/project_env.sh @@ -3,12 +3,7 @@ set -eu cd "$(dirname "$0")" -# source project defition. -# Now let's load the project definition. -PROJECT_NAME="$PROJECT_PREFIX-$BITCOIN_CHAIN" -export PROJECT_NAME="$PROJECT_NAME" -PROJECT_PATH="$PROJECTS_DIR/$PROJECT_NAME" -export PROJECT_PATH="$PROJECT_PATH" + PROJECT_DEFINITION_PATH="$PROJECT_PATH/project.conf" if [ ! -f "$PROJECT_DEFINITION_PATH" ]; then diff --git a/deployment/update.sh b/deployment/update.sh index 038b93f..5ac94dc 100755 --- a/deployment/update.sh +++ b/deployment/update.sh @@ -23,6 +23,22 @@ for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do export PROJECT_PREFIX="$PROJECT_PREFIX" export BITCOIN_CHAIN="$BITCOIN_CHAIN" + # if the user sets USER_TARGET_PROJECT, let's ensure the project exists. + if [ -n "$USER_TARGET_PROJECT" ]; then + if ! lxc project list | grep -q "$USER_TARGET_PROJECT"; then + echo "ERROR: the project does not exist! Nothing to update." + exit 1 + fi + + if [ "$PROJECT_NAME" != "$USER_TARGET_PROJECT" ]; then + echo "INFO: Skipping project '$PROJECT_NAME' since the system owner has used the --project switch." + exit + fi + fi + + export PROJECT_NAME="$PROJECT_NAME" + export PROJECT_PATH="$PROJECT_PATH" + . ./project_env.sh # Check to see if any of the VMs actually don't exist.