Update the install script
This commit is contained in:
102
install.sh
102
install.sh
@@ -14,11 +14,11 @@ install_prereqs() {
|
|||||||
sudo apt-get update -y
|
sudo apt-get update -y
|
||||||
sudo apt-get install docker.io -y
|
sudo apt-get install docker.io -y
|
||||||
sudo usermod -aG docker $(whoami)
|
sudo usermod -aG docker $(whoami)
|
||||||
sudo reboot
|
sudo su $(whoami)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_discord_bot() {
|
run_discord_bot() {
|
||||||
local drb_container_name="drb-client-discord-bot"
|
local drb_container_name="drb-client-discord-bot"
|
||||||
# Stop and remove existing container if it's running/exists
|
# Stop and remove existing container if it's running/exists
|
||||||
if docker ps -a --format '{{.Names}}' | grep -q "^${drb_container_name}$"; then
|
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
|
if [ -f "$(pwd)/data/config.json" ]; then
|
||||||
echo -e "${GREEN}Successfully created 'config.json'.${NC}"
|
echo -e "${GREEN}Successfully created 'config.json'.${NC}"
|
||||||
echo -e "${GREEN}Content of config.json:${NC}"
|
echo -e "${GREEN}Content of config.json:${NC}"
|
||||||
cat config.json
|
cat $(pwd)/data/config.json
|
||||||
else
|
else
|
||||||
echo -e "${RED}Error: Failed to create 'config.json'.${NC}"
|
echo -e "${RED}Error: Failed to create 'config.json'.${NC}"
|
||||||
exit 1 # Exit with an error code if file creation fails
|
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}"
|
echo -e "${GREEN}Starting new container '${container_name}' from image '${image_name}' with restart policy 'unless-stopped'.${NC}"
|
||||||
# Run the container
|
# Run the container
|
||||||
if docker run -d \
|
docker run -d \
|
||||||
--name "${container_name}" \
|
--name "${container_name}" \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
-v "$(pwd)/data":/data \
|
-v "$(pwd)/data":/data \
|
||||||
--network=host \
|
--network=host \
|
||||||
"${image_name}"; then
|
"${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}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}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}"
|
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 ---
|
# --- Main script execution ---
|
||||||
|
|
||||||
# Install PreReqs
|
# Default flags
|
||||||
install_prereqs
|
RUN_BOTH_DOCKERS=false
|
||||||
|
RUN_DISCORD_DOCKER=false
|
||||||
|
RUN_CLIENT_DOCKER=false
|
||||||
|
FULL_INSTALL=true
|
||||||
|
|
||||||
# Create config.json
|
# Parse command-line arguments
|
||||||
create_config_json
|
# 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
|
while [[ "$#" -gt 0 ]]; do
|
||||||
start_docker_container
|
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
|
if [ "$FULL_INSTALL" = true ]; then
|
||||||
install_discord_bot
|
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
|
||||||
Reference in New Issue
Block a user