install.sh 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #!/bin/bash
  2. # Dune Weaver Touch - One-Command Installer
  3. # This script sets up everything needed to run Dune Weaver Touch on boot
  4. #
  5. # Uses linuxfb backend for Qt rendering (software-rendered via Linux framebuffer)
  6. # This provides better compatibility with Raspberry Pi without complex GPU/KMS setup
  7. set -e
  8. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  9. ACTUAL_USER="${SUDO_USER:-$USER}"
  10. USER_HOME=$(eval echo ~$ACTUAL_USER)
  11. echo "🎯 Dune Weaver Touch - Complete Installation"
  12. echo "============================================="
  13. echo "App directory: $SCRIPT_DIR"
  14. echo "User: $ACTUAL_USER"
  15. echo ""
  16. # Check if running as root
  17. if [ "$EUID" -ne 0 ]; then
  18. echo "❌ This installer must be run with sudo privileges"
  19. echo ""
  20. echo "Usage: sudo ./install.sh"
  21. echo ""
  22. exit 1
  23. fi
  24. echo "🔧 Installing system components..."
  25. echo ""
  26. # Function to install system scripts
  27. install_scripts() {
  28. echo "📄 Installing system scripts..."
  29. local scripts=("screen-on" "screen-off" "touch-monitor")
  30. for script in "${scripts[@]}"; do
  31. local source_path="$SCRIPT_DIR/scripts/$script"
  32. local target_path="/usr/local/bin/$script"
  33. if [ -f "$source_path" ]; then
  34. cp "$source_path" "$target_path"
  35. chmod 755 "$target_path"
  36. chown root:root "$target_path"
  37. echo " ✅ $script → $target_path"
  38. else
  39. echo " ⚠️ $script not found at $source_path"
  40. fi
  41. done
  42. echo " 📄 System scripts installed"
  43. }
  44. # Function to setup systemd service
  45. setup_systemd() {
  46. echo "🚀 Setting up systemd service..."
  47. # Make startup wrapper executable
  48. chmod +x "$SCRIPT_DIR/start-with-fb-check.sh"
  49. # Update paths in the service file
  50. sed "s|/home/pi/dune-weaver-touch|$SCRIPT_DIR|g" "$SCRIPT_DIR/dune-weaver-touch.service" > /tmp/dune-weaver-touch.service
  51. sed -i "s|User=pi|User=$ACTUAL_USER|g" /tmp/dune-weaver-touch.service
  52. sed -i "s|Group=pi|Group=$ACTUAL_USER|g" /tmp/dune-weaver-touch.service
  53. # Copy service file
  54. cp /tmp/dune-weaver-touch.service /etc/systemd/system/
  55. # Enable service
  56. systemctl daemon-reload
  57. systemctl enable dune-weaver-touch.service
  58. echo " 🚀 Systemd service installed and enabled"
  59. }
  60. # Function to setup screen rotation
  61. setup_screen_rotation() {
  62. echo "🔄 Setting up 180° screen rotation..."
  63. # Determine boot config path (supports both /boot/config.txt and /boot/firmware/config.txt)
  64. BOOT_CONFIG=""
  65. if [ -f /boot/firmware/config.txt ]; then
  66. BOOT_CONFIG="/boot/firmware/config.txt"
  67. elif [ -f /boot/config.txt ]; then
  68. BOOT_CONFIG="/boot/config.txt"
  69. fi
  70. if [ -n "$BOOT_CONFIG" ]; then
  71. # Ensure FKMS is enabled (required for Freenove display)
  72. if ! grep -q "^dtoverlay=vc4-fkms-v3d" "$BOOT_CONFIG"; then
  73. # Check if KMS (full) is present and replace it
  74. if grep -q "^dtoverlay=vc4-kms-v3d" "$BOOT_CONFIG"; then
  75. sed -i 's/^dtoverlay=vc4-kms-v3d/dtoverlay=vc4-fkms-v3d/' "$BOOT_CONFIG"
  76. echo " ✅ Changed vc4-kms-v3d to vc4-fkms-v3d (required for display)"
  77. else
  78. echo "dtoverlay=vc4-fkms-v3d" >> "$BOOT_CONFIG"
  79. echo " ✅ Added vc4-fkms-v3d overlay"
  80. fi
  81. else
  82. echo " ℹ️ FKMS already enabled"
  83. fi
  84. # Note: display_rotate and lcd_rotate don't work with linuxfb
  85. # Rotation is handled by Qt's rotation parameter in startup scripts
  86. echo " ℹ️ Display rotation handled by Qt (linuxfb:rotation=180)"
  87. echo " 🔄 Screen rotation (180°) will be applied by application startup"
  88. else
  89. echo " ⚠️ Boot config not found - rotation not configured"
  90. fi
  91. }
  92. # Function to setup kiosk optimizations
  93. setup_kiosk_optimizations() {
  94. echo "🖥️ Setting up kiosk optimizations..."
  95. # Disable boot messages for cleaner boot
  96. if ! grep -q "quiet splash" /boot/cmdline.txt 2>/dev/null; then
  97. if [ -f /boot/cmdline.txt ]; then
  98. cp /boot/cmdline.txt /boot/cmdline.txt.backup
  99. sed -i 's/$/ quiet splash/' /boot/cmdline.txt
  100. echo " ✅ Boot splash enabled"
  101. fi
  102. else
  103. echo " ℹ️ Boot splash already enabled"
  104. fi
  105. # Disable rainbow splash
  106. if ! grep -q "disable_splash=1" /boot/config.txt 2>/dev/null; then
  107. if [ -f /boot/config.txt ]; then
  108. echo "disable_splash=1" >> /boot/config.txt
  109. echo " ✅ Rainbow splash disabled"
  110. fi
  111. else
  112. echo " ℹ️ Rainbow splash already disabled"
  113. fi
  114. # Note about auto-login - let user configure manually
  115. echo " ℹ️ Auto-login configuration skipped (manual setup recommended)"
  116. echo " 🖥️ Kiosk optimizations applied"
  117. }
  118. # Function to setup Python virtual environment and install dependencies
  119. setup_python_environment() {
  120. echo "🐍 Setting up Python virtual environment..."
  121. # Create virtual environment if it doesn't exist
  122. if [ ! -d "$SCRIPT_DIR/venv" ]; then
  123. echo " 📦 Creating virtual environment..."
  124. python3 -m venv "$SCRIPT_DIR/venv" || {
  125. echo " ⚠️ Could not create virtual environment. Installing python3-venv..."
  126. apt update && apt install -y python3-venv python3-full
  127. python3 -m venv "$SCRIPT_DIR/venv"
  128. }
  129. else
  130. echo " ℹ️ Virtual environment already exists"
  131. fi
  132. # Activate virtual environment and install dependencies
  133. echo " 📦 Installing Python dependencies in virtual environment..."
  134. "$SCRIPT_DIR/venv/bin/python" -m pip install --upgrade pip
  135. # Install from requirements.txt if it exists, otherwise install manually
  136. if [ -f "$SCRIPT_DIR/requirements.txt" ]; then
  137. "$SCRIPT_DIR/venv/bin/pip" install -r "$SCRIPT_DIR/requirements.txt"
  138. else
  139. "$SCRIPT_DIR/venv/bin/pip" install PySide6 requests
  140. fi
  141. # Change ownership to the actual user (not root)
  142. chown -R "$ACTUAL_USER:$ACTUAL_USER" "$SCRIPT_DIR/venv"
  143. echo " 🐍 Python virtual environment ready"
  144. }
  145. # Function to setup patterns directory permissions
  146. setup_patterns_permissions() {
  147. echo "📁 Setting up patterns directory permissions..."
  148. # Determine patterns directory location (parent of touch app)
  149. PATTERNS_DIR="$(dirname "$SCRIPT_DIR")/patterns"
  150. if [ -d "$PATTERNS_DIR" ]; then
  151. echo " 📂 Found patterns directory: $PATTERNS_DIR"
  152. # Ensure cached_images directory exists
  153. CACHE_DIR="$PATTERNS_DIR/cached_images"
  154. if [ ! -d "$CACHE_DIR" ]; then
  155. echo " 📁 Creating cached_images directory..."
  156. mkdir -p "$CACHE_DIR"
  157. fi
  158. # Set ownership to the user who will run the service
  159. echo " 🔑 Setting ownership to $ACTUAL_USER..."
  160. chown -R "$ACTUAL_USER:$ACTUAL_USER" "$CACHE_DIR"
  161. # Set permissions: user can read/write, group can read, others can read
  162. echo " 🔒 Setting permissions (755 for dirs, 644 for files)..."
  163. find "$CACHE_DIR" -type d -exec chmod 755 {} \;
  164. find "$CACHE_DIR" -type f -exec chmod 644 {} \;
  165. echo " ✅ Patterns cache directory permissions configured"
  166. else
  167. echo " ⚠️ Patterns directory not found at $PATTERNS_DIR"
  168. echo " ℹ️ If patterns exist elsewhere, manually run:"
  169. echo " sudo chown -R $ACTUAL_USER:$ACTUAL_USER /path/to/patterns/cached_images"
  170. fi
  171. }
  172. # Main installation process
  173. echo "Starting complete installation..."
  174. echo ""
  175. # Install everything
  176. setup_python_environment
  177. setup_patterns_permissions
  178. install_scripts
  179. setup_systemd
  180. setup_screen_rotation
  181. setup_kiosk_optimizations
  182. echo ""
  183. echo "🎉 Installation Complete!"
  184. echo "========================"
  185. echo ""
  186. echo "✅ Python virtual environment created at: $SCRIPT_DIR/venv"
  187. echo "✅ Patterns cache directory permissions configured"
  188. echo "✅ System scripts installed in /usr/local/bin/"
  189. echo "✅ Systemd service configured for auto-start"
  190. echo "✅ Screen rotation (180°) configured"
  191. echo "✅ Kiosk optimizations applied"
  192. echo ""
  193. echo "🔧 Service Management:"
  194. echo " Start now: sudo systemctl start dune-weaver-touch"
  195. echo " Stop: sudo systemctl stop dune-weaver-touch"
  196. echo " Status: sudo systemctl status dune-weaver-touch"
  197. echo " Logs: sudo journalctl -u dune-weaver-touch -f"
  198. echo ""
  199. echo "🚀 Next Steps:"
  200. echo " 1. Configure auto-login (recommended for kiosk mode):"
  201. echo " sudo ./setup-autologin.sh (automated setup)"
  202. echo " OR manually: sudo raspi-config → System Options → Boot/Auto Login → Desktop Autologin"
  203. echo " 2. Reboot your system to see the full kiosk experience"
  204. echo " 3. The app will start automatically on boot via systemd service"
  205. echo " 4. Check the logs if you encounter any issues"
  206. echo ""
  207. echo "💡 To start the service now without rebooting:"
  208. echo " sudo systemctl start dune-weaver-touch"
  209. echo ""
  210. echo "🛠️ For development/testing (run manually):"
  211. echo " cd $SCRIPT_DIR"
  212. echo " ./run.sh"
  213. echo ""
  214. echo "⚙️ To change boot/login settings later:"
  215. echo " sudo ./configure-boot.sh"
  216. echo ""
  217. # Ask if user wants to start now
  218. read -p "🤔 Would you like to start the service now? (y/N): " -n 1 -r
  219. echo
  220. if [[ $REPLY =~ ^[Yy]$ ]]; then
  221. echo "🚀 Starting Dune Weaver Touch service..."
  222. systemctl start dune-weaver-touch
  223. sleep 2
  224. systemctl status dune-weaver-touch --no-pager -l
  225. echo ""
  226. echo "✅ Service started! Check the status above."
  227. fi
  228. echo ""
  229. echo "🎯 Installation completed successfully!"