From 308e0e3bc6211ffccdfdfbb0ec4e11a69b2dc624 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 8 Sep 2025 08:17:42 +1200 Subject: [PATCH] Update 2 and remove 3 files --- squashdisplay/install.sh | 18 ++- squashdisplay/scripts/kiosk.sh | 41 ----- squashdisplay/scripts/setup-host.sh | 180 --------------------- squashdisplay/scripts/watchdog.sh | 10 -- squashdisplay/start.sh | 234 +++++++++++++++++++++++++--- 5 files changed, 223 insertions(+), 260 deletions(-) delete mode 100755 squashdisplay/scripts/kiosk.sh delete mode 100755 squashdisplay/scripts/setup-host.sh delete mode 100755 squashdisplay/scripts/watchdog.sh diff --git a/squashdisplay/install.sh b/squashdisplay/install.sh index f98563a..4a92c5f 100755 --- a/squashdisplay/install.sh +++ b/squashdisplay/install.sh @@ -25,11 +25,16 @@ echo " - Setting up kiosk scripts" echo " - Disabling automatic updates" echo " - Configuring display settings" echo "" -read -p "Do you want to continue? (yes/no): " confirmation -if [ "$confirmation" != "yes" ]; then - echo "Installation cancelled." - exit 0 +# Check if running interactively (has a TTY) +if [ -t 0 ]; then + read -p "Do you want to continue? (yes/no): " confirmation + if [ "$confirmation" != "yes" ]; then + echo "Installation cancelled." + exit 0 + fi +else + echo "Running in non-interactive mode, proceeding with installation..." fi echo "Pulling Docker image..." @@ -42,10 +47,7 @@ if _is_container_exists "$CONTAINER_NAME"; then _remove_container "$CONTAINER_NAME" || true fi -# Make scripts executable -chmod +x ${SERVICE_PATH}/scripts/*.sh - -# Start the setup container +# Start the setup container (scripts are now embedded in start.sh) bash ./start.sh || _die "Failed to start Squash Display setup" echo "" diff --git a/squashdisplay/scripts/kiosk.sh b/squashdisplay/scripts/kiosk.sh deleted file mode 100755 index 448b183..0000000 --- a/squashdisplay/scripts/kiosk.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -# Kiosk startup script for Chromium browser - -# Disable screen blanking and power management -xset s noblank -xset s off -xset -dpms - -# Hide cursor after 1 second of inactivity -unclutter -idle 1 & - -# Force display resolution -xrandr --output HDMI-1 --mode ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} --rate ${DISPLAY_REFRESH} 2>/dev/null || \ -xrandr --output HDMI-2 --mode ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} --rate ${DISPLAY_REFRESH} 2>/dev/null || \ -xrandr --output default --mode ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} --rate ${DISPLAY_REFRESH} 2>/dev/null || true - -# Start Chromium in kiosk mode -chromium-browser \ - --window-size=${DISPLAY_WIDTH},${DISPLAY_HEIGHT} \ - --window-position=0,0 \ - --noerrdialogs \ - --disable-infobars \ - --disable-features=TranslateUI \ - --disable-extensions \ - --disable-plugins \ - --disable-web-security \ - --disable-features=VizDisplayCompositor \ - --start-fullscreen \ - --kiosk \ - --incognito \ - --no-first-run \ - --fast \ - --fast-start \ - --disable-default-apps \ - --disable-translate \ - --disable-background-timer-throttling \ - --disable-renderer-backgrounding \ - --disable-backgrounding-occluded-windows \ - --disable-component-extensions-with-background-pages \ - --autoplay-policy=no-user-gesture-required \ - "${KIOSK_URL}" \ No newline at end of file diff --git a/squashdisplay/scripts/setup-host.sh b/squashdisplay/scripts/setup-host.sh deleted file mode 100755 index 407237e..0000000 --- a/squashdisplay/scripts/setup-host.sh +++ /dev/null @@ -1,180 +0,0 @@ -#!/bin/sh -# Host setup script - runs inside privileged container to configure the host - -set -e - -echo "Starting Squash Display kiosk setup..." - -# Function to run commands on the host -host_exec() { - nsenter -t 1 -m -u -i -n -p -- "$@" -} - -# Install required packages -echo "Installing required packages..." -host_exec apt-get update -host_exec apt-get install -y chromium-browser xorg xinit x11-xserver-utils unclutter || \ -host_exec apt-get install -y chromium xorg xinit x11-xserver-utils unclutter - -# Create kiosk user if it doesn't exist -if ! host_exec id -u ${KIOSK_USER} >/dev/null 2>&1; then - echo "Creating user ${KIOSK_USER}..." - host_exec useradd -m -s /bin/bash ${KIOSK_USER} - host_exec usermod -aG video,audio ${KIOSK_USER} -fi - -# Setup auto-login if enabled -if [ "${ENABLE_AUTO_LOGIN}" = "true" ]; then - echo "Configuring auto-login for ${KIOSK_USER}..." - - # Create systemd override for getty@tty1 - host_exec mkdir -p /etc/systemd/system/getty@tty1.service.d - cat </dev/null || \ -xrandr --output HDMI-2 --mode ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} --rate ${DISPLAY_REFRESH} 2>/dev/null || \ -xrandr --output default --mode ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} --rate ${DISPLAY_REFRESH} 2>/dev/null || true - -# Start Chromium in kiosk mode -chromium-browser \ - --window-size=${DISPLAY_WIDTH},${DISPLAY_HEIGHT} \ - --window-position=0,0 \ - --noerrdialogs \ - --disable-infobars \ - --disable-features=TranslateUI \ - --disable-extensions \ - --disable-plugins \ - --disable-web-security \ - --disable-features=VizDisplayCompositor \ - --start-fullscreen \ - --kiosk \ - --incognito \ - --no-first-run \ - --fast \ - --fast-start \ - --disable-default-apps \ - --disable-translate \ - --disable-background-timer-throttling \ - --disable-renderer-backgrounding \ - --disable-backgrounding-occluded-windows \ - --disable-component-extensions-with-background-pages \ - --autoplay-policy=no-user-gesture-required \ - "${KIOSK_URL}" -EOF - -# Substitute environment variables -host_exec sed -i "s|\${DISPLAY_WIDTH}|${DISPLAY_WIDTH}|g" /home/${KIOSK_USER}/kiosk.sh -host_exec sed -i "s|\${DISPLAY_HEIGHT}|${DISPLAY_HEIGHT}|g" /home/${KIOSK_USER}/kiosk.sh -host_exec sed -i "s|\${DISPLAY_REFRESH}|${DISPLAY_REFRESH}|g" /home/${KIOSK_USER}/kiosk.sh -host_exec sed -i "s|\${KIOSK_URL}|${KIOSK_URL}|g" /home/${KIOSK_USER}/kiosk.sh - -host_exec chmod +x /home/${KIOSK_USER}/kiosk.sh -host_exec chown ${KIOSK_USER}:${KIOSK_USER} /home/${KIOSK_USER}/kiosk.sh - -# Setup watchdog if enabled -if [ "${ENABLE_WATCHDOG}" = "true" ]; then - echo "Setting up watchdog script..." - cat <<'EOF' | host_exec tee /home/${KIOSK_USER}/watchdog.sh -#!/bin/bash -while true; do - if ! pgrep chromium > /dev/null; then - echo "$(date): Chromium not running, restarting..." >> /home/${KIOSK_USER}/watchdog.log - DISPLAY=:0 /home/${KIOSK_USER}/kiosk.sh & - fi - sleep 30 -done -EOF - host_exec sed -i "s|\${KIOSK_USER}|${KIOSK_USER}|g" /home/${KIOSK_USER}/watchdog.sh - host_exec chmod +x /home/${KIOSK_USER}/watchdog.sh - host_exec chown ${KIOSK_USER}:${KIOSK_USER} /home/${KIOSK_USER}/watchdog.sh -fi - -# Configure .bashrc for auto-start -echo "Configuring auto-start..." -if ! host_exec grep -q "Auto-start X server" /home/${KIOSK_USER}/.bashrc 2>/dev/null; then - cat <<'EOF' | host_exec tee -a /home/${KIOSK_USER}/.bashrc - -# Auto-start X server and kiosk on login -if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]; then - exec startx ~/kiosk.sh -fi - -# Start watchdog in background -if [ "${ENABLE_WATCHDOG}" = "true" ]; then - ~/watchdog.sh & -fi -EOF - host_exec sed -i "s|\${ENABLE_WATCHDOG}|${ENABLE_WATCHDOG}|g" /home/${KIOSK_USER}/.bashrc -fi - -# Disable automatic updates -echo "Disabling automatic updates..." -host_exec systemctl disable apt-daily.service 2>/dev/null || true -host_exec systemctl disable apt-daily.timer 2>/dev/null || true -host_exec systemctl disable apt-daily-upgrade.timer 2>/dev/null || true -host_exec systemctl disable apt-daily-upgrade.service 2>/dev/null || true - -# Configure GPU memory split (Raspberry Pi specific) -if host_exec test -f /boot/firmware/config.txt || host_exec test -f /boot/config.txt; then - echo "Configuring GPU memory split..." - CONFIG_FILE="/boot/firmware/config.txt" - host_exec test -f /boot/config.txt && CONFIG_FILE="/boot/config.txt" - - if ! host_exec grep -q "^gpu_mem=" ${CONFIG_FILE}; then - echo "gpu_mem=${GPU_MEM}" | host_exec tee -a ${CONFIG_FILE} - else - host_exec sed -i "s/^gpu_mem=.*/gpu_mem=${GPU_MEM}/" ${CONFIG_FILE} - fi -fi - -# Setup HDMI keep-alive service if enabled -if [ "${ENABLE_HDMI_KEEP_ALIVE}" = "true" ]; then - echo "Setting up HDMI keep-alive service..." - cat <<'EOF' | host_exec tee /etc/systemd/system/hdmi-keep-alive.service -[Unit] -Description=Keep HDMI active -After=graphical.target - -[Service] -Type=simple -ExecStart=/bin/sh -c 'while true; do tvservice -p 2>/dev/null || true; sleep 60; done' -Restart=always -RestartSec=10 - -[Install] -WantedBy=graphical.target -EOF - host_exec systemctl daemon-reload - host_exec systemctl enable hdmi-keep-alive.service 2>/dev/null || true -fi - -echo "Squash Display kiosk setup complete!" -echo "" -echo "Configuration:" -echo " URL: ${KIOSK_URL}" -echo " User: ${KIOSK_USER}" -echo " Display: ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}@${DISPLAY_REFRESH}Hz" -echo " Watchdog: ${ENABLE_WATCHDOG}" -echo " Auto-login: ${ENABLE_AUTO_LOGIN}" -echo "" -echo "Please reboot the system for all changes to take effect." \ No newline at end of file diff --git a/squashdisplay/scripts/watchdog.sh b/squashdisplay/scripts/watchdog.sh deleted file mode 100755 index 9277ef1..0000000 --- a/squashdisplay/scripts/watchdog.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# Watchdog script to restart Chromium if it crashes - -while true; do - if ! pgrep chromium > /dev/null; then - echo "$(date): Chromium not running, restarting..." - DISPLAY=:0 /home/${KIOSK_USER}/kiosk.sh & - fi - sleep 30 -done \ No newline at end of file diff --git a/squashdisplay/start.sh b/squashdisplay/start.sh index 0e265bd..5ce36cb 100755 --- a/squashdisplay/start.sh +++ b/squashdisplay/start.sh @@ -5,6 +5,178 @@ _check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_T echo "Starting Squash Display setup container..." +# Create the setup script as a heredoc that will be executed in the container +SETUP_SCRIPT='#!/bin/sh +set -e + +echo "Starting Squash Display kiosk setup..." + +# Function to run commands on the host +host_exec() { + nsenter -t 1 -m -u -i -n -p -- "$@" +} + +# Install required packages +echo "Installing required packages..." +host_exec apt-get update +host_exec apt-get install -y chromium-browser xorg xinit x11-xserver-utils unclutter || \ +host_exec apt-get install -y chromium xorg xinit x11-xserver-utils unclutter + +# Create kiosk user if it does not exist +if ! host_exec id -u '"${KIOSK_USER}"' >/dev/null 2>&1; then + echo "Creating user '"${KIOSK_USER}"'..." + host_exec useradd -m -s /bin/bash '"${KIOSK_USER}"' + host_exec usermod -aG video,audio '"${KIOSK_USER}"' +fi + +# Setup auto-login if enabled +if [ "'"${ENABLE_AUTO_LOGIN}"'" = "true" ]; then + echo "Configuring auto-login for '"${KIOSK_USER}"'..." + + host_exec mkdir -p /etc/systemd/system/getty@tty1.service.d + cat </dev/null || \ +xrandr --output HDMI-2 --mode '"${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}"' --rate '"${DISPLAY_REFRESH}"' 2>/dev/null || \ +xrandr --output default --mode '"${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}"' --rate '"${DISPLAY_REFRESH}"' 2>/dev/null || true + +# Start Chromium in kiosk mode +chromium-browser \ + --window-size='"${DISPLAY_WIDTH},${DISPLAY_HEIGHT}"' \ + --window-position=0,0 \ + --noerrdialogs \ + --disable-infobars \ + --disable-features=TranslateUI \ + --disable-extensions \ + --disable-plugins \ + --disable-web-security \ + --disable-features=VizDisplayCompositor \ + --start-fullscreen \ + --kiosk \ + --incognito \ + --no-first-run \ + --fast \ + --fast-start \ + --disable-default-apps \ + --disable-translate \ + --disable-background-timer-throttling \ + --disable-renderer-backgrounding \ + --disable-backgrounding-occluded-windows \ + --disable-component-extensions-with-background-pages \ + --autoplay-policy=no-user-gesture-required \ + "'"${KIOSK_URL}"'" +KIOSKSCRIPT + +host_exec chmod +x /home/'"${KIOSK_USER}"'/kiosk.sh +host_exec chown '"${KIOSK_USER}:${KIOSK_USER}"' /home/'"${KIOSK_USER}"'/kiosk.sh + +# Setup watchdog if enabled +if [ "'"${ENABLE_WATCHDOG}"'" = "true" ]; then + echo "Setting up watchdog script..." + cat <<'"'"'WATCHDOG'"'"' | host_exec tee /home/'"${KIOSK_USER}"'/watchdog.sh +#!/bin/bash +while true; do + if ! pgrep chromium > /dev/null; then + echo "$(date): Chromium not running, restarting..." >> /home/'"${KIOSK_USER}"'/watchdog.log + DISPLAY=:0 /home/'"${KIOSK_USER}"'/kiosk.sh & + fi + sleep 30 +done +WATCHDOG + host_exec chmod +x /home/'"${KIOSK_USER}"'/watchdog.sh + host_exec chown '"${KIOSK_USER}:${KIOSK_USER}"' /home/'"${KIOSK_USER}"'/watchdog.sh +fi + +# Configure .bashrc for auto-start +echo "Configuring auto-start..." +if ! host_exec grep -q "Auto-start X server" /home/'"${KIOSK_USER}"'/.bashrc 2>/dev/null; then + cat <<'"'"'BASHRC'"'"' | host_exec tee -a /home/'"${KIOSK_USER}"'/.bashrc + +# Auto-start X server and kiosk on login +if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]; then + exec startx ~/kiosk.sh +fi + +# Start watchdog in background +if [ "'"${ENABLE_WATCHDOG}"'" = "true" ]; then + ~/watchdog.sh & +fi +BASHRC +fi + +# Disable automatic updates +echo "Disabling automatic updates..." +host_exec systemctl disable apt-daily.service 2>/dev/null || true +host_exec systemctl disable apt-daily.timer 2>/dev/null || true +host_exec systemctl disable apt-daily-upgrade.timer 2>/dev/null || true +host_exec systemctl disable apt-daily-upgrade.service 2>/dev/null || true + +# Configure GPU memory split (Raspberry Pi specific) +if host_exec test -f /boot/firmware/config.txt || host_exec test -f /boot/config.txt; then + echo "Configuring GPU memory split..." + CONFIG_FILE="/boot/firmware/config.txt" + host_exec test -f /boot/config.txt && CONFIG_FILE="/boot/config.txt" + + if ! host_exec grep -q "^gpu_mem=" ${CONFIG_FILE}; then + echo "gpu_mem='"${GPU_MEM}"'" | host_exec tee -a ${CONFIG_FILE} + else + host_exec sed -i "s/^gpu_mem=.*/gpu_mem='"${GPU_MEM}"'/" ${CONFIG_FILE} + fi +fi + +# Setup HDMI keep-alive service if enabled +if [ "'"${ENABLE_HDMI_KEEP_ALIVE}"'" = "true" ]; then + echo "Setting up HDMI keep-alive service..." + cat <<'"'"'HDMISERVICE'"'"' | host_exec tee /etc/systemd/system/hdmi-keep-alive.service +[Unit] +Description=Keep HDMI active +After=graphical.target + +[Service] +Type=simple +ExecStart=/bin/sh -c '"'"'while true; do tvservice -p 2>/dev/null || true; sleep 60; done'"'"' +Restart=always +RestartSec=10 + +[Install] +WantedBy=graphical.target +HDMISERVICE + host_exec systemctl daemon-reload + host_exec systemctl enable hdmi-keep-alive.service 2>/dev/null || true +fi + +echo "Squash Display kiosk setup complete!" +echo "" +echo "Configuration:" +echo " URL: '"${KIOSK_URL}"'" +echo " User: '"${KIOSK_USER}"'" +echo " Display: '"${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}@${DISPLAY_REFRESH}"'Hz" +echo " Watchdog: '"${ENABLE_WATCHDOG}"'" +echo " Auto-login: '"${ENABLE_AUTO_LOGIN}"'" +echo "" +echo "Please reboot the system for all changes to take effect." +' + # Build the docker run command - needs privileged access to configure host DOCKER_RUN_CMD="docker run -d \ --restart no \ @@ -13,18 +185,8 @@ DOCKER_RUN_CMD="docker run -d \ --pid=host \ --network=host \ -v /:/host \ - -v ${SERVICE_PATH}/scripts:/scripts:ro \ - -e KIOSK_URL=\"${KIOSK_URL}\" \ - -e KIOSK_USER=\"${KIOSK_USER}\" \ - -e DISPLAY_WIDTH=\"${DISPLAY_WIDTH}\" \ - -e DISPLAY_HEIGHT=\"${DISPLAY_HEIGHT}\" \ - -e DISPLAY_REFRESH=\"${DISPLAY_REFRESH}\" \ - -e GPU_MEM=\"${GPU_MEM}\" \ - -e ENABLE_WATCHDOG=\"${ENABLE_WATCHDOG}\" \ - -e ENABLE_AUTO_LOGIN=\"${ENABLE_AUTO_LOGIN}\" \ - -e ENABLE_HDMI_KEEP_ALIVE=\"${ENABLE_HDMI_KEEP_ALIVE}\" \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \ - sh /scripts/setup-host.sh" + sh -c 'echo \"${SETUP_SCRIPT}\" | sh'" # Create and start the container if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then @@ -33,17 +195,47 @@ fi # Wait for setup to complete echo "Running kiosk setup..." -echo "This may take a few minutes as packages are installed..." +echo "This may take several minutes as packages are installed..." +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 +# 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 ""