Update the install script

This commit is contained in:
Logan Cusano
2025-06-29 14:23:32 -04:00
parent f2fa623f4e
commit 0300ef2407

View File

@@ -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}"
# 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