fixed formatting and private var names

This commit is contained in:
tomo 2025-02-21 10:49:08 +01:00
parent f1d214ae96
commit 18575b1eb9
No known key found for this signature in database
GPG Key ID: 5FB8BCB7CE54EE44

View File

@ -29,7 +29,7 @@ multideploy_deploy() {
fi fi
_debug2 "DOMAIN_DIR" "$DOMAIN_DIR" _debug2 "DOMAIN_DIR" "$DOMAIN_DIR"
_preprocess_deployfile "$DOMAIN_DIR/$MULTIDEPLOY_FILENAME" _preprocess_deployfile "$DOMAIN_DIR/$MULTIDEPLOY_FILENAME" || return 1
MULTIDEPLOY_CONFIG="${MULTIDEPLOY_CONFIG:-$(_getdeployconf MULTIDEPLOY_CONFIG)}" MULTIDEPLOY_CONFIG="${MULTIDEPLOY_CONFIG:-$(_getdeployconf MULTIDEPLOY_CONFIG)}"
if [ -z "$MULTIDEPLOY_CONFIG" ]; then if [ -z "$MULTIDEPLOY_CONFIG" ]; then
@ -47,7 +47,7 @@ multideploy_deploy() {
# deploy_filepath # deploy_filepath
_preprocess_deployfile() { _preprocess_deployfile() {
deploy_file="$1" _deploy_file="$1"
# Check if yq is installed # Check if yq is installed
if ! command -v yq >/dev/null 2>&1; then if ! command -v yq >/dev/null 2>&1; then
@ -56,9 +56,9 @@ _preprocess_deployfile() {
fi fi
# Check if deploy file exists and create a default template if not # Check if deploy file exists and create a default template if not
if [ -f "$deploy_file" ]; then if [ -f "$_deploy_file" ]; then
_debug3 "Deploy file found." _debug3 "Deploy file found."
_check_deployfile "$deploy_file" "$MULTIDEPLOY_CONFIG" _check_deployfile "$_deploy_file" "$MULTIDEPLOY_CONFIG"
else else
# TODO: Replace URL with wiki link # TODO: Replace URL with wiki link
_err "Deploy file not found. Go to https://CHANGE_URL_TO_WIKI to see how to create one." _err "Deploy file not found. Go to https://CHANGE_URL_TO_WIKI to see how to create one."
@ -66,48 +66,48 @@ _preprocess_deployfile() {
fi fi
} }
# deploy_filepath deploy_config # deploy_filepath _deploy_config
_check_deployfile() { _check_deployfile() {
deploy_file="$1" _deploy_file="$1"
deploy_config="$3" _deploy_config="$3"
# Check version # Check version
deploy_file_version=$(yq '.version' "$deploy_file") _deploy_file_version=$(yq '.version' "$_deploy_file")
if [ "$MULTIDEPLOY_VERSION" != "$deploy_file_version" ]; then if [ "$MULTIDEPLOY_VERSION" != "$_deploy_file_version" ]; then
_err "As of $PROJECT_NAME $VER, the deploy file needs version $MULTIDEPLOY_VERSION! Your current deploy file is of version $deploy_file_version." _err "As of $PROJECT_NAME $VER, the deploy file needs version $MULTIDEPLOY_VERSION! Your current deploy file is of version $_deploy_file_version."
return 1 return 1
fi fi
# Check if config exists # Check if config exists
if ! yq e ".configs[] | select(.name == \"$deploy_config\")" "$deploy_file" >/dev/null; then if ! yq e ".configs[] | select(.name == \"$_deploy_config\")" "$_deploy_file" >/dev/null; then
_err "Config '$deploy_config' not found." _err "Config '$_deploy_config' not found."
return 1 return 1
fi fi
# Extract all services from config # Extract all services from config
services=$(_get_services_list "$deploy_file" "$deploy_config") _services=$(_get_services_list "$_deploy_file" "$_deploy_config")
if [ -z "$services" ]; then if [ -z "$_services" ]; then
_err "Config '$deploy_config' does not have any services to deploy to." _err "Config '$_deploy_config' does not have any services to deploy to."
return 1 return 1
fi fi
# Check if extracted services exist in services list # Check if extracted services exist in services list
for service in $services; do for _service in $_services; do
if ! yq e ".services[] | select(.name == \"$service\")" "$deploy_file" >/dev/null; then if ! yq e ".services[] | select(.name == \"$_service\")" "$_deploy_file" >/dev/null; then
_err "Service '$service' not found." _err "Service '$_service' not found."
return 1 return 1
fi fi
# Check if service has hook # Check if service has hook
if ! yq e ".services[] | select(.name == \"$service\").hook" "$deploy_file" >/dev/null; then if ! yq e ".services[] | select(.name == \"$_service\").hook" "$_deploy_file" >/dev/null; then
_err "Service '$service' does not have a hook." _err "Service '$_service' does not have a hook."
return 1 return 1
fi fi
# Check if service has environment # Check if service has environment
if ! yq e ".services[] | select(.name == \"$service\").environment" "$deploy_file" >/dev/null; then if ! yq e ".services[] | select(.name == \"$_service\").environment" "$_deploy_file" >/dev/null; then
_err "Service '$service' does not an environment." _err "Service '$_service' does not an environment."
return 1 return 1
fi fi
done done
@ -115,26 +115,26 @@ _check_deployfile() {
# deploy_filepath deploy_config # deploy_filepath deploy_config
_get_services_list() { _get_services_list() {
deploy_file="$1" _deploy_file="$1"
deploy_config="$2" _deploy_config="$2"
services=$(yq e ".configs[] | select(.name == \"$deploy_config\").services[]" "$deploy_file") _services=$(yq e ".configs[] | select(.name == \"$_deploy_config\").services[]" "$_deploy_file")
echo "$services" echo "$_services"
} }
# deploy_filepath service_names # deploy_filepath service_names
_get_full_services_list() { _get_full_services_list() {
deploy_file="$1" _deploy_file="$1"
shift shift
service_names="$*" _service_names="$*"
full_services="" _full_services=""
for service in $service_names; do for _service in $_service_names; do
full_service=$(yq e ".services[] | select(.name == \"$service\")" "$deploy_file") _full_service=$(yq e ".services[] | select(.name == \"$_service\")" "$_deploy_file")
full_services="$full_services _full_services="$_full_services
$full_service" $_full_service"
done done
echo "$full_services" echo "$_full_services"
} }