#!/bin/bash # shellcheck disable=SC1091 source "${AGENT_PATH}/common.sh" _check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" echo "Starting Squash Display setup container..." # Get the directory where this script is located SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Check if setup.sh exists if [ ! -f "${SCRIPT_DIR}/setup.sh" ]; then echo "Error: setup.sh not found in ${SCRIPT_DIR}" _die "Setup script not found!" fi # Make setup script executable chmod +x ${SCRIPT_DIR}/setup.sh echo "Found setup script at: ${SCRIPT_DIR}/setup.sh" # Set default values for any unset variables KIOSK_URL="${KIOSK_URL:-https://squash.kiwi/court/otog}" KIOSK_USER="${KIOSK_USER:-squash}" DISPLAY_WIDTH="${DISPLAY_WIDTH:-1920}" DISPLAY_HEIGHT="${DISPLAY_HEIGHT:-1080}" DISPLAY_REFRESH="${DISPLAY_REFRESH:-60}" GPU_MEM="${GPU_MEM:-256}" ENABLE_WATCHDOG="${ENABLE_WATCHDOG:-true}" ENABLE_AUTO_LOGIN="${ENABLE_AUTO_LOGIN:-true}" ENABLE_HDMI_KEEP_ALIVE="${ENABLE_HDMI_KEEP_ALIVE:-true}" # Get system type from environment or try to detect it if [ -z "$SYSTEM_TYPE" ]; then # Auto-detect if not provided if [ -f "/proc/device-tree/model" ] && grep -qi "raspberry" /proc/device-tree/model 2>/dev/null; then SYSTEM_TYPE="rpi" elif [ -f "/etc/os-release" ]; then . /etc/os-release if [ "$ID" = "ubuntu" ] && [ "$(uname -m)" = "x86_64" ]; then SYSTEM_TYPE="ubuntu" elif [ "$ID" = "raspbian" ] || ([ "$ID" = "debian" ] && ([ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "armv7l" ])); then SYSTEM_TYPE="rpi" fi fi # Default to rpi if still not detected SYSTEM_TYPE="${SYSTEM_TYPE:-rpi}" fi # Build the docker run command - needs privileged access to configure host # Using --env-file to avoid quoting issues cat > /tmp/squashdisplay.env << EOF KIOSK_URL=${KIOSK_URL} KIOSK_USER=${KIOSK_USER} DISPLAY_WIDTH=${DISPLAY_WIDTH} DISPLAY_HEIGHT=${DISPLAY_HEIGHT} DISPLAY_REFRESH=${DISPLAY_REFRESH} GPU_MEM=${GPU_MEM} ENABLE_WATCHDOG=${ENABLE_WATCHDOG} ENABLE_AUTO_LOGIN=${ENABLE_AUTO_LOGIN} ENABLE_HDMI_KEEP_ALIVE=${ENABLE_HDMI_KEEP_ALIVE} SYSTEM_TYPE=${SYSTEM_TYPE} EOF DOCKER_RUN_CMD="docker run -d \ --restart no \ --name ${CONTAINER_NAME} \ --privileged \ --pid=host \ --network=host \ -v /:/host \ -v ${SCRIPT_DIR}/setup.sh:/setup.sh:ro \ --env-file /tmp/squashdisplay.env \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \ sh /setup.sh" # Create and start the container if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then rm -f /tmp/squashdisplay.env _die "Failed to start Squash Display setup container" fi # Clean up env file rm -f /tmp/squashdisplay.env # Wait for setup to complete echo "Running kiosk setup..." echo "This may take several minutes as packages are installed..." echo "" # Check if running interactively if [ -t 0 ]; then echo "Following setup progress (this may take 5-10 minutes)..." echo "You can also check progress with: docker logs -f ${CONTAINER_NAME}" echo "" # Follow the container logs until it exits docker logs -f ${CONTAINER_NAME} 2>&1 # Check if setup completed successfully EXIT_CODE=$(docker inspect ${CONTAINER_NAME} --format='{{.State.ExitCode}}') if [ "$EXIT_CODE" != "0" ]; then echo "Setup failed with exit code: $EXIT_CODE" echo "Check logs for details: docker logs ${CONTAINER_NAME}" exit 1 fi else echo "Setup running in background..." echo "Check progress with: docker logs -f ${CONTAINER_NAME}" echo "" # In non-interactive mode, just wait a moment for container to start sleep 5 # Check if container started successfully if ! _is_container_running "$CONTAINER_NAME"; then # Container already exited, check exit code EXIT_CODE=$(docker inspect ${CONTAINER_NAME} --format='{{.State.ExitCode}}' 2>/dev/null || echo "1") if [ "$EXIT_CODE" = "0" ]; then echo "Setup completed successfully!" else echo "Setup may have failed. Check status with: ./status.sh" echo "View logs with: docker logs ${CONTAINER_NAME}" fi else echo "Setup is running. Monitor with: docker logs -f ${CONTAINER_NAME}" echo "Check status with: ./status.sh" fi fi echo "" echo "Squash Display setup completed successfully!" echo "Container: ${CONTAINER_NAME}"