Added ignored variables
This commit is contained in:
@@ -9,13 +9,16 @@ if [ -d .git ]; then
|
|||||||
git fetch "https://${GIT_USERNAME}:${GIT_PAT}@${CLEAN_REPO_URL}" "${GIT_BRANCH}"
|
git fetch "https://${GIT_USERNAME}:${GIT_PAT}@${CLEAN_REPO_URL}" "${GIT_BRANCH}"
|
||||||
git reset --hard FETCH_HEAD
|
git reset --hard FETCH_HEAD
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
EXTENSIONS="yml json conf properties" # Space-separated list of extensions
|
EXTENSIONS="yml json conf properties" # Space-separated list of extensions
|
||||||
ENV="production" # Change this to the environment you need
|
ENV="development" # Change this to the environment you need
|
||||||
DRY_RUN="false" # Change to true if you want to simulate changes without modifying files
|
DRY_RUN="false" # Change to true if you want to simulate changes without modifying files
|
||||||
MAX_BACKUPS=3 # Maximum number of backup files to keep
|
MAX_BACKUPS=3 # Maximum number of backup files to keep
|
||||||
|
IGNORED_PLACEHOLDERS="playerUUID playerName playerUUIDNoDash" # Space-separated list of placeholders to ignore
|
||||||
|
|
||||||
# Load environment variables from .env.production file
|
# Load environment variables from .env.production file
|
||||||
ENV_FILE=".env.production"
|
ENV_FILE=".env.development"
|
||||||
if [ -f "$ENV_FILE" ]; then
|
if [ -f "$ENV_FILE" ]; then
|
||||||
echo "Loading environment variables from $ENV_FILE..."
|
echo "Loading environment variables from $ENV_FILE..."
|
||||||
# Read each line in .env.production
|
# Read each line in .env.production
|
||||||
@@ -34,10 +37,23 @@ else
|
|||||||
echo "Error: $ENV_FILE not found!"
|
echo "Error: $ENV_FILE not found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to escape special characters for sed
|
# Function to escape special characters for sed
|
||||||
escape_sed_special_chars() {
|
escape_sed_special_chars() {
|
||||||
echo "$1" | sed 's/[][\/.^$*]/\\&/g'
|
echo "$1" | sed 's/[][\/.^$*]/\\&/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to check if a variable is in the ignored list
|
||||||
|
is_ignored_placeholder() {
|
||||||
|
local var="$1"
|
||||||
|
for ignored in $IGNORED_PLACEHOLDERS; do
|
||||||
|
if [ "$var" = "$ignored" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Function to manage backups
|
# Function to manage backups
|
||||||
manage_backups() {
|
manage_backups() {
|
||||||
local output_file="$1"
|
local output_file="$1"
|
||||||
@@ -88,9 +104,9 @@ for EXT in $EXTENSIONS; do
|
|||||||
manage_backups "$OUTPUT_FILE"
|
manage_backups "$OUTPUT_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Validate unresolved placeholders
|
# Validate unresolved placeholders (excluding ignored ones)
|
||||||
UNRESOLVED=$(grep -o '\${[A-Za-z_][A-Za-z0-9_]*}' "$TEMPLATE_FILE" | sed 's/[${}]//g' | while read -r var; do
|
UNRESOLVED=$(grep -o '\${[A-Za-z_][A-Za-z0-9_]*}' "$TEMPLATE_FILE" | sed 's/[${}]//g' | while read -r var; do
|
||||||
if [ -z "$(eval echo "\$$var")" ]; then
|
if ! is_ignored_placeholder "$var" && [ -z "$(eval echo "\$$var")" ]; then
|
||||||
echo "$var"
|
echo "$var"
|
||||||
fi
|
fi
|
||||||
done)
|
done)
|
||||||
@@ -99,15 +115,17 @@ for EXT in $EXTENSIONS; do
|
|||||||
echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED"
|
echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Replace placeholders with environment variable values
|
|
||||||
|
# Replace placeholders with environment variable values (skip ignored ones)
|
||||||
sed_script=""
|
sed_script=""
|
||||||
while IFS='=' read -r key value; do
|
while IFS='=' read -r key value; do
|
||||||
if [ -n "$key" ] && [ "${key#\#}" = "$key" ]; then
|
if [ -n "$key" ] && [ "${key#\#}" = "$key" ] && ! is_ignored_placeholder "$key"; then
|
||||||
escaped_key=$(escape_sed_special_chars "$key")
|
escaped_key=$(escape_sed_special_chars "$key")
|
||||||
escaped_value=$(escape_sed_special_chars "$(eval echo "\$$key")")
|
escaped_value=$(escape_sed_special_chars "$(eval echo "\$$key")")
|
||||||
sed_script="${sed_script}s|\${${escaped_key}}|${escaped_value}|g;"
|
sed_script="${sed_script}s|\${${escaped_key}}|${escaped_value}|g;"
|
||||||
fi
|
fi
|
||||||
done < "$ENV_FILE"
|
done < "$ENV_FILE"
|
||||||
|
|
||||||
# Generate the output file
|
# Generate the output file
|
||||||
sed -e "$sed_script" "$TEMPLATE_FILE" > "$OUTPUT_FILE"
|
sed -e "$sed_script" "$TEMPLATE_FILE" > "$OUTPUT_FILE"
|
||||||
echo "Processed $TEMPLATE_FILE into $OUTPUT_FILE"
|
echo "Processed $TEMPLATE_FILE into $OUTPUT_FILE"
|
||||||
|
|||||||
Reference in New Issue
Block a user