commit 06190f8764b75aa2418e98a00fa89024068563e4 Author: Exos9 Date: Mon Jan 12 23:52:33 2026 +0100 first commit diff --git a/Linux/Development/MERGE-TO-PRODUCTION.sh b/Linux/Development/MERGE-TO-PRODUCTION.sh new file mode 100644 index 0000000..0bb644c --- /dev/null +++ b/Linux/Development/MERGE-TO-PRODUCTION.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Prompt for confirmation +echo "Are you sure you want to merge 'development' into 'production'? (y/n)" +read -r confirmation + +if [[ "$confirmation" == "y" || "$confirmation" == "Y" ]]; then + # Switch to the production branch + git checkout production + + # Pull the latest changes for production + git pull origin production + + # Merge the development branch into production + git merge development + + # Check if the merge was successful + if [ $? -eq 0 ]; then + echo "Merge successful. Please resolve any conflicts and commit." + else + echo "Merge failed. Please resolve conflicts manually." + fi +else + echo "Merge aborted." +fi diff --git a/Linux/Development/PUSH-TO-DEVELOPMENT.sh b/Linux/Development/PUSH-TO-DEVELOPMENT.sh new file mode 100644 index 0000000..58bfdae --- /dev/null +++ b/Linux/Development/PUSH-TO-DEVELOPMENT.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status. +set -e + +# Function to display a message in red color +error() { + echo -e "\e[31m$1\e[0m" +} + +# Function to display a message in green color +success() { + echo -e "\e[32m$1\e[0m" +} + +# Ensure we're inside a Git repository +if ! git rev-parse --git-dir > /dev/null 2>&1; then + error "Error: This directory is not a Git repository." + exit 1 +fi + +# Get the current branch name +CURRENT_BRANCH=$(git symbolic-ref --short HEAD) + +# Check if the current branch is 'development' +if [ "$CURRENT_BRANCH" != "development" ]; then + error "Error: You are not on the 'development' branch." + echo "Please switch to the 'development' branch and run this script again." + exit 1 +fi + +# Prompt for a commit message +echo "Enter your commit message:" +read -r COMMIT_MESSAGE + +# Check if the commit message is empty +if [ -z "$COMMIT_MESSAGE" ]; then + error "Error: Commit message cannot be empty." + exit 1 +fi + +# Add all changes +git add . + +# Show the changes to be committed +echo "The following changes will be committed:" +git status --short + +# Prompt for confirmation to commit +echo "Do you want to proceed with the commit and push to 'development' branch? (yes/no)" +read -r CONFIRMATION + +if [ "$CONFIRMATION" != "yes" ]; then + error "Aborting commit and push to 'development' branch." + exit 0 +fi + +# Commit the changes with the provided message +git commit -m "$COMMIT_MESSAGE" + +# Show the last commit +echo "Last commit on 'development' branch:" +git --no-pager log -1 --pretty=format:"%h - %s (%an, %ar)" +echo + +# Pull the latest changes from the remote 'development' branch +git pull origin development --rebase + +# Push the 'development' branch to the remote repository +git push origin development + +success "Successfully pushed changes to 'development' branch." diff --git a/Linux/Development/PUSH-TO-PRODUCTION.sh b/Linux/Development/PUSH-TO-PRODUCTION.sh new file mode 100644 index 0000000..2b655c2 --- /dev/null +++ b/Linux/Development/PUSH-TO-PRODUCTION.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status. +set -e + +# Function to display a message in red color +error() { + echo -e "\e[31m$1\e[0m" +} + +# Function to display a message in green color +success() { + echo -e "\e[32m$1\e[0m" +} + +# Ensure we're inside a Git repository +if ! git rev-parse --git-dir > /dev/null 2>&1; then + error "Error: This directory is not a Git repository." + exit 1 +fi + +# Get the current branch name +CURRENT_BRANCH=$(git symbolic-ref --short HEAD) + +# Check if the current branch is 'development' +if [ "$CURRENT_BRANCH" != "development" ]; then + error "Error: You are not on the 'development' branch." + echo "Please switch to the 'development' branch and run this script again." + exit 1 +fi + +# Prompt for a commit message +echo "Enter your commit message:" +read -r COMMIT_MESSAGE + +# Check if the commit message is empty +if [ -z "$COMMIT_MESSAGE" ]; then + error "Error: Commit message cannot be empty." + exit 1 +fi + +# Add all changes +git add . + +# Commit the changes with the provided message +git commit -m "$COMMIT_MESSAGE" + +# Show the last commit +echo "Last commit on 'development' branch:" +git --no-pager log -1 --pretty=format:"%h - %s (%an, %ar)" +echo + +# Prompt for confirmation to push to 'production' +echo "Do you want to merge 'development' into 'production' and push to the remote repository? (yes/no)" +read -r CONFIRMATION + +if [ "$CONFIRMATION" != "yes" ]; then + error "Aborting push to 'production' branch." + exit 0 +fi + +# Fetch the latest changes from the remote repository +git fetch origin + +# Switch to the 'production' branch +git checkout production + +# Pull the latest changes in 'production' branch +git pull origin production + +# Merge 'development' into 'production' +git merge --no-ff development -m "Merge branch 'development' into 'production'" + +# Push the 'production' branch to the remote repository +git push origin production + +# Switch back to the 'development' branch +git checkout development + +success "Successfully pushed changes from 'development' to 'production' branch." diff --git a/Linux/Development/Pull-Latest-From-Git-Function.sh b/Linux/Development/Pull-Latest-From-Git-Function.sh new file mode 100644 index 0000000..45a0508 --- /dev/null +++ b/Linux/Development/Pull-Latest-From-Git-Function.sh @@ -0,0 +1,42 @@ +# Function to pull the latest changes from the Git repo +pull_latest_from_git() { + # Directory where the repo will be cloned + REPO_DIR="/mnt/server" + + # Check if Git is installed + if ! command -v git >/dev/null 2>&1; then + echo "Git is not installed. Installing Git..." + apk update + apk add git + fi + + # Configure Git to use the provided username and PAT + if [ -n "${GIT_USERNAME}" ] && [ -n "${GIT_PAT}" ]; then + echo "Configuring Git credentials and directory..." + git config --global --add safe.directory "${REPO_DIR}" + echo "The directory config worked" + git config --global credential.helper store + echo "https://${GIT_USERNAME}:${GIT_PAT}@${GIT_REPO_URL#https://}" > /root/.git-credentials + chmod 600 /root/.git-credentials + echo "The credentials config worked" + fi + + cd "${REPO_DIR}" + + # Check if the .git directory exists + if [ -d ".git" ]; then + echo "Repository already exists. Pulling latest changes from ${GIT_BRANCH} branch..." + git fetch origin + git reset "origin/${GIT_BRANCH}" + else + echo "Cloning repository from ${GIT_REPO_URL}..." + git clone https://${GIT_REPO_URL} ${REPO_DIR} + fi + + # Clean up Git credentials + rm -f /root/.git-credentials + git config --global --unset credential.helper +} + +# Pull the latest changes from Git +pull_latest_from_git \ No newline at end of file diff --git a/Linux/Development/generate-config.sh b/Linux/Development/generate-config.sh new file mode 100644 index 0000000..ba4f8ea --- /dev/null +++ b/Linux/Development/generate-config.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# Enable strict error handling +set -e + +# Function to show usage instructions +show_usage() { + echo "Usage: $0 [file extensions] [environment] [--dry-run]" + echo " file extensions: A space-separated list of file extensions (e.g. .yml .json .conf)." + echo " environment: The target environment (e.g., development or production)." + echo " --dry-run : Simulate changes without modifying files." +} + +# Parse command-line arguments +DRY_RUN=false +ENV=$1 +if [[ -z "$ENV" ]]; then + show_usage + exit 1 +fi + +if [[ "$2" == "--dry-run" ]]; then + DRY_RUN=true +fi + +shift # Shift arguments so we can get the file extensions after the environment + +EXTENSIONS=("$@") +if [[ ${#EXTENSIONS[@]} -eq 0 ]]; then + echo "Error: You must specify at least one file extension." + show_usage + exit 1 +fi + +echo "Arguments passed correctly!" + +# Load the appropriate .env file +if [ -f ".env.$ENV" ]; then + set -a + source ".env.$ENV" + set +a +else + echo "Environment file .env.$ENV not found!" + exit 1 +fi + +# Function to escape all special characters that might affect sed +escape_sed_special_chars() { + printf '%s' "$1" | sed 's|[&/\$]|\&|g; s|[[:space:]]|\\ |g; s|\\|\\\\|g' +} + +# Process files for each extension +for EXT in "${EXTENSIONS[@]}"; do + # Find and process all *.template files with the current extension, including subdirectories + find . -name "*.template$EXT" | while read -r TEMPLATE_FILE; do + # Derive output file name by removing ".template" + OUTPUT_FILE="${TEMPLATE_FILE%.template$EXT}$EXT" + + # Dry-run reporting or actual processing + if $DRY_RUN; then + echo "Dry run: would generate $OUTPUT_FILE from $TEMPLATE_FILE" + + LINE_NUMBER=0 + while IFS= read -r line || [[ -n "$line" ]]; do + LINE_NUMBER=$((LINE_NUMBER + 1)) + while [[ "$line" =~ (\$\{([A-Za-z_][A-Za-z0-9_]*)\}) ]]; do + PLACEHOLDER="${BASH_REMATCH[1]}" + VAR_NAME="${BASH_REMATCH[2]}" + VAR_VALUE="${!VAR_NAME:-}" + + echo " Would have inputted '$VAR_VALUE' in place of '$VAR_NAME' in $OUTPUT_FILE at line $LINE_NUMBER" + + if [[ "$VAR_VALUE" == "" ]]; then + echo " Warning: Variable '$VAR_NAME' is undefined and will cause an error in actual mode." + fi + + line="${line/$PLACEHOLDER/}" + done + done < "$TEMPLATE_FILE" + + else + # Validate unresolved placeholders + UNRESOLVED=$(grep -oP '\${\K[A-Za-z_][A-Za-z0-9_]*(?=})' "$TEMPLATE_FILE" | while read -r var; do + if [ -z "${!var}" ]; then + echo "$var" + fi + done) + + if [ -n "$UNRESOLVED" ]; then + echo "Error: Unresolved variable placeholders detected in $TEMPLATE_FILE!" + echo "Ensure all variables are defined in .env.$ENV. Missing: $UNRESOLVED" + exit 1 + fi + + # Backup existing output file if it exists + if [ -f "$OUTPUT_FILE" ]; then + mv "$OUTPUT_FILE" "${OUTPUT_FILE}.bak" + echo "Backup created for $OUTPUT_FILE as ${OUTPUT_FILE}.bak" + fi + + # Replace placeholders with environment variables + sed_script="" + while IFS='=' read -r key value; do + # Skip invalid variable names + if [[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then + # Escape special characters in the key and value for sed + escaped_key=$(escape_sed_special_chars "${key}") + escaped_value=$(escape_sed_special_chars "${!key}") + sed_script+="s|\${${escaped_key}}|${escaped_value}|g;" + fi + done < <(env) + + # Generate the output file + sed -e "$sed_script" "$TEMPLATE_FILE" > "$OUTPUT_FILE" + echo "Generated $OUTPUT_FILE from $TEMPLATE_FILE" + fi + done +done + +# Keep the terminal open at the end +echo "Script completed. Press any key to exit..." +read -n 1 -s diff --git a/Linux/Development/push-scripts-to-repo.bat b/Linux/Development/push-scripts-to-repo.bat new file mode 100644 index 0000000..abde84d --- /dev/null +++ b/Linux/Development/push-scripts-to-repo.bat @@ -0,0 +1,17 @@ +@echo off +:: Add all files to Git +git add . + +:: Prompt for commit message +set /p commitMessage="Enter the commit message: " + +:: Commit the changes +git commit -m "%commitMessage%" + +:: Confirm if the user wants to push the changes +set /p confirmPush="Do you want to push the changes to the main branch? (yes/no): " +if /i "%confirmPush%"=="yes" ( + git push origin +) else ( + echo Changes not pushed. +) diff --git a/Linux/Development/push-scripts-to-repo.sh b/Linux/Development/push-scripts-to-repo.sh new file mode 100644 index 0000000..d85168e --- /dev/null +++ b/Linux/Development/push-scripts-to-repo.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Add all files to Git +git add . + +# Prompt for commit message +read -p "Enter the commit message: " commitMessage + +# Commit the changes +git commit -m "$commitMessage" + +# Confirm if the user wants to push the changes +read -p "Do you want to push the changes to the main branch? (yes/no): " confirmPush +if [[ "$confirmPush" == "yes" ]]; then + git push origin +else + echo "Changes not pushed." +fi diff --git a/Linux/Development/startup-proxy-dev.sh b/Linux/Development/startup-proxy-dev.sh new file mode 100644 index 0000000..71b0ba8 --- /dev/null +++ b/Linux/Development/startup-proxy-dev.sh @@ -0,0 +1,109 @@ +#!/bin/sh +EXTENSIONS="yml json conf toml" # Space-separated list of extensions +ENV="production" # 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 +# Load environment variables from .env.production file +ENV_FILE=".env.production" +if [ -f "$ENV_FILE" ]; then + echo "Loading environment variables from $ENV_FILE..." + # Read each line in .env.production + while IFS='=' read -r key value; do + # Skip empty lines and comments + if [ -z "$key" ] || [ "$(printf '%s' "$key" | cut -c1)" = "#" ]; then + continue + fi + # Remove potential spaces around the variable and export it + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$ENV_FILE" + echo "Environment variables loaded successfully." +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 manage backups +manage_backups() { + local output_file="$1" + local timestamp + timestamp=$(date +"%Y%m%d_%H%M%S") + local backup_file="${output_file}_${timestamp}.bak" + + # Create backup + cp "$output_file" "$backup_file" + echo "Backed up $output_file to $backup_file" + + # Find and remove old backups, keeping only the most recent MAX_BACKUPS + find "$(dirname "$output_file")" -maxdepth 1 \ + -name "$(basename "$output_file")_*.bak" | \ + sort -r | \ + tail -n +$((MAX_BACKUPS + 1)) | \ + xargs -r rm +} + +echo "Environment setup complete. Starting template processing..." +# Process template files for each extension +for EXT in $EXTENSIONS; do + echo "Processing files with extension .template.$EXT..." + + # Find template files recursively + TEMPLATES=$(find . -type f -name "*.template.$EXT") + + if [ -z "$TEMPLATES" ]; then + echo "No template files found for extension .template.$EXT" + continue + fi + + echo "Found the following template files:" + echo "$TEMPLATES" + + echo "$TEMPLATES" | while read -r TEMPLATE_FILE; do + # Remove .template from the end to generate output file + OUTPUT_FILE="${TEMPLATE_FILE%.template.$EXT}.$EXT" + echo "Processing $TEMPLATE_FILE into $OUTPUT_FILE..." + + if [ "$DRY_RUN" = "true" ]; then + echo "Dry run: Would process $TEMPLATE_FILE into $OUTPUT_FILE" + continue + fi + + # Create backup if output file already exists + if [ -f "$OUTPUT_FILE" ]; then + manage_backups "$OUTPUT_FILE" + fi + + # Validate unresolved placeholders + 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 + echo "$var" + fi + done) + if [ -n "$UNRESOLVED" ]; then + echo "Error: Unresolved variables detected in $TEMPLATE_FILE!" + echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED" + exit 1 + fi + # Replace placeholders with environment variable values + sed_script="" + while IFS='=' read -r key value; do + if [ -n "$key" ] && [ "${key#\#}" = "$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" + done +done +echo "Template processing complete. Starting the server in 5 seconds..." +sleep 5 + + +java -Xms256M -Xmx1024M -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:+UnlockExperimentalVMOptions -XX:+ParallelRefProcEnabled -XX:+AlwaysPreTouch -XX:MaxInlineLevel=15 -jar velocity.jar \ No newline at end of file diff --git a/Linux/Development/startup-server-dev.sh b/Linux/Development/startup-server-dev.sh new file mode 100644 index 0000000..e8604b2 --- /dev/null +++ b/Linux/Development/startup-server-dev.sh @@ -0,0 +1,108 @@ +#!/bin/sh +EXTENSIONS="yml json conf properties" # Space-separated list of extensions +ENV="production" # 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 +# Load environment variables from .env.production file +ENV_FILE=".env.production" +if [ -f "$ENV_FILE" ]; then + echo "Loading environment variables from $ENV_FILE..." + # Read each line in .env.production + while IFS='=' read -r key value; do + # Skip empty lines and comments + if [ -z "$key" ] || [ "$(printf '%s' "$key" | cut -c1)" = "#" ]; then + continue + fi + # Remove potential spaces around the variable and export it + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$ENV_FILE" + echo "Environment variables loaded successfully." +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 manage backups +manage_backups() { + local output_file="$1" + local timestamp + timestamp=$(date +"%Y%m%d_%H%M%S") + local backup_file="${output_file}_${timestamp}.bak" + + # Create backup + cp "$output_file" "$backup_file" + echo "Backed up $output_file to $backup_file" + + # Find and remove old backups, keeping only the most recent MAX_BACKUPS + find "$(dirname "$output_file")" -maxdepth 1 \ + -name "$(basename "$output_file")_*.bak" | \ + sort -r | \ + tail -n +$((MAX_BACKUPS + 1)) | \ + xargs -r rm +} + +echo "Environment setup complete. Starting template processing..." +# Process template files for each extension +for EXT in $EXTENSIONS; do + echo "Processing files with extension .template.$EXT..." + + # Find template files recursively + TEMPLATES=$(find . -type f -name "*.template.$EXT") + + if [ -z "$TEMPLATES" ]; then + echo "No template files found for extension .template.$EXT" + continue + fi + + echo "Found the following template files:" + echo "$TEMPLATES" + + echo "$TEMPLATES" | while read -r TEMPLATE_FILE; do + # Remove .template from the end to generate output file + OUTPUT_FILE="${TEMPLATE_FILE%.template.$EXT}.$EXT" + echo "Processing $TEMPLATE_FILE into $OUTPUT_FILE..." + + if [ "$DRY_RUN" = "true" ]; then + echo "Dry run: Would process $TEMPLATE_FILE into $OUTPUT_FILE" + continue + fi + + # Create backup if output file already exists + if [ -f "$OUTPUT_FILE" ]; then + manage_backups "$OUTPUT_FILE" + fi + + # Validate unresolved placeholders + 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 + echo "$var" + fi + done) + if [ -n "$UNRESOLVED" ]; then + echo "Error: Unresolved variables detected in $TEMPLATE_FILE!" + echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED" + exit 1 + fi + # Replace placeholders with environment variable values + sed_script="" + while IFS='=' read -r key value; do + if [ -n "$key" ] && [ "${key#\#}" = "$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" + done +done +echo "Template processing complete. Starting the server in 5 seconds..." +sleep 5 + +java -Xms1024M -Xmx4192M --add-modules=jdk.incubator.vector -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -jar server.jar --nogui \ No newline at end of file diff --git a/Linux/Server/startup-proxy.sh b/Linux/Server/startup-proxy.sh new file mode 100644 index 0000000..fda03cd --- /dev/null +++ b/Linux/Server/startup-proxy.sh @@ -0,0 +1,116 @@ +#!/bin/sh +# Check if Git repo needs updating +if [ -d .git ]; then + echo "Pulling latest changes from the repository..." + git pull "https://${GIT_USERNAME}:${GIT_PAT}@${GIT_REPO_URL}" "${GIT_BRANCH}" || true +fi + +# Constants +EXTENSIONS="yml json conf toml" # Space-separated list of extensions +ENV="production" # 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 +# Load environment variables from .env.production file +ENV_FILE=".env.production" +if [ -f "$ENV_FILE" ]; then + echo "Loading environment variables from $ENV_FILE..." + # Read each line in .env.production + while IFS='=' read -r key value; do + # Skip empty lines and comments + if [ -z "$key" ] || [ "$(printf '%s' "$key" | cut -c1)" = "#" ]; then + continue + fi + # Remove potential spaces around the variable and export it + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$ENV_FILE" + echo "Environment variables loaded successfully." +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 manage backups +manage_backups() { + local output_file="$1" + local timestamp + timestamp=$(date +"%Y%m%d_%H%M%S") + local backup_file="${output_file}_${timestamp}.bak" + + # Create backup + cp "$output_file" "$backup_file" + echo "Backed up $output_file to $backup_file" + + # Find and remove old backups, keeping only the most recent MAX_BACKUPS + find "$(dirname "$output_file")" -maxdepth 1 \ + -name "$(basename "$output_file")_*.bak" | \ + sort -r | \ + tail -n +$((MAX_BACKUPS + 1)) | \ + xargs -r rm +} + +echo "Environment setup complete. Starting template processing..." +# Process template files for each extension +for EXT in $EXTENSIONS; do + echo "Processing files with extension .template.$EXT..." + + # Find template files recursively + TEMPLATES=$(find . -type f -name "*.template.$EXT") + + if [ -z "$TEMPLATES" ]; then + echo "No template files found for extension .template.$EXT" + continue + fi + + echo "Found the following template files:" + echo "$TEMPLATES" + + echo "$TEMPLATES" | while read -r TEMPLATE_FILE; do + # Remove .template from the end to generate output file + OUTPUT_FILE="${TEMPLATE_FILE%.template.$EXT}.$EXT" + echo "Processing $TEMPLATE_FILE into $OUTPUT_FILE..." + + if [ "$DRY_RUN" = "true" ]; then + echo "Dry run: Would process $TEMPLATE_FILE into $OUTPUT_FILE" + continue + fi + + # Create backup if output file already exists + if [ -f "$OUTPUT_FILE" ]; then + manage_backups "$OUTPUT_FILE" + fi + + # Validate unresolved placeholders + 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 + echo "$var" + fi + done) + if [ -n "$UNRESOLVED" ]; then + echo "Error: Unresolved variables detected in $TEMPLATE_FILE!" + echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED" + exit 1 + fi + # Replace placeholders with environment variable values + sed_script="" + while IFS='=' read -r key value; do + if [ -n "$key" ] && [ "${key#\#}" = "$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" + done +done +echo "Template processing complete. Starting the server in 5 seconds..." +sleep 5 + + +java -Xms${SERVER_MIN_MEMORY}M -Xmx${SERVER_MEMORY}M -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:+UnlockExperimentalVMOptions -XX:+ParallelRefProcEnabled -XX:+AlwaysPreTouch -XX:MaxInlineLevel=15 -jar ${SERVER_JARFILE} \ No newline at end of file diff --git a/Linux/Server/startup-server.sh b/Linux/Server/startup-server.sh new file mode 100644 index 0000000..3ddef13 --- /dev/null +++ b/Linux/Server/startup-server.sh @@ -0,0 +1,115 @@ +#!/bin/sh +# Check if Git repo needs updating +if [ -d .git ]; then + echo "Pulling latest changes from the repository..." + git pull "https://${GIT_USERNAME}:${GIT_PAT}@${GIT_REPO_URL}" "${GIT_BRANCH}" || true +fi + +# Constants +EXTENSIONS="yml json conf properties" # Space-separated list of extensions +ENV="production" # 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 +# Load environment variables from .env.production file +ENV_FILE=".env.production" +if [ -f "$ENV_FILE" ]; then + echo "Loading environment variables from $ENV_FILE..." + # Read each line in .env.production + while IFS='=' read -r key value; do + # Skip empty lines and comments + if [ -z "$key" ] || [ "$(printf '%s' "$key" | cut -c1)" = "#" ]; then + continue + fi + # Remove potential spaces around the variable and export it + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + export "$key=$value" + done < "$ENV_FILE" + echo "Environment variables loaded successfully." +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 manage backups +manage_backups() { + local output_file="$1" + local timestamp + timestamp=$(date +"%Y%m%d_%H%M%S") + local backup_file="${output_file}_${timestamp}.bak" + + # Create backup + cp "$output_file" "$backup_file" + echo "Backed up $output_file to $backup_file" + + # Find and remove old backups, keeping only the most recent MAX_BACKUPS + find "$(dirname "$output_file")" -maxdepth 1 \ + -name "$(basename "$output_file")_*.bak" | \ + sort -r | \ + tail -n +$((MAX_BACKUPS + 1)) | \ + xargs -r rm +} + +echo "Environment setup complete. Starting template processing..." +# Process template files for each extension +for EXT in $EXTENSIONS; do + echo "Processing files with extension .template.$EXT..." + + # Find template files recursively + TEMPLATES=$(find . -type f -name "*.template.$EXT") + + if [ -z "$TEMPLATES" ]; then + echo "No template files found for extension .template.$EXT" + continue + fi + + echo "Found the following template files:" + echo "$TEMPLATES" + + echo "$TEMPLATES" | while read -r TEMPLATE_FILE; do + # Remove .template from the end to generate output file + OUTPUT_FILE="${TEMPLATE_FILE%.template.$EXT}.$EXT" + echo "Processing $TEMPLATE_FILE into $OUTPUT_FILE..." + + if [ "$DRY_RUN" = "true" ]; then + echo "Dry run: Would process $TEMPLATE_FILE into $OUTPUT_FILE" + continue + fi + + # Create backup if output file already exists + if [ -f "$OUTPUT_FILE" ]; then + manage_backups "$OUTPUT_FILE" + fi + + # Validate unresolved placeholders + 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 + echo "$var" + fi + done) + if [ -n "$UNRESOLVED" ]; then + echo "Error: Unresolved variables detected in $TEMPLATE_FILE!" + echo "Ensure the following variables are defined in $ENV_FILE: $UNRESOLVED" + exit 1 + fi + # Replace placeholders with environment variable values + sed_script="" + while IFS='=' read -r key value; do + if [ -n "$key" ] && [ "${key#\#}" = "$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" + done +done +echo "Template processing complete. Starting the server in 5 seconds..." +sleep 5 + +java -Xms${SERVER_MIN_MEMORY}M -Xmx${SERVER_MEMORY}M --add-modules=jdk.incubator.vector -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -jar ${SERVER_JARFILE} --nogui \ No newline at end of file diff --git a/Windows/MERGE-TO-PRODUCTION.bat b/Windows/MERGE-TO-PRODUCTION.bat new file mode 100644 index 0000000..5bc611d --- /dev/null +++ b/Windows/MERGE-TO-PRODUCTION.bat @@ -0,0 +1,24 @@ +@echo off + +:: Prompt for confirmation +set /p confirmation="Are you sure you want to merge 'development' into 'production'? (y/n): " + +if /i "%confirmation%"=="y" ( + :: Switch to the production branch + git checkout production + + :: Pull the latest changes for production + git pull origin production + + :: Merge the development branch into production + git merge development + + :: Check if the merge was successful + if %errorlevel%==0 ( + echo Merge successful. Please resolve any conflicts and commit. + ) else ( + echo Merge failed. Please resolve conflicts manually. + ) +) else ( + echo Merge aborted. +) diff --git a/Windows/PUSH-TO-DEVELOPMENT.bat b/Windows/PUSH-TO-DEVELOPMENT.bat new file mode 100644 index 0000000..2823789 --- /dev/null +++ b/Windows/PUSH-TO-DEVELOPMENT.bat @@ -0,0 +1,58 @@ +@echo off +setlocal ENABLEDELAYEDEXPANSION + +:: Ensure we're inside a Git repository +git rev-parse --git-dir > NUL 2>&1 +if ERRORLEVEL 1 ( + echo Error: This directory is not a Git repository. + exit /b 1 +) + +:: Get the current branch name +FOR /F "delims=" %%i IN ('git symbolic-ref --short HEAD') DO SET CURRENT_BRANCH=%%i + +:: Check if the current branch is 'development' +if NOT "!CURRENT_BRANCH!"=="development" ( + echo Error: You are not on the 'development' branch. + echo Please switch to the 'development' branch and run this script again. + exit /b 1 +) + +:: Prompt for a commit message +set /p COMMIT_MESSAGE=Enter your commit message: + +if "%COMMIT_MESSAGE%"=="" ( + echo Error: Commit message cannot be empty. + exit /b 1 +) + +:: Add all changes +git add --all + +:: Show the changes to be committed +echo The following changes will be committed: +git status --short + +:: Prompt for confirmation to commit +set /p CONFIRMATION=Do you want to proceed with the commit and push to 'development' branch? (yes/no): + +if /I NOT "%CONFIRMATION%"=="yes" ( + echo Aborting commit and push to 'development' branch. + exit /b 0 +) + +:: Commit the changes with the provided message +git commit -m "%COMMIT_MESSAGE%" + +:: Show the last commit +echo Last commit on 'development' branch: +git --no-pager log -1 --pretty=format:"%%h - %%s (%%an, %%ar)" +echo. + +:: Pull the latest changes from the remote 'development' branch +git pull origin development --rebase + +:: Push the 'development' branch to the remote repository +git push origin development + +echo Successfully pushed changes to 'development' branch. diff --git a/Windows/PUSH-TO-PRODUCTION.bat b/Windows/PUSH-TO-PRODUCTION.bat new file mode 100644 index 0000000..740e057 --- /dev/null +++ b/Windows/PUSH-TO-PRODUCTION.bat @@ -0,0 +1,66 @@ +@echo off +setlocal ENABLEDELAYEDEXPANSION + +:: Ensure we're inside a Git repository +git rev-parse --git-dir > NUL 2>&1 +if ERRORLEVEL 1 ( + echo Error: This directory is not a Git repository. + exit /b 1 +) + +:: Get the current branch name +FOR /F "delims=" %%i IN ('git symbolic-ref --short HEAD') DO SET CURRENT_BRANCH=%%i + +:: Check if the current branch is 'development' +if NOT "!CURRENT_BRANCH!"=="development" ( + echo Error: You are not on the 'development' branch. + echo Please switch to the 'development' branch and run this script again. + exit /b 1 +) + +:: Prompt for a commit message +set /p COMMIT_MESSAGE=Enter your commit message: + +if "%COMMIT_MESSAGE%"=="" ( + echo Error: Commit message cannot be empty. + exit /b 1 +) + +:: Add all changes +git add --all + +:: Commit the changes with the provided message +git commit -m "%COMMIT_MESSAGE%" + +:: Show the last commit +echo Last commit on 'development' branch: +git --no-pager log -1 --pretty=format:"%%h - %%s (%%an, %%ar)" +echo. + +:: Prompt for confirmation to push to 'production' +set /p CONFIRMATION=Do you want to merge 'development' into 'production' and push to the remote repository? (yes/no): + +if /I NOT "%CONFIRMATION%"=="yes" ( + echo Aborting push to 'production' branch. + exit /b 0 +) + +:: Fetch the latest changes from the remote repository +git fetch origin + +:: Switch to the 'production' branch +git checkout production + +:: Pull the latest changes in 'production' branch +git pull origin production + +:: Merge 'development' into 'production' +git merge --no-ff development -m "Merge branch 'development' into 'production'" + +:: Push the 'production' branch to the remote repository +git push origin production + +:: Switch back to the 'development' branch +git checkout development + +echo Successfully pushed changes from 'development' to 'production' branch. diff --git a/Windows/start-all-servers.bat b/Windows/start-all-servers.bat new file mode 100644 index 0000000..697902f --- /dev/null +++ b/Windows/start-all-servers.bat @@ -0,0 +1,14 @@ +@echo off +echo Starting all servers... + +REM Open the Velocity proxy in a new Git Bash window +start "" "C:\Program Files\Git\bin\bash.exe" -c "C:/Users/pomam/Documents/Feyhallow/Development Environment/Development Servers/Proxy/startup-proxy-dev.sh" + +REM Open the first Minecraft server in a new Git Bash window +start "" "C:\Program Files\Git\bin\bash.exe" -c "C:/Users/pomam/Documents/Feyhallow/Development Environment/Development Servers/Lobby/startup-server-dev.sh" + +REM Open the second Minecraft server in a new Git Bash window +start "" "C:\Program Files\Git\bin\bash.exe" -c "C:/Users/pomam/Documents/Feyhallow/Development Environment/Development Servers/Survie/startup-server-dev.sh" + +echo All servers are starting in separate windows! +pause