From 0300ef24071107271e41f0ac44e04507cc3e4a6c Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 29 Jun 2025 14:23:32 -0400 Subject: [PATCH] Update the install script --- install.sh | 102 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/install.sh b/install.sh index 8dd6688..6b3f3fa 100644 --- a/install.sh +++ b/install.sh @@ -14,11 +14,11 @@ install_prereqs() { sudo apt-get update -y sudo apt-get install docker.io -y sudo usermod -aG docker $(whoami) - sudo reboot + sudo su $(whoami) fi } -install_discord_bot() { +run_discord_bot() { local drb_container_name="drb-client-discord-bot" # Stop and remove existing container if it's running/exists if docker ps -a --format '{{.Names}}' | grep -q "^${drb_container_name}$"; then @@ -62,7 +62,7 @@ create_config_json() { if [ -f "$(pwd)/data/config.json" ]; then echo -e "${GREEN}Successfully created 'config.json'.${NC}" echo -e "${GREEN}Content of config.json:${NC}" - cat config.json + cat $(pwd)/data/config.json else echo -e "${RED}Error: Failed to create 'config.json'.${NC}" exit 1 # Exit with an error code if file creation fails @@ -95,12 +95,13 @@ start_docker_container() { echo -e "${GREEN}Starting new container '${container_name}' from image '${image_name}' with restart policy 'unless-stopped'.${NC}" # Run the container - if docker run -d \ - --name "${container_name}" \ - --restart unless-stopped \ - -v "$(pwd)/data":/data \ - --network=host \ - "${image_name}"; then + docker run -d \ + --name "${container_name}" \ + --restart unless-stopped \ + -v "$(pwd)/data":/data \ + --network=host \ + "${image_name}" + if docker ps -a --format '{{.Names}}' | grep -q "^${container_name}$"; then echo -e "${GREEN}Docker container '${container_name}' started successfully in detached mode.${NC}" echo -e "${GREEN}It is configured to restart automatically on daemon startup or if it exits (unless stopped manually).${NC}" echo -e "${GREEN}You can check its status with: docker ps -f name=${container_name}${NC}" @@ -113,16 +114,81 @@ start_docker_container() { # --- Main script execution --- -# Install PreReqs -install_prereqs +# Default flags +RUN_BOTH_DOCKERS=false +RUN_DISCORD_DOCKER=false +RUN_CLIENT_DOCKER=false +FULL_INSTALL=true -# Create config.json -create_config_json +# Parse command-line arguments +# We use a while loop with a case statement to handle different options. +# getopts is for short options (e.g., -r) +# For long options (e.g., --run), we'll handle them manually or use a more advanced parser. -# Build and Start Docker container -start_docker_container +while [[ "$#" -gt 0 ]]; do + case "$1" in + -r|--run) + RUN_BOTH_DOCKERS=true + FULL_INSTALL=false # If -r is passed, we don't do a full install + shift # Move to next argument + ;; + -c|--client) + RUN_CLIENT_DOCKER=true + FULL_INSTALL=false + shift + ;; + -d|--discord|-l) + RUN_DISCORD_DOCKER=true + FULL_INSTALL=false + shift + ;; + *) + echo "Unknown parameter passed: $1" + shift + ;; + esac +done -# Download the drb discord bot -install_discord_bot +if [ "$FULL_INSTALL" = true ]; then + echo -e "${GREEN}--- Starting full installation and setup ---${NC}" + # Install PreReqs + install_prereqs -echo -e "${GREEN}--- All installation and startup steps finished ---${NC}" \ No newline at end of file + # Create config.json + create_config_json + + # Build and Start Docker container + start_docker_container + + # Download/update and run the drb discord bot + run_discord_bot + + echo -e "${GREEN}--- All installation and startup steps finished ---${NC}" +elif [ "$RUN_BOTH_DOCKERS" = true ]; then + # Build and run the DRB client container + echo -e "${GREEN}--- Starting DRB Client Docker container ---${NC}" + start_docker_container + + # Download/update and run the DRB Discord Bot container + echo -e "${GREEN}--- Starting DRB Listener Docker container ---${NC}" + run_discord_bot + + echo -e "${GREEN}--- Docker containers startup finished ---${NC}" +elif [ "$RUN_DISCORD_DOCKER" = true ]; then + # Download/update and run the DRB Discord Bot container + echo -e "${GREEN}--- Starting DRB Listener Docker container ---${NC}" + run_discord_bot + + echo -e "${GREEN}--- Discord Docker container startup finished ---${NC}" +elif [ "$RUN_CLIENT_DOCKER" = true ]; then + # Build and run the DRB client container + echo -e "${GREEN}--- Starting DRB Client Docker container ---${NC}" + start_docker_container + + echo -e "${GREEN}--- Client Docker container startup finished ---${NC}" +else + # This case should ideally not be hit if flags are handled correctly, + # but it's here for completeness. + echo -e "${YELLOW}---No valid operation specified. Exiting.${NC}" + exit 1 +fi \ No newline at end of file