configure-boot.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/bash
  2. # Configure boot and session options for Dune Weaver Touch
  3. set -e
  4. if [ "$EUID" -ne 0 ]; then
  5. echo "❌ This script must be run as root (use sudo)"
  6. exit 1
  7. fi
  8. ACTUAL_USER="${SUDO_USER:-$USER}"
  9. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  10. echo "🔧 Dune Weaver Touch - Boot Configuration"
  11. echo "=========================================="
  12. echo "Current user: $ACTUAL_USER"
  13. echo ""
  14. show_current_config() {
  15. echo "📊 Current Configuration:"
  16. # Check auto-login status
  17. if [ -f /etc/lightdm/lightdm.conf.d/60-autologin.conf ]; then
  18. echo " ✅ Auto-login: Enabled (lightdm)"
  19. elif grep -q "autologin-user=" /etc/lightdm/lightdm.conf 2>/dev/null; then
  20. echo " ✅ Auto-login: Enabled (lightdm main config)"
  21. elif [ -f /etc/systemd/system/getty@tty1.service.d/override.conf ]; then
  22. echo " ✅ Auto-login: Enabled (systemd)"
  23. else
  24. echo " ❌ Auto-login: Disabled"
  25. fi
  26. # Check service status
  27. if systemctl is-enabled dune-weaver-touch >/dev/null 2>&1; then
  28. echo " ✅ Service: Enabled (starts on boot)"
  29. else
  30. echo " ❌ Service: Disabled"
  31. fi
  32. # Check kiosk session
  33. if [ -f /usr/share/xsessions/dune-weaver-kiosk.session ]; then
  34. echo " ✅ Kiosk Session: Available"
  35. else
  36. echo " ❌ Kiosk Session: Not installed"
  37. fi
  38. echo ""
  39. }
  40. enable_auto_login() {
  41. echo "🔑 Enabling auto-login..."
  42. if [ -d /etc/lightdm ]; then
  43. mkdir -p /etc/lightdm/lightdm.conf.d
  44. cat > /etc/lightdm/lightdm.conf.d/60-autologin.conf << EOF
  45. [Seat:*]
  46. autologin-user=$ACTUAL_USER
  47. autologin-user-timeout=0
  48. user-session=LXDE-pi
  49. EOF
  50. echo " ✅ lightdm auto-login enabled"
  51. else
  52. # Fallback to systemd
  53. mkdir -p /etc/systemd/system/getty@tty1.service.d
  54. cat > /etc/systemd/system/getty@tty1.service.d/override.conf << EOF
  55. [Service]
  56. ExecStart=
  57. ExecStart=-/sbin/agetty --autologin $ACTUAL_USER --noclear %I \$TERM
  58. EOF
  59. systemctl daemon-reload
  60. echo " ✅ systemd auto-login enabled"
  61. fi
  62. }
  63. disable_auto_login() {
  64. echo "🔑 Disabling auto-login..."
  65. # Remove lightdm auto-login configs
  66. rm -f /etc/lightdm/lightdm.conf.d/60-autologin.conf
  67. if [ -f /etc/lightdm/lightdm.conf ]; then
  68. sed -i "s/^autologin-user=.*/#autologin-user=/" /etc/lightdm/lightdm.conf
  69. fi
  70. # Remove systemd auto-login
  71. rm -rf /etc/systemd/system/getty@tty1.service.d
  72. systemctl daemon-reload
  73. echo " ✅ Auto-login disabled"
  74. }
  75. enable_service() {
  76. echo "🚀 Enabling Dune Weaver service..."
  77. systemctl enable dune-weaver-touch.service
  78. echo " ✅ Service will start on boot"
  79. }
  80. disable_service() {
  81. echo "🚀 Disabling Dune Weaver service..."
  82. systemctl disable dune-weaver-touch.service
  83. systemctl stop dune-weaver-touch.service 2>/dev/null || true
  84. echo " ✅ Service disabled"
  85. }
  86. # Show current status
  87. show_current_config
  88. # Main menu
  89. echo "Choose configuration:"
  90. echo "1) Full Kiosk Mode (auto-login + service enabled)"
  91. echo "2) Service Only (manual login, auto-start service)"
  92. echo "3) Manual Mode (manual login, manual start)"
  93. echo "4) Toggle auto-login only"
  94. echo "5) Toggle service only"
  95. echo "6) Show current status"
  96. echo "7) Exit"
  97. echo ""
  98. read -p "Enter your choice (1-7): " choice
  99. case $choice in
  100. 1)
  101. enable_auto_login
  102. enable_service
  103. echo ""
  104. echo "🎯 Full kiosk mode enabled!"
  105. echo " Reboot to see the changes"
  106. ;;
  107. 2)
  108. disable_auto_login
  109. enable_service
  110. echo ""
  111. echo "🔧 Service-only mode enabled!"
  112. echo " Manual login required, but service starts automatically"
  113. ;;
  114. 3)
  115. disable_auto_login
  116. disable_service
  117. echo ""
  118. echo "🛠️ Manual mode enabled!"
  119. echo " Manual login and manual service start required"
  120. ;;
  121. 4)
  122. if [ -f /etc/lightdm/lightdm.conf.d/60-autologin.conf ] || [ -f /etc/systemd/system/getty@tty1.service.d/override.conf ]; then
  123. disable_auto_login
  124. else
  125. enable_auto_login
  126. fi
  127. ;;
  128. 5)
  129. if systemctl is-enabled dune-weaver-touch >/dev/null 2>&1; then
  130. disable_service
  131. else
  132. enable_service
  133. fi
  134. ;;
  135. 6)
  136. show_current_config
  137. ;;
  138. 7)
  139. echo "👋 Exiting..."
  140. exit 0
  141. ;;
  142. *)
  143. echo "❌ Invalid choice"
  144. exit 1
  145. ;;
  146. esac
  147. echo ""
  148. echo "✅ Configuration updated!"