#!/bin/bash # DOXA-SECRET Installation Script # --- Settings --- APP_NAME="doxa-secret" INSTALL_DIR="$HOME/.local/bin" CONFIG_DIR="$HOME/.doxa-secret" # --- Functions --- error_exit() { echo -e "\033[1;31mERROR: $1\033[0m" >&2 exit 1 } success_message() { echo -e "\033[1;32mSUCCESS: $1\033[0m" } info_message() { echo -e "\033[1;34mINFO: $1\033[0m" } # --- Main Script --- info_message "Checking Go installation..." if ! command -v go &> /dev/null then error_exit "Go is not installed. Please install Go before running this script." fi success_message "Go is installed." info_message "Downloading project dependencies..." if ! go mod download then error_exit "Failed to download Go dependencies. Check your connection." fi success_message "Project dependencies downloaded." info_message "Compiling application..." APP_BINARY="$APP_NAME" if ! go build -o "$APP_BINARY" . then error_exit "Failed to compile application." fi success_message "Application compiled successfully to './$APP_BINARY'." info_message "Installing application..." if ! mkdir -p "$INSTALL_DIR" then error_exit "Failed to create installation directory '$INSTALL_DIR'." fi if ! cp "$APP_BINARY" "$INSTALL_DIR/" then error_exit "Failed to copy binary to '$INSTALL_DIR'." fi chmod +x "$INSTALL_DIR/$APP_NAME" success_message "Application '$APP_NAME' installed to '$INSTALL_DIR'." info_message "Setting up configuration directory..." if ! mkdir -p "$CONFIG_DIR" then error_exit "Failed to create config directory '$CONFIG_DIR'." fi success_message "Configuration directory '$CONFIG_DIR' ready." info_message "Installation finished." success_message "You can now run '$APP_NAME' from anywhere in your terminal." echo "" echo -e "\033[1;33mPRO TIP:\nIf \`$APP_NAME\` is not recognized, make sure '$INSTALL_DIR' is in your PATH.\nYou can add it by appending the following line to your shell profile (~/.bashrc, ~/.zshrc, or ~/.profile):\n\nexport PATH=\$PATH:$INSTALL_DIR\n\nThen restart your terminal or reload the profile (e.g. \`source ~/.bashrc\`).\033[0m" echo "" # Clean up local binary rm "$APP_BINARY" exit 0