| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #!/bin/bash
- # Function to display the menu
- show_menu() {
- echo "1) Change Hostname"
- echo "2) Change Timezone"
- echo "3) Configure .xinitrc"
- echo "4) Configure start.sh"
- echo "5) Configure Automatic Login"
- echo "6) Exit"
- }
- # Function to change hostname
- change_hostname() {
- read -p "Enter new hostname: " new_hostname
- sudo hostnamectl set-hostname "$new_hostname"
- echo "Hostname changed to $new_hostname"
- }
- # Function to change timezone
- change_timezone() {
- read -p "Enter new timezone (e.g., America/New_York): " new_timezone
- sudo timedatectl set-timezone "$new_timezone"
- echo "Timezone changed to $new_timezone"
- }
- # 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 -rfbauth ~/.vnc/passwd -forever -rfbport 5901 &
- # Start Kiosk Script
- /bin/bash /home/kiosk/start.sh
- EOF
- sudo chmod a+x /home/kiosk/.xinitrc
- echo ".xinitrc configured"
- }
- # Function to configure start.sh
- 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>&-)
- 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
- }
- # Helper function to configure start.sh for a single website
- set_start_script_single() {
- VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
- mkdir -p /home/kiosk/.vnc
- rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
- echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
- chmod 600 /home/kiosk/.vnc/passwd
- # Write the script with properly formatted commands
- cat > /home/kiosk/start.sh <<EOF
- #!/bin/bash
- /usr/bin/chromium --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $2
- EOF
- chmod a+x /home/kiosk/start.sh
- }
- # Helper function to configure start.sh for multiple tabs
- configure_tabs() {
- local scaling_factor=$1
- shift # Remove the first argument (scaling factor) to loop over URLs
- local tab_urls=""
- for url in "$@"; do
- tab_urls+="'$url' " # Ensure URLs are properly quoted
- done
- VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
- mkdir -p /home/kiosk/.vnc
- rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
- echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
- chmod 600 /home/kiosk/.vnc/passwd
- # Write the script with properly formatted commands
- cat > /home/kiosk/start.sh <<EOF
- #!/bin/bash
- /usr/bin/chromium --incognito --force-device-scale-factor=$scaling_factor --temp-profile --disable-profiles --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $tab_urls &
- sleep 10 # Allow time for Chromium to launch
- # Function definitions should be placed before they are called
- switch_tabs() {
- WINDOW_ID=\$(xdotool search --onlyvisible --class chromium | head -n 1)
- xdotool windowactivate --sync \$WINDOW_ID
- xdotool key --window \$WINDOW_ID ctrl+Tab
- }
- is_vnc_active() {
- netstat -an | grep ':5901' | grep -q 'ESTABLISHED'
- return \$?
- }
- # Main loop to handle tab switching
- while true; do
- if is_vnc_active; then
- echo "VNC session active, pausing tab switch..."
- sleep 5
- else
- echo "VNC session inactive, switching tabs..."
- switch_tabs
- sleep 30
- fi
- done
- EOF
- chmod a+x /home/kiosk/start.sh
- }
- # 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"
- echo "Automatic login configured"
- }
- # Main loop
- while true; do
- show_menu
- read -p "Choose an option: " choice
- case $choice in
- 1) change_hostname ;;
- 2) change_timezone ;;
- 3) configure_xinitrc ;;
- 4) configure_start_sh ;;
- 5) configure_autologin ;;
- 6) exit 0 ;;
- *) echo "Invalid option, please try again" ;;
- esac
- done
|