From 40a053004480b0354e239849d6af879b8256b275 Mon Sep 17 00:00:00 2001 From: crt Date: Tue, 2 Jul 2024 12:13:30 +0000 Subject: [PATCH] Silly --- kiosk.sh | 217 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 kiosk.sh diff --git a/kiosk.sh b/kiosk.sh new file mode 100644 index 0000000..0073fe5 --- /dev/null +++ b/kiosk.sh @@ -0,0 +1,217 @@ +#!/bin/bash + + + +# Function to display command output in a dialog box +execute_command() { + output=$(mktemp /tmp/command_output.XXXXXX) + if "$@" >"$output" 2>&1; then + dialog --title "Command Output" --textbox "$output" 20 60 + else + dialog --title "Error Occurred" --textbox "$output" 20 60 + fi + rm "$output" +} + +# Function to install necessary packages for Debian +install_packages_debian() { + echo "Starting Package installation on Debian. Please check the terminal output." + sudo apt-get update && sudo apt-get install -y chromium tightvncserver xorg x11-xserver-utils unclutter openbox xdotool vnstat x11vnc +} + +# Function to install necessary packages for Raspberry Pi OS Lite +install_packages_raspberry() { + echo "Starting Package installation on Raspberry Pi OS Lite. Please check the terminal output." + sudo apt-get update && sudo apt-get install -y chromium-browser tightvncserver xorg x11-xserver-utils unclutter openbox xdotool vnstat x11vnc + sudo ln -s /usr/bin/chromium-browser /usr/bin/chromium +} + +# Installation selector based on distro +install_packages() { + DIALOG_RESULT=$(dialog --title "Select Distribution" --menu "Choose your Linux distribution:" 15 50 2 \ + 1 "Debian" \ + 2 "Raspberry Pi OS Lite" \ + 3>&1 1>&2 2>&3 3>&-) + + case "$DIALOG_RESULT" in + 1) install_packages_debian ;; + 2) install_packages_raspberry ;; + esac +} + +# Function to configure .xinitrc +configure_xinitrc() { + cat > /home/kiosk/.xinitrc << 'EOF' +#!/bin/sh + +# Disable power management, screen blanking and make cursor disappear if not moved +xset s off +xset -dpms +xset s noblank +unclutter -idle 0.1 -root & + +# Start Openbox session +openbox-session & +x11vnc -display :0 -auth guess -forever -rfbport 5901 & + +# Start Kiosk Script +/bin/bash /home/kiosk/start.sh +EOF + sudo chmod a+x /home/kiosk/.xinitrc +} + +# Function to configure automatic sign-in +configure_autologin() { + dialog --title "Automatic Login Configuration" --msgbox "Configuring automatic login..." 10 50 + sudo mkdir -p /etc/systemd/system/getty@tty1.service.d + sudo bash -c "cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << 'EOF' +[Service] +ExecStart= +ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM +EOF" +} + +# Function to configure start.sh with dynamic scaling factor for interactive or automated mode +configure_start_sh() { + SCALE_FACTOR=$(dialog --title "Display Scaling Factor" --inputbox "Enter the display scaling factor (e.g., 1 for 1080p, 2 for 4K):" 8 50 "1" 3>&1 1>&2 2>&3 3>&-) + + if [[ $# -eq 0 ]]; then # If no arguments, it's interactive mode + DIALOG_RESULT=$(dialog --title "start.sh Configuration" --menu "Choose the script example:" 15 50 2 \ + 1 "Simple website script" \ + 2 "Two or more tabs alternating every 30 seconds" \ + 3>&1 1>&2 2>&3 3>&-) + + if [ "$DIALOG_RESULT" = "1" ]; then + WEBSITE=$(dialog --title "Enter Website URL" --inputbox "Please enter the URL for the simple website:" 8 50 "https://www.example.com" 3>&1 1>&2 2>&3 3>&-) + set_start_script_single $SCALE_FACTOR $WEBSITE + elif [ "$DIALOG_RESULT" = "2" ]; then + TAB_COUNT=$(dialog --title "Number of Tabs" --inputbox "Enter number of tabs:" 8 50 "3" 3>&1 1>&2 2>&3 3>&-) + local tab_urls=() + for (( i=1; i<=TAB_COUNT; i++ )); do + URL=$(dialog --title "Enter URL for Tab $i" --inputbox "Enter URL:" 8 50 "http://example$i.com" 3>&1 1>&2 2>&3 3>&-) + tab_urls+=("$URL") + done + configure_tabs $SCALE_FACTOR "${tab_urls[@]}" + fi + else # Automated mode with URLs as arguments + if [ $# -eq 1 ]; then # Single website + set_start_script_single $SCALE_FACTOR $1 + else # Multiple tabs + configure_tabs $SCALE_FACTOR "$@" + fi + fi +} + + +# Helper function to configure start.sh for a single website +set_start_script_single() { + cat > /home/kiosk/start.sh < /home/kiosk/start.sh <> /home/$USER/.bashrc +} + + +# Check for help option +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + echo "Usage: $0 [--auto [ ... ]]" + echo "Options:" + echo " --auto Run the script in automatic mode with no user interaction." + echo " Requires specifying the distribution ('debian' or 'raspberry')," + echo " scaling factor (e.g., '1' for 1080p, '2' for 4K), and at least one URL." + echo " Additional URLs are optional and will open in new tabs." + echo " -h, --help Display this help and exit." + echo "" + echo "Example:" + echo " $0 --auto debian 1 \"https://www.example.com\"" + echo " $0 --auto raspberry 2 \"https://www.example1.com\" \"https://www.example2.com\"" + exit 0 +fi + +# Automated or interactive mode check +if [[ $1 == "--auto" ]]; then + distro=$2 + shift 2 # Remove the first two arguments (script name and distro) for URLs and scaling factor + scaling_factor=$1 + shift # Remove the scaling factor to get URLs + [[ $distro == "debian" ]] && install_packages_debian + [[ $distro == "raspberry" ]] && install_packages_raspberry + configure_xinitrc + configure_start_sh "$@" + configure_autologin + edit_bashrc +else +dialog --title "WARNING !!!" --msgbox "Do not run this script under any user other than "kiosk" and make sure the Kiosk user has sudo rights for the duration of the installation. In addition check out the -h command on this script if you wish to do the installation more automated!" 10 50 + # Main menu for guided installation + while true; do + CHOICE=$(dialog --title "Rafisa Kiosk Configuration Menu" --menu "Choose an option:" 20 60 10 \ + 1 "Install Required Packages" \ + 2 "Install .xinitrc file" \ + 3 "Configure and Install Kiosk script (start.sh)" \ + 4 "Enable Automatic Sign-In" \ + 5 "Append X autostart to .bashrc for console users" \ + 6 "Exit" \ + 3>&1 1>&2 2>&3 3>&-) + + case $CHOICE in + 1) install_packages ;; + 2) configure_xinitrc ;; + 3) configure_start_sh ;; + 4) configure_autologin ;; + 5) edit_bashrc ;; + 6) break ;; + *) echo "Invalid option. Try another one." >&2 + esac + done + dialog --title "Exit" --msgbox "If you completed all steps and no errors were shown to you, reboot now to test if the installation was successful." 10 50 +fi + +clear \ No newline at end of file