Refactor: Complete codebase reorganization and modernization
- Split server.js routes into modular files (server/routes/) - departures.js: Departure data endpoints - sites.js: Site search and nearby sites - config.js: Configuration endpoints - Reorganized file structure following Node.js best practices: - Moved sites-config.json to config/sites.json - Moved API_RESPONSE_DOCUMENTATION.md to docs/ - Moved raspberry-pi-setup.sh to scripts/ - Archived legacy files to archive/ directory - Updated all code references to new file locations - Added archive/ to .gitignore to exclude legacy files from repo - Updated README.md with new structure and organization - All functionality tested and working correctly Version: 1.2.0
This commit is contained in:
144
scripts/raspberry-pi-setup.sh
Normal file
144
scripts/raspberry-pi-setup.sh
Normal file
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
# Raspberry Pi Setup Script for SL Transport Departures Display
|
||||
# This script sets up the necessary services to run the display system on boot
|
||||
|
||||
echo "Setting up SL Transport Departures Display on Raspberry Pi..."
|
||||
|
||||
# Check if running as root
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Please run as root (use sudo)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current directory
|
||||
INSTALL_DIR=$(pwd)
|
||||
echo "Installing from: $INSTALL_DIR"
|
||||
|
||||
# Check if Node.js is installed
|
||||
if ! command -v node &> /dev/null; then
|
||||
echo "Node.js not found. Installing Node.js..."
|
||||
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
|
||||
apt-get install -y nodejs
|
||||
echo "Node.js installed successfully."
|
||||
else
|
||||
echo "Node.js is already installed."
|
||||
fi
|
||||
|
||||
# Create systemd service for the server
|
||||
echo "Creating systemd service for the server..."
|
||||
cat > /etc/systemd/system/sl-departures.service << EOL
|
||||
[Unit]
|
||||
Description=SL Departures Display Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/node ${INSTALL_DIR}/server.js
|
||||
WorkingDirectory=${INSTALL_DIR}
|
||||
Restart=always
|
||||
# Run as the pi user - change if needed
|
||||
User=pi
|
||||
Environment=NODE_ENV=production
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
# Enable and start the service
|
||||
echo "Enabling and starting the server service..."
|
||||
systemctl enable sl-departures.service
|
||||
systemctl start sl-departures.service
|
||||
|
||||
# Create autostart entry for Chromium in kiosk mode
|
||||
echo "Setting up autostart for Chromium in kiosk mode..."
|
||||
|
||||
# Determine the user to set up autostart for
|
||||
if [ -d "/home/pi" ]; then
|
||||
USER_HOME="/home/pi"
|
||||
USERNAME="pi"
|
||||
else
|
||||
# Try to find a non-root user
|
||||
USERNAME=$(getent passwd 1000 | cut -d: -f1)
|
||||
if [ -z "$USERNAME" ]; then
|
||||
echo "Could not determine user for autostart. Please set up autostart manually."
|
||||
exit 1
|
||||
fi
|
||||
USER_HOME="/home/$USERNAME"
|
||||
fi
|
||||
|
||||
echo "Setting up autostart for user: $USERNAME"
|
||||
|
||||
# Create autostart directory if it doesn't exist
|
||||
mkdir -p $USER_HOME/.config/autostart
|
||||
chown $USERNAME:$USERNAME $USER_HOME/.config/autostart
|
||||
|
||||
# Create autostart entry
|
||||
cat > $USER_HOME/.config/autostart/sl-departures-kiosk.desktop << EOL
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=SL Departures Kiosk
|
||||
Exec=chromium-browser --kiosk --disable-restore-session-state --noerrdialogs --disable-infobars --no-first-run http://localhost:3002
|
||||
Hidden=false
|
||||
X-GNOME-Autostart-enabled=true
|
||||
EOL
|
||||
|
||||
# Set correct ownership
|
||||
chown $USERNAME:$USERNAME $USER_HOME/.config/autostart/sl-departures-kiosk.desktop
|
||||
|
||||
# Disable screen blanking and screensaver
|
||||
echo "Disabling screen blanking and screensaver..."
|
||||
|
||||
# For X11
|
||||
if [ -d "/etc/X11/xorg.conf.d" ]; then
|
||||
cat > /etc/X11/xorg.conf.d/10-blanking.conf << EOL
|
||||
Section "ServerFlags"
|
||||
Option "BlankTime" "0"
|
||||
Option "StandbyTime" "0"
|
||||
Option "SuspendTime" "0"
|
||||
Option "OffTime" "0"
|
||||
EndSection
|
||||
EOL
|
||||
fi
|
||||
|
||||
# For console
|
||||
if [ -f "/etc/kbd/config" ]; then
|
||||
sed -i 's/^BLANK_TIME=.*/BLANK_TIME=0/' /etc/kbd/config
|
||||
sed -i 's/^POWERDOWN_TIME=.*/POWERDOWN_TIME=0/' /etc/kbd/config
|
||||
fi
|
||||
|
||||
# Add to rc.local for good measure
|
||||
if [ -f "/etc/rc.local" ]; then
|
||||
# Check if the commands are already in rc.local
|
||||
if ! grep -q "xset s off" /etc/rc.local; then
|
||||
# Insert before the exit 0 line
|
||||
sed -i '/exit 0/i \
|
||||
# Disable screen blanking\
|
||||
xset s off\
|
||||
xset -dpms\
|
||||
xset s noblank\
|
||||
' /etc/rc.local
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Creating a desktop shortcut for manual launch..."
|
||||
cat > $USER_HOME/Desktop/SL-Departures.desktop << EOL
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=SL Departures Display
|
||||
Comment=Launch SL Departures Display in Chromium
|
||||
Exec=chromium-browser --kiosk --disable-restore-session-state http://localhost:3002
|
||||
Icon=web-browser
|
||||
Terminal=false
|
||||
Categories=Network;WebBrowser;
|
||||
EOL
|
||||
|
||||
chown $USERNAME:$USERNAME $USER_HOME/Desktop/SL-Departures.desktop
|
||||
chmod +x $USER_HOME/Desktop/SL-Departures.desktop
|
||||
|
||||
echo "Setup complete!"
|
||||
echo "The system will start automatically on next boot."
|
||||
echo "To start manually:"
|
||||
echo "1. Start the server: sudo systemctl start sl-departures.service"
|
||||
echo "2. Launch the browser: Use the desktop shortcut or run 'chromium-browser --kiosk http://localhost:3002'"
|
||||
echo ""
|
||||
echo "To check server status: sudo systemctl status sl-departures.service"
|
||||
echo "To view server logs: sudo journalctl -u sl-departures.service"
|
||||
Reference in New Issue
Block a user