Add script for managing torrentarr containers (not in use)
This commit is contained in:
89
scripts/torrentarr.sh
Executable file
89
scripts/torrentarr.sh
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define available options as a simple array
|
||||
OPTIONS=("tv" "movies" "all")
|
||||
|
||||
# Default values
|
||||
TARGET_ALL=true
|
||||
INSTANCE="all"
|
||||
ACTION="up"
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
--down|-d)
|
||||
ACTION="down"
|
||||
;;
|
||||
--restart|-r)
|
||||
ACTION="restart"
|
||||
;;
|
||||
*)
|
||||
# Assume this is the instance name
|
||||
INSTANCE="$1"
|
||||
# Only set TARGET_ALL to false if a specific instance is provided
|
||||
if [ "$INSTANCE" != "all" ]; then
|
||||
TARGET_ALL=false
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Validate the instance name
|
||||
if ! [[ " ${OPTIONS[*]} " == *" ${INSTANCE} "* ]]; then
|
||||
echo "Unknown instance: $INSTANCE"
|
||||
echo "Valid options: ${OPTIONS[*]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to execute docker compose commands
|
||||
run_docker_compose() {
|
||||
local instance=$1
|
||||
local action=$2
|
||||
local ENV_FILE="./${instance}.env"
|
||||
|
||||
if [ "$action" == "restart" ]; then
|
||||
echo "Restart: Stopping $instance torrentarr instance..."
|
||||
docker compose --env-file "$ENV_FILE" down --remove-orphans
|
||||
echo "Restart: Starting $instance torrentarr instance..."
|
||||
docker compose --env-file "$ENV_FILE" up -d
|
||||
else
|
||||
if [ "$action" == "down" ]; then
|
||||
echo "Stopping $inst torrentarr instance..."
|
||||
docker compose --env-file "$ENV_FILE" down --remove-orphans
|
||||
echo "Stopped $inst torrentarr instance."
|
||||
elif [ "$action" == "up" ]; then
|
||||
echo "Starting $inst torrentarr instance..."
|
||||
docker compose --env-file "$ENV_FILE" up -d
|
||||
echo "Started $inst torrentarr instance."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle all instances or specific instance
|
||||
if [ "$TARGET_ALL" = true ]; then
|
||||
if [ "$ACTION" == "up" ]; then
|
||||
echo "Starting all instances..."
|
||||
elif [ "$ACTION" == "down" ]; then
|
||||
echo "Stopping all instances..."
|
||||
elif [ "$ACTION" == "restart" ]; then
|
||||
echo "Restarting all instances..."
|
||||
fi
|
||||
|
||||
# Loop through all options except "all"
|
||||
for inst in "${OPTIONS[@]}"; do
|
||||
if [ "$inst" != "all" ]; then
|
||||
run_docker_compose "$inst" $ACTION
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$ACTION" == "up" ]; then
|
||||
echo "Started all instances"
|
||||
elif [ "$ACTION" == "down" ]; then
|
||||
echo "Stopped all instances"
|
||||
elif [ "$ACTION" == "restart" ]; then
|
||||
echo "Restarted all instances"
|
||||
fi
|
||||
else
|
||||
run_docker_compose "$INSTANCE" $ACTION
|
||||
fi
|
||||
Reference in New Issue
Block a user