diff --git a/Linux/Server/startup-server.sh b/Linux/Server/startup-server.sh index c3c99d0..8e689aa 100644 --- a/Linux/Server/startup-server.sh +++ b/Linux/Server/startup-server.sh @@ -9,13 +9,16 @@ if [ -d .git ]; then git fetch "https://${GIT_USERNAME}:${GIT_PAT}@${CLEAN_REPO_URL}" "${GIT_BRANCH}" git reset --hard FETCH_HEAD fi + # Constants 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 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 -ENV_FILE=".env.production" +ENV_FILE=".env.development" if [ -f "$ENV_FILE" ]; then echo "Loading environment variables from $ENV_FILE..." # Read each line in .env.production @@ -34,10 +37,23 @@ else echo "Error: $ENV_FILE not found!" exit 1 fi + # Function to escape special characters for sed escape_sed_special_chars() { 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 manage_backups() { local output_file="$1" @@ -88,9 +104,9 @@ for EXT in $EXTENSIONS; do manage_backups "$OUTPUT_FILE" 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 - if [ -z "$(eval echo "\$$var")" ]; then + if ! is_ignored_placeholder "$var" && [ -z "$(eval echo "\$$var")" ]; then echo "$var" fi done) @@ -99,15 +115,17 @@ for EXT in $EXTENSIONS; do echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED" exit 1 fi - # Replace placeholders with environment variable values + + # Replace placeholders with environment variable values (skip ignored ones) sed_script="" 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_value=$(escape_sed_special_chars "$(eval echo "\$$key")") sed_script="${sed_script}s|\${${escaped_key}}|${escaped_value}|g;" fi done < "$ENV_FILE" + # Generate the output file sed -e "$sed_script" "$TEMPLATE_FILE" > "$OUTPUT_FILE" echo "Processed $TEMPLATE_FILE into $OUTPUT_FILE"