From 4c2eff001198b83ba5dc4d559607f563a7c6b028 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 1 Sep 2025 14:16:35 +1200 Subject: [PATCH] config: Update 7 files --- .../config/docker-compose.yml | 6 +- squashkiwi-streaming/config/service.env | 4 +- squashkiwi-streaming/destroy.sh | 14 +++-- squashkiwi-streaming/install.sh | 4 +- squashkiwi-streaming/restore.sh | 61 +++++-------------- squashkiwi-streaming/start.sh | 1 - squashkiwi-streaming/uninstall.sh | 17 +----- 7 files changed, 31 insertions(+), 76 deletions(-) diff --git a/squashkiwi-streaming/config/docker-compose.yml b/squashkiwi-streaming/config/docker-compose.yml index 3a3573e..de82fb7 100644 --- a/squashkiwi-streaming/config/docker-compose.yml +++ b/squashkiwi-streaming/config/docker-compose.yml @@ -9,7 +9,7 @@ services: network_mode: host volumes: - ./mediamtx.yml:/mediamtx.yml - - ${RECORDINGS_PATH}:/recordings + - ${RECORDINGS_FOLDER}:/recordings environment: - MTX_PROTOCOLS=tcp - CAMERA_USER=${CAMERA_USER} @@ -34,7 +34,7 @@ services: depends_on: - mediamtx volumes: - - ${RECORDINGS_PATH}:/recordings + - ${RECORDINGS_FOLDER}:/recordings environment: - SQUASHKIWI_API=${SQUASHKIWI_API} - COURT_ID=${COURT_ID} @@ -58,7 +58,7 @@ services: volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro - ./web:/usr/share/nginx/html:ro - - ${RECORDINGS_PATH}:/recordings:ro + - ${RECORDINGS_FOLDER}:/recordings:ro - nginx-cache:/var/cache/nginx depends_on: - mediamtx diff --git a/squashkiwi-streaming/config/service.env b/squashkiwi-streaming/config/service.env index 71d9e53..23d5ee5 100644 --- a/squashkiwi-streaming/config/service.env +++ b/squashkiwi-streaming/config/service.env @@ -1,7 +1,8 @@ # SquashKiwi Streaming Configuration # Edit this file to configure your streaming service -LOCAL_DATA_FOLDER="/home/dropshell/example-squashkiwi-streaming" +LOCAL_DATA_FOLDER="/home/dropshell/example-squashkiwi-streaming-data" +RECORDINGS_FOLDER="/home/dropshell/example-squashkiwi-streaming-recordings" # Camera Configuration @@ -18,7 +19,6 @@ COURT_NAME=Court 1 SQUASHKIWI_API=https://squash.kiwi/api # Recording Settings -RECORDINGS_PATH="/home/dropshell/example-squashkiwi-streaming/recordings" RECORDING_RETENTION_DAYS=30 RECORDING_QUALITY=high IDLE_TIMEOUT=300 diff --git a/squashkiwi-streaming/destroy.sh b/squashkiwi-streaming/destroy.sh index 0698a54..e745f3d 100755 --- a/squashkiwi-streaming/destroy.sh +++ b/squashkiwi-streaming/destroy.sh @@ -1,11 +1,15 @@ #!/bin/bash # shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" -_check_required_env_vars "PROJECT_NAME" "LOCAL_DATA_FOLDER" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/_paths.sh" +_check_required_env_vars "LOCAL_DATA_FOLDER" -cd "${LOCAL_DATA_FOLDER}/config" || _die "Failed to change to config directory" +"${SCRIPT_DIR}/uninstall.sh" -echo "Destroying ${PROJECT_NAME} containers and networks..." -docker compose down -v || _die "Failed to destroy Docker Compose services" +# shellcheck disable=SC2046 +destroy_items $(get_squashkiwi_streaming_paths) || _die "Failed to destroy ${LOCAL_DATA_FOLDER}" +rm -rf "${RECORDINGS_FOLDER}" + +echo "Destroyed ${CONTAINER_NAME}" -echo "${PROJECT_NAME} destroyed (configuration and recordings preserved)" \ No newline at end of file diff --git a/squashkiwi-streaming/install.sh b/squashkiwi-streaming/install.sh index 4377bb8..85f7c28 100755 --- a/squashkiwi-streaming/install.sh +++ b/squashkiwi-streaming/install.sh @@ -8,13 +8,11 @@ _check_required_env_vars "PROJECT_NAME" "LOCAL_DATA_FOLDER" "CAMERA_IP" "COURT_I # Create directories # shellcheck disable=SC2046 create_items $(get_squashkiwi_streaming_paths) || _die "Failed to create directories" +mkdir -p "${RECORDINGS_FOLDER}" # Copy configuration files cp -r "${SCRIPT_DIR}/config/"* "${LOCAL_DATA_FOLDER}/config/" || _die "Failed to copy config files" -# Update recordings path in service.env -sed -i "s|RECORDINGS_PATH=.*|RECORDINGS_PATH=${LOCAL_DATA_FOLDER}/recordings|" "${LOCAL_DATA_FOLDER}/config/service.env" - # Test Docker _check_docker_installed || _die "Docker test failed, aborting installation..." diff --git a/squashkiwi-streaming/restore.sh b/squashkiwi-streaming/restore.sh index 9a0a4a2..e01382b 100755 --- a/squashkiwi-streaming/restore.sh +++ b/squashkiwi-streaming/restore.sh @@ -1,55 +1,22 @@ #!/bin/bash # shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" -_check_required_env_vars "PROJECT_NAME" "LOCAL_DATA_FOLDER" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/_paths.sh" +_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR" -BACKUP_DIR="${HOME}/backups/${PROJECT_NAME}" +# RESTORE SCRIPT +# The restore script is OPTIONAL. +# It is used to restore the service on the server from a backup file. +# It is called with one argument: the path to the backup file. -# List available backups -echo "Available backups:" -ls -1t "${BACKUP_DIR}"/*.tar.gz 2>/dev/null | head -10 | nl +# # Stop container before backup +"${SCRIPT_DIR}/uninstall.sh" || _die "Failed to uninstall service before restore" -if [[ $? -ne 0 ]]; then - echo "No backups found in ${BACKUP_DIR}" - exit 1 -fi +# shellcheck disable=SC2046 +restore_items $(get_squashkiwi_streaming_paths) || _die "Failed to restore data folder from backup" -# Select backup -read -p "Enter backup number to restore (or path to backup file): " selection +# reinstall service +"${SCRIPT_DIR}/install.sh" || _die "Failed to reinstall service after restore" -if [[ -f "$selection" ]]; then - BACKUP_FILE="$selection" -else - BACKUP_FILE=$(ls -1t "${BACKUP_DIR}"/*.tar.gz 2>/dev/null | sed -n "${selection}p") -fi - -if [[ ! -f "$BACKUP_FILE" ]]; then - echo "Backup file not found: ${BACKUP_FILE}" - exit 1 -fi - -echo "Restoring from: ${BACKUP_FILE}" -read -p "This will overwrite current configuration. Continue? (yes/no): " confirmation - -if [[ "$confirmation" != "yes" ]]; then - echo "Restore cancelled" - exit 0 -fi - -# Stop services -bash "${SCRIPT_DIR}/stop.sh" || true - -# Backup current config -if [[ -d "${LOCAL_DATA_FOLDER}/config" ]]; then - mv "${LOCAL_DATA_FOLDER}/config" "${LOCAL_DATA_FOLDER}/config.bak.$(date +%Y%m%d_%H%M%S)" -fi - -# Extract backup -tar -xzf "${BACKUP_FILE}" -C "${LOCAL_DATA_FOLDER}" || _die "Failed to extract backup" - -echo "✓ Backup restored" - -# Restart services -bash "${SCRIPT_DIR}/start.sh" - -echo "Restore complete!" \ No newline at end of file +echo "Restore complete! Service is running again on port $HOST_PORT with restored website." diff --git a/squashkiwi-streaming/start.sh b/squashkiwi-streaming/start.sh index 1001bdf..2cd12c9 100755 --- a/squashkiwi-streaming/start.sh +++ b/squashkiwi-streaming/start.sh @@ -1,7 +1,6 @@ #!/bin/bash # shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" _check_required_env_vars "PROJECT_NAME" "LOCAL_DATA_FOLDER" cd "${LOCAL_DATA_FOLDER}/config" || _die "Failed to change to config directory" diff --git a/squashkiwi-streaming/uninstall.sh b/squashkiwi-streaming/uninstall.sh index 2dba863..6209653 100755 --- a/squashkiwi-streaming/uninstall.sh +++ b/squashkiwi-streaming/uninstall.sh @@ -3,22 +3,9 @@ source "${AGENT_PATH}/common.sh" _check_required_env_vars "PROJECT_NAME" "LOCAL_DATA_FOLDER" -echo "WARNING: This will remove all ${PROJECT_NAME} containers, images, and data!" -echo "Recordings will be permanently deleted." -read -p "Are you sure? (yes/no): " confirmation - -if [[ "$confirmation" != "yes" ]]; then - echo "Uninstall cancelled" - exit 0 -fi - cd "${LOCAL_DATA_FOLDER}/config" || _die "Failed to change to config directory" # Stop and remove containers -docker compose down -v --rmi all || true +docker compose down || true -# Remove local data -echo "Removing local data folder: ${LOCAL_DATA_FOLDER}" -rm -rf "${LOCAL_DATA_FOLDER}" - -echo "${PROJECT_NAME} has been completely uninstalled" \ No newline at end of file +echo "${PROJECT_NAME} has been uninstalled"