setup-autostart.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/bin/bash
  2. # Setup Dune Weaver Touch to start automatically on boot
  3. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. ACTUAL_USER="${SUDO_USER:-$USER}"
  5. USER_HOME=$(eval echo ~$ACTUAL_USER)
  6. echo "=== Dune Weaver Touch Auto-Start Setup ==="
  7. echo "App directory: $SCRIPT_DIR"
  8. echo "User: $ACTUAL_USER"
  9. echo ""
  10. # Function to install system scripts
  11. install_scripts() {
  12. echo "Installing system scripts..."
  13. if [ "$EUID" -ne 0 ]; then
  14. echo "❌ Script installation requires root privileges. Run with sudo."
  15. return 1
  16. fi
  17. "$SCRIPT_DIR/scripts/install-scripts.sh"
  18. echo "✅ System scripts installed"
  19. }
  20. # Function to setup systemd service
  21. setup_systemd() {
  22. echo "Setting up systemd service..."
  23. # Check if running as root
  24. if [ "$EUID" -ne 0 ]; then
  25. echo "❌ Systemd setup requires root privileges. Run with sudo."
  26. return 1
  27. fi
  28. # Install scripts first
  29. install_scripts
  30. # Update paths in the service file
  31. sed "s|/home/pi/dune-weaver-touch|$SCRIPT_DIR|g" "$SCRIPT_DIR/dune-weaver-touch.service" > /tmp/dune-weaver-touch.service
  32. sed -i "s|User=pi|User=$ACTUAL_USER|g" /tmp/dune-weaver-touch.service
  33. sed -i "s|Group=pi|Group=$ACTUAL_USER|g" /tmp/dune-weaver-touch.service
  34. # Copy service file
  35. cp /tmp/dune-weaver-touch.service /etc/systemd/system/
  36. # Enable service
  37. systemctl daemon-reload
  38. systemctl enable dune-weaver-touch.service
  39. echo "✅ Systemd service installed and enabled"
  40. echo " The app will start automatically on boot"
  41. echo ""
  42. echo "Service commands:"
  43. echo " sudo systemctl start dune-weaver-touch"
  44. echo " sudo systemctl stop dune-weaver-touch"
  45. echo " sudo systemctl status dune-weaver-touch"
  46. echo " sudo journalctl -u dune-weaver-touch -f"
  47. }
  48. # Function to setup desktop autostart
  49. setup_desktop() {
  50. echo "Setting up desktop autostart..."
  51. # Create autostart directory if it doesn't exist
  52. mkdir -p "$USER_HOME/.config/autostart"
  53. # Update paths in desktop file
  54. sed "s|/home/pi/dune-weaver-touch|$SCRIPT_DIR|g" "$SCRIPT_DIR/dune-weaver-touch.desktop" > "$USER_HOME/.config/autostart/dune-weaver-touch.desktop"
  55. # Make sure the user owns the file
  56. chown $ACTUAL_USER:$ACTUAL_USER "$USER_HOME/.config/autostart/dune-weaver-touch.desktop"
  57. echo "✅ Desktop autostart configured"
  58. echo " The app will start when the user logs in"
  59. }
  60. # Function to setup boot splash (optional)
  61. setup_boot_splash() {
  62. echo "Setting up boot splash screen..."
  63. if [ "$EUID" -ne 0 ]; then
  64. echo "❌ Boot splash setup requires root privileges. Run with sudo."
  65. return 1
  66. fi
  67. # Disable boot messages for cleaner boot
  68. if ! grep -q "quiet splash" /boot/cmdline.txt; then
  69. sed -i 's/$/ quiet splash/' /boot/cmdline.txt
  70. echo "✅ Boot splash enabled"
  71. else
  72. echo "ℹ️ Boot splash already enabled"
  73. fi
  74. # Disable rainbow splash
  75. if ! grep -q "disable_splash=1" /boot/config.txt; then
  76. echo "disable_splash=1" >> /boot/config.txt
  77. echo "✅ Rainbow splash disabled"
  78. else
  79. echo "ℹ️ Rainbow splash already disabled"
  80. fi
  81. }
  82. # Main menu
  83. echo "Choose setup method:"
  84. echo "1) Systemd service (recommended for headless/kiosk mode)"
  85. echo "2) Desktop autostart (for desktop environments)"
  86. echo "3) Both systemd + desktop autostart"
  87. echo "4) Install system scripts only"
  88. echo "5) Add boot splash optimizations"
  89. echo "6) Complete kiosk setup (scripts + systemd + boot splash)"
  90. echo ""
  91. read -p "Enter your choice (1-6): " choice
  92. case $choice in
  93. 1)
  94. setup_systemd
  95. ;;
  96. 2)
  97. setup_desktop
  98. ;;
  99. 3)
  100. setup_systemd
  101. setup_desktop
  102. ;;
  103. 4)
  104. install_scripts
  105. ;;
  106. 5)
  107. setup_boot_splash
  108. ;;
  109. 6)
  110. install_scripts
  111. setup_systemd
  112. setup_boot_splash
  113. echo ""
  114. echo "🎯 Complete kiosk setup done!"
  115. echo " Reboot to see the full kiosk experience"
  116. ;;
  117. *)
  118. echo "❌ Invalid choice"
  119. exit 1
  120. ;;
  121. esac
  122. echo ""
  123. echo "✅ Setup complete!"