configure.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #!/bin/bash
  2. # Function to display the menu
  3. show_menu() {
  4. echo "1) Change Hostname"
  5. echo "2) Change Timezone"
  6. echo "3) Configure .xinitrc"
  7. echo "4) Configure start.sh"
  8. echo "5) Configure Automatic Login"
  9. echo "6) Exit"
  10. }
  11. # Function to change hostname
  12. change_hostname() {
  13. read -p "Enter new hostname: " new_hostname
  14. sudo hostnamectl set-hostname "$new_hostname"
  15. echo "Hostname changed to $new_hostname"
  16. }
  17. # Function to change timezone
  18. change_timezone() {
  19. read -p "Enter new timezone (e.g., America/New_York): " new_timezone
  20. sudo timedatectl set-timezone "$new_timezone"
  21. echo "Timezone changed to $new_timezone"
  22. }
  23. # Function to configure .xinitrc
  24. configure_xinitrc() {
  25. cat > /home/kiosk/.xinitrc << 'EOF'
  26. #!/bin/sh
  27. # Disable power management, screen blanking and make cursor disappear if not moved
  28. xset s off
  29. xset -dpms
  30. xset s noblank
  31. unclutter -idle 0.1 -root &
  32. # Start Openbox session
  33. openbox-session &
  34. x11vnc -display :0 -rfbauth ~/.vnc/passwd -forever -rfbport 5901 &
  35. # Start Kiosk Script
  36. /bin/bash /home/kiosk/start.sh
  37. EOF
  38. sudo chmod a+x /home/kiosk/.xinitrc
  39. echo ".xinitrc configured"
  40. }
  41. # Function to configure start.sh
  42. configure_start_sh() {
  43. 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>&-)
  44. DIALOG_RESULT=$(dialog --title "start.sh Configuration" --menu "Choose the script example:" 15 50 2 \
  45. 1 "Simple website script" \
  46. 2 "Two or more tabs alternating every 30 seconds" \
  47. 3>&1 1>&2 2>&3 3>&-)
  48. if [ "$DIALOG_RESULT" = "1" ]; then
  49. 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>&-)
  50. set_start_script_single $SCALE_FACTOR $WEBSITE
  51. elif [ "$DIALOG_RESULT" = "2" ]; then
  52. TAB_COUNT=$(dialog --title "Number of Tabs" --inputbox "Enter number of tabs:" 8 50 "3" 3>&1 1>&2 2>&3 3>&-)
  53. local tab_urls=()
  54. for (( i=1; i<=TAB_COUNT; i++ )); do
  55. URL=$(dialog --title "Enter URL for Tab $i" --inputbox "Enter URL:" 8 50 "http://example$i.com" 3>&1 1>&2 2>&3 3>&-)
  56. tab_urls+=("$URL")
  57. done
  58. configure_tabs $SCALE_FACTOR "${tab_urls[@]}"
  59. fi
  60. }
  61. # Helper function to configure start.sh for a single website
  62. set_start_script_single() {
  63. VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
  64. mkdir -p /home/kiosk/.vnc
  65. rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
  66. echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
  67. chmod 600 /home/kiosk/.vnc/passwd
  68. # Write the script with properly formatted commands
  69. cat > /home/kiosk/start.sh <<EOF
  70. #!/bin/bash
  71. /usr/bin/chromium --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $2
  72. EOF
  73. chmod a+x /home/kiosk/start.sh
  74. }
  75. # Helper function to configure start.sh for multiple tabs
  76. configure_tabs() {
  77. local scaling_factor=$1
  78. shift # Remove the first argument (scaling factor) to loop over URLs
  79. local tab_urls=""
  80. for url in "$@"; do
  81. tab_urls+="'$url' " # Ensure URLs are properly quoted
  82. done
  83. VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
  84. mkdir -p /home/kiosk/.vnc
  85. rm -f /home/kiosk/.vnc/passwd # Remove existing password file if it exists
  86. echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
  87. chmod 600 /home/kiosk/.vnc/passwd
  88. # Write the script with properly formatted commands
  89. cat > /home/kiosk/start.sh <<EOF
  90. #!/bin/bash
  91. /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 &
  92. sleep 10 # Allow time for Chromium to launch
  93. # Function definitions should be placed before they are called
  94. switch_tabs() {
  95. WINDOW_ID=\$(xdotool search --onlyvisible --class chromium | head -n 1)
  96. xdotool windowactivate --sync \$WINDOW_ID
  97. xdotool key --window \$WINDOW_ID ctrl+Tab
  98. }
  99. is_vnc_active() {
  100. netstat -an | grep ':5901' | grep -q 'ESTABLISHED'
  101. return \$?
  102. }
  103. # Main loop to handle tab switching
  104. while true; do
  105. if is_vnc_active; then
  106. echo "VNC session active, pausing tab switch..."
  107. sleep 5
  108. else
  109. echo "VNC session inactive, switching tabs..."
  110. switch_tabs
  111. sleep 30
  112. fi
  113. done
  114. EOF
  115. chmod a+x /home/kiosk/start.sh
  116. }
  117. # Function to configure automatic sign-in
  118. configure_autologin() {
  119. dialog --title "Automatic Login Configuration" --msgbox "Configuring automatic login..." 10 50
  120. sudo mkdir -p /etc/systemd/system/getty@tty1.service.d
  121. sudo bash -c "cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << 'EOF'
  122. [Service]
  123. ExecStart=
  124. ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
  125. EOF"
  126. echo "Automatic login configured"
  127. }
  128. # Main loop
  129. while true; do
  130. show_menu
  131. read -p "Choose an option: " choice
  132. case $choice in
  133. 1) change_hostname ;;
  134. 2) change_timezone ;;
  135. 3) configure_xinitrc ;;
  136. 4) configure_start_sh ;;
  137. 5) configure_autologin ;;
  138. 6) exit 0 ;;
  139. *) echo "Invalid option, please try again" ;;
  140. esac
  141. done