#!/bin/bash # --- Function to configure Git hooks path in repos --- function configure_git_hooks_path() { local BASE_DIR="." local HOOKS_PATH="githooks/" echo "Configuring local Git hooks path for repositories in the current directory..." for repo_dir in "$BASE_DIR"/*/; do if [ -d "$repo_dir/.git" ]; then repo_name=$(basename "$repo_dir") echo "-> Entering $repo_name..." ( cd "$repo_dir" || continue git config --local core.hooksPath "$HOOKS_PATH" echo " Git hooks path set to '$HOOKS_PATH' for $repo_name." ) fi done echo "Git configuration complete." } # --- Function to set up directories and namespaces --- function setup_environment() { echo "Setting up local directories and namespaces..." local INFRA_BASE="." echo "Creating infrastructure directories inside the current folder: $(pwd)" # Create infrastructure directories relative to the current folder mkdir -p "$INFRA_BASE/redis/cache/aurora" mkdir -p "$INFRA_BASE/redis/cache/shoprentersales" mkdir -p "$INFRA_BASE/minio/aurora" mkdir -p "$INFRA_BASE/rabbitmq/message" mkdir -p "$INFRA_BASE/rabbitmq/shipping-gateway" mkdir -p "$INFRA_BASE/rabbitmq/shoprenter-payment" mkdir -p "$INFRA_BASE/rabbitmq/payment-gateway" mkdir -p "$INFRA_BASE/redis/shipping-gateway" mkdir -p "$INFRA_BASE/redis/cache/imageservice" mkdir -p "$INFRA_BASE/minio/imageservice/data" mkdir -p "$INFRA_BASE/redis/cache/ms-sr-oauth" mkdir -p "$INFRA_BASE/redis/cart" mkdir -p "$INFRA_BASE/rabbitmq/sr-partner-dashboard" mkdir -p "$INFRA_BASE/rabbitmq/gls-app" mkdir -p "$INFRA_BASE/price-history-elasticsearch/data" mkdir -p "$INFRA_BASE/price-history-elasticsearch-test/data" mkdir -p "$INFRA_BASE/redis/mcp-server" mkdir -p "$INFRA_BASE/redis/translate-app" mkdir -p "$INFRA_BASE/rabbitmq/translate-app" echo "Directory setup complete." configure_git_hooks_path } # --- Function to add ingress entries to /etc/hosts --- function add_ingress_hosts() { echo "Adding ingress entries to /etc/hosts..." # Define the path to the hosts file HOSTS_FILE="/etc/hosts" # Get all ingress hostnames INGRESS_HOSTS=$(kubectl get ingress --all-namespaces | grep -v "NAMESPACE" | awk '{ print $4 }' | grep -v "HOSTS" | grep -v "ADDRESS" | tr ',' '\n' | sort -u) # Check if there are any ingress hosts to add if [ -z "$INGRESS_HOSTS" ]; then echo "No ingress hosts found to add. Skipping." return 0 fi # Get a list of hostnames already present in the hosts file EXISTING_HOSTS=$(grep -oE '\b[a-zA-Z0-9.-]+\b' "$HOSTS_FILE" | sort -u) # Use a temporary file to build the new hosts file content TEMP_HOSTS_FILE=$(mktemp) # Copy existing hosts file to the temporary file cat "$HOSTS_FILE" > "$TEMP_HOSTS_FILE" local new_entries_added=false # Append new ingress entries to the temporary file, only if they don't already exist echo "" >> "$TEMP_HOSTS_FILE" echo "# Kubernetes Ingress entries - added by setup script" >> "$TEMP_HOSTS_FILE" for host in $INGRESS_HOSTS; do if ! grep -q "$host" <<< "$EXISTING_HOSTS"; then echo "127.0.0.1 $host" >> "$TEMP_HOSTS_FILE" new_entries_added=true else echo "Host '$host' already exists in $HOSTS_FILE. Skipping." fi done if [ "$new_entries_added" = true ]; then # Use sudo to overwrite the original hosts file with the temporary one sudo cp "$TEMP_HOSTS_FILE" "$HOSTS_FILE" echo "New ingress entries successfully added to $HOSTS_FILE." else echo "No new ingress entries were added." fi # Clean up the temporary file rm "$TEMP_HOSTS_FILE" } # --- Main menu --- echo "Hello! What would you like to do?" PS3="Please enter your choice: " select option in "Set up environment" "Add Ingress entries" "Quit"; do case $option in "Set up environment") setup_environment break ;; "Add Ingress entries") add_ingress_hosts break ;; "Quit") echo "Exiting. Goodbye!" exit 0 ;; *) echo "Invalid option. Please try again." ;; esac done