configure.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # Write the script with properly formatted commands
  34. cat > /home/kiosk/start.sh <<EOF
  35. #!/bin/bash
  36. /usr/bin/chromium --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $2
  37. EOF
  38. chmod a+x /home/kiosk/start.sh
  39. }
  40. # Helper function to configure start.sh for multiple tabs
  41. configure_tabs() {
  42. local scaling_factor=$1
  43. shift # Remove the first argument (scaling factor) to loop over URLs
  44. local tab_urls=""
  45. for url in "$@"; do
  46. tab_urls+="'$url' " # Ensure URLs are properly quoted
  47. done
  48. # Write the script with properly formatted commands
  49. cat > /home/kiosk/start.sh <<EOF
  50. #!/bin/bash
  51. /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 &
  52. sleep 10 # Allow time for Chromium to launch
  53. # Function definitions should be placed before they are called
  54. switch_tabs() {
  55. WINDOW_ID=\$(xdotool search --onlyvisible --class chromium | head -n 1)
  56. xdotool windowactivate --sync \$WINDOW_ID
  57. xdotool key --window \$WINDOW_ID ctrl+Tab
  58. }
  59. is_vnc_active() {
  60. netstat -an | grep ':5901' | grep -q 'ESTABLISHED'
  61. return \$?
  62. }
  63. # Main loop to handle tab switching
  64. while true; do
  65. if is_vnc_active; then
  66. echo "VNC session active, pausing tab switch..."
  67. sleep 5
  68. else
  69. echo "VNC session inactive, switching tabs..."
  70. switch_tabs
  71. sleep 30
  72. fi
  73. done
  74. EOF
  75. chmod a+x /home/kiosk/start.sh
  76. }
  77. # Function to change VNC password
  78. change_vnc_password() {
  79. VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the new VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
  80. mkdir -p /home/kiosk/.vnc
  81. rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
  82. echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
  83. chmod 600 /home/kiosk/.vnc/passwd
  84. echo "VNC password changed"
  85. }
  86. # Main loop
  87. while true; do
  88. choice=$(show_menu)
  89. case $choice in
  90. 1) configure_start_sh ;;
  91. 2) change_vnc_password ;;
  92. 3) exit 0 ;;
  93. *) echo "Invalid option, please try again" ;;
  94. esac
  95. done