configure.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. # Function to display the menu
  3. show_menu() {
  4. DIALOG_RESULT=$(dialog --title "Configuration Menu" --menu "Choose an option:" 15 50 3 \
  5. 1 "Change Scaling, Kiosk Type, and Websites" \
  6. 2 "Change VNC Password" \
  7. 3 "Exit" \
  8. 3>&1 1>&2 2>&3 3>&-)
  9. echo $DIALOG_RESULT
  10. }
  11. # Function to configure start.sh
  12. configure_start_sh() {
  13. 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>&-)
  14. DIALOG_RESULT=$(dialog --title "start.sh Configuration" --menu "Choose the script example:" 15 50 2 \
  15. 1 "Simple website script" \
  16. 2 "Two or more tabs alternating every 30 seconds" \
  17. 3>&1 1>&2 2>&3 3>&-)
  18. if [ "$DIALOG_RESULT" = "1" ]; then
  19. 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>&-)
  20. set_start_script_single $SCALE_FACTOR $WEBSITE
  21. elif [ "$DIALOG_RESULT" = "2" ]; then
  22. TAB_COUNT=$(dialog --title "Number of Tabs" --inputbox "Enter number of tabs:" 8 50 "3" 3>&1 1>&2 2>&3 3>&-)
  23. local tab_urls=()
  24. for (( i=1; i<=TAB_COUNT; i++ )); do
  25. URL=$(dialog --title "Enter URL for Tab $i" --inputbox "Enter URL:" 8 50 "http://example$i.com" 3>&1 1>&2 2>&3 3>&-)
  26. tab_urls+=("$URL")
  27. done
  28. configure_tabs $SCALE_FACTOR "${tab_urls[@]}"
  29. fi
  30. }
  31. # Helper function to configure start.sh for a single website
  32. set_start_script_single() {
  33. VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
  34. mkdir -p /home/kiosk/.vnc
  35. rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
  36. echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
  37. chmod 600 /home/kiosk/.vnc/passwd
  38. # Write the script with properly formatted commands
  39. cat > /home/kiosk/start.sh <<EOF
  40. #!/bin/bash
  41. /usr/bin/chromium --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $2
  42. EOF
  43. chmod a+x /home/kiosk/start.sh
  44. }
  45. # Helper function to configure start.sh for multiple tabs
  46. configure_tabs() {
  47. local scaling_factor=$1
  48. shift # Remove the first argument (scaling factor) to loop over URLs
  49. local tab_urls=""
  50. for url in "$@"; do
  51. tab_urls+="'$url' " # Ensure URLs are properly quoted
  52. done
  53. VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
  54. mkdir -p /home/kiosk/.vnc
  55. rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
  56. echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
  57. chmod 600 /home/kiosk/.vnc/passwd
  58. # Write the script with properly formatted commands
  59. cat > /home/kiosk/start.sh <<EOF
  60. #!/bin/bash
  61. /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 &
  62. sleep 10 # Allow time for Chromium to launch
  63. # Function definitions should be placed before they are called
  64. switch_tabs() {
  65. WINDOW_ID=\$(xdotool search --onlyvisible --class chromium | head -n 1)
  66. xdotool windowactivate --sync \$WINDOW_ID
  67. xdotool key --window \$WINDOW_ID ctrl+Tab
  68. }
  69. is_vnc_active() {
  70. netstat -an | grep ':5901' | grep -q 'ESTABLISHED'
  71. return \$?
  72. }
  73. # Main loop to handle tab switching
  74. while true; do
  75. if is_vnc_active; then
  76. echo "VNC session active, pausing tab switch..."
  77. sleep 5
  78. else
  79. echo "VNC session inactive, switching tabs..."
  80. switch_tabs
  81. sleep 30
  82. fi
  83. done
  84. EOF
  85. chmod a+x /home/kiosk/start.sh
  86. }
  87. # Function to change VNC password
  88. change_vnc_password() {
  89. VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the new VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
  90. mkdir -p /home/kiosk/.vnc
  91. rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
  92. echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
  93. chmod 600 /home/kiosk/.vnc/passwd
  94. echo "VNC password changed"
  95. }
  96. # Main loop
  97. while true; do
  98. choice=$(show_menu)
  99. case $choice in
  100. 1) configure_start_sh ;;
  101. 2) change_vnc_password ;;
  102. 3) exit 0 ;;
  103. *) echo "Invalid option, please try again" ;;
  104. esac
  105. done