diff --git a/modules/netbird-strike b/modules/netbird-strike index 26ed747..2d3aa7a 100644 --- a/modules/netbird-strike +++ b/modules/netbird-strike @@ -1,69 +1,89 @@ #!/bin/bash # ----------------------------------------------------------------------- -# Dynasty Module: Universal NetBird Strike v1.1 (Dual-Native UI) +# Dynasty Module: NetBird Strike v0.1.2 # ----------------------------------------------------------------------- -# --- 1. OS & Architecture Detection --- -if [[ "$OSTYPE" == "darwin"* ]]; then - OS="macOS" - ARCH=$(uname -m) - NB_VERSION="0.30.1" +LOG_DIR="$HOME/.dynr/logs/netbird-strike" +mkdir -p "$LOG_DIR" +TS=$(date +"%Y%m%d_%H%M%S") +STRIKE_LOG="$LOG_DIR/strike_$TS.log" + +BLUE='\033[38;5;45m'; PURPLE='\033[38;5;127m'; GOLD='\033[38;5;178m'; RED='\033[38;5;196m'; NC='\033[0m' + +log_event() { echo -e "$1" | tee -a "$STRIKE_LOG"; } + +# --- 💀 Decimation Stance (Cleanup) --- +run_decimation() { + log_event "${RED}⚠️ INITIATING DECIMATION STANCE...${NC}" - if [[ "$ARCH" == "arm64" ]]; then - FILE_NAME="netbird_ui_darwin_arm64.pkg" - else - FILE_NAME="netbird_ui_darwin_amd64.pkg" - fi - PKG_URL="https://github.com/netbirdio/netbird/releases/download/v${NB_VERSION}/${FILE_NAME}" -else - OS="Linux" -fi + # Locate the netbird directory (usually /root/netbird or $HOME/netbird) + NB_PATH="/root/netbird" + [ ! -d "$NB_PATH" ] && NB_PATH="$HOME/netbird" -# --- 2. Execution Logic --- -echo "-------------------------------------------------" -echo "Initiating NetBird Strike v1.1 on $OS" -echo "-------------------------------------------------" - -if [[ "$OS" == "macOS" ]]; then - # macOS Native Strike - if ! command -v netbird &> /dev/null; then - echo "ACTION: Downloading Native Package for $ARCH..." - curl -L "$PKG_URL" -o "/tmp/netbird.pkg" - - echo "ACTION: Installing (Admin Password Required)..." - sudo installer -pkg "/tmp/netbird.pkg" -target / - rm "/tmp/netbird.pkg" + if [ -d "$NB_PATH" ] && [ -f "$NB_PATH/docker-compose.yml" ]; then + read -p "Run 'docker compose down' to stop and clean networks? (y/n): " DO_DOWN + if [[ "$DO_DOWN" == "y" ]]; then + log_event "ACTION: Bringing down Docker mesh..." + cd "$NB_PATH" && sudo docker compose down 2>&1 | tee -a "$STRIKE_LOG" + cd - > /dev/null + fi else - echo "STATUS: NetBird is already manifested on this Mac." + log_event "NOTE: No docker-compose.yml found in $NB_PATH. Skipping 'down' command." fi -else - # Linux Strike - if ! command -v netbird &> /dev/null; then - echo "ACTION: Fetching Linux Repository..." - curl -sSL https://pkgs.netbird.io/install.sh | sudo bash - else - echo "STATUS: NetBird already exists in this realm." - fi -fi -# --- 3. The Dual-Native UI Prompt --- -if [[ "$OS" == "macOS" ]]; then - # Native macOS Popup Box - SETUP_KEY=$(osascript -e 'display dialog "Enter your NetBird Setup Key (Leave blank for UI login):" default answer "" with title "Dynasty NetBird Manifest" buttons {"Cancel", "Strike"} default button "Strike"' -e 'text returned of result' 2>/dev/null) - # If user hits Cancel, exit gracefully - if [ $? -ne 0 ]; then - echo "Operation Cancelled." - exit 0 + read -p "DELETE all NetBird configuration and data files? (y/n): " PURGE_DATA + if [[ "$PURGE_DATA" == "y" ]]; then + echo -e "${RED}Final Warning: This will delete all keys and mesh data!${NC}" + read -p "Type 'PURGE' to confirm: " FINAL_VAL + if [[ "$FINAL_VAL" == "PURGE" ]]; then + log_event "ACTION: Purging directories..." + sudo rm -rf /root/netbird 2>> "$STRIKE_LOG" + sudo rm -rf "$HOME/netbird" 2>> "$STRIKE_LOG" + sudo rm -rf "$HOME/.netbird" 2>> "$STRIKE_LOG" + log_event "STATUS: Configuration wiped." + else + log_event "Purge aborted." + fi fi -else - # Native Linux Terminal Box (Fallback to read if no whiptail) - if command -v whiptail >/dev/null 2>&1; then - SETUP_KEY=$(whiptail --title "NetBird Manifest" --inputbox "Enter your Setup Key (Leave blank for UI login):" 10 60 3>&1 1>&2 2>&3) - else - echo "-------------------------------------------------" - read -p "Enter Setup Key (or leave blank for UI login): " SETUP_KEY < /dev/tty - fi -fi +} -# --- 4. Final Connection --- -if [[ -n "$SETUP_ \ No newline at end of file +# --- 🏗️ Forge Stance (Install) --- +run_forge() { + [[ "$OSTYPE" == "darwin"* ]] && { echo -e "${RED}Forge requires Linux (Docker).${NC}"; return; } + + log_event "${GOLD}Initiating Server Forge...${NC}" + read -p "Confirm NetBird SERVER installation? (y/n): " CONFIRM + [[ "$CONFIRM" != "y" ]] && return + + # Granular Dependency Check + MISSING=() + command -v curl &> /dev/null || MISSING+=("curl") + command -v jq &> /dev/null || MISSING+=("jq") + if ! command -v docker &> /dev/null; then + MISSING+=("docker") + else + ! docker compose version &> /dev/null && MISSING+=("docker-compose-v2") + fi + + if [ ${#MISSING[@]} -gt 0 ]; then + echo -e "${RED}⚠️ Missing Dependencies: ${MISSING[*]}${NC}" + read -p "Allow Dynasty to install these now? (y/n): " PERM + if [[ "$PERM" == "y" ]]; then + sudo apt update -qq + [[ " ${MISSING[*]} " == *" curl "* ]] && sudo apt install -y curl + [[ " ${MISSING[*]} " == *" jq "* ]] && sudo apt install -y jq + if [[ " ${MISSING[*]} " == *" docker "* || " ${MISSING[*]} " == *" docker-compose "* ]]; then + curl -fsSL https://get.docker.com | sh + sudo apt install -y docker-compose-plugin + fi + else + log_event "Rejected dependencies. Forge cancelled."; return + fi + fi + + log_event "ACTION: Executing Overlord Script..." + curl -fsSL https://github.com/netbirdio/netbird/releases/latest/download/getting-started.sh | bash 2>&1 | tee -a "$STRIKE_LOG" +} + +# --- Main Interface --- +# [Menu Logic with Client/Forge/Decimate options] \ No newline at end of file