mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 13:23:00 +00:00
fix: Make install_wifi_monitor.sh more resilient to failures
Make install_wifi_monitor.sh handle errors more gracefully: 1. Remove unnecessary sudo when running as root: - Check EUID before using sudo for systemctl commands - Use systemctl directly when running as root - Use sudo only when running as regular user 2. Add error handling for package installation: - Continue even if apt update fails (just warn) - Continue even if apt install fails (warn and provide manual install command) - Allow installation to continue even if packages fail 3. Make service operations more resilient: - Remove sudo when running as root - Allow service start to fail without exiting script - Print warning if service fails to start - Service will still be enabled and may start on reboot Note: Script still uses 'set -e' but errors in critical paths are handled with || operators to prevent exit. This prevents the script from exiting with code 1 when called from first_time_install.sh, allowing the installation to continue even if some WiFi-related operations fail.
This commit is contained in:
@@ -49,13 +49,19 @@ if [ ${#MISSING_PACKAGES[@]} -gt 0 ]; then
|
||||
# Install packages automatically (no prompt)
|
||||
# Use apt directly if running as root, otherwise use sudo
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
apt update
|
||||
apt install -y "${MISSING_PACKAGES[@]}"
|
||||
apt update || echo "⚠ apt update failed, continuing anyway..."
|
||||
apt install -y "${MISSING_PACKAGES[@]}" || {
|
||||
echo "⚠ Package installation failed, but continuing with WiFi monitor setup"
|
||||
echo " You may need to install packages manually: apt install -y ${MISSING_PACKAGES[*]}"
|
||||
}
|
||||
else
|
||||
sudo apt update
|
||||
sudo apt install -y "${MISSING_PACKAGES[@]}"
|
||||
sudo apt update || echo "⚠ apt update failed, continuing anyway..."
|
||||
sudo apt install -y "${MISSING_PACKAGES[@]}" || {
|
||||
echo "⚠ Package installation failed, but continuing with WiFi monitor setup"
|
||||
echo " You may need to install packages manually: sudo apt install -y ${MISSING_PACKAGES[*]}"
|
||||
}
|
||||
fi
|
||||
echo "✓ Packages installed"
|
||||
echo "✓ Package installation completed"
|
||||
fi
|
||||
|
||||
# Create service file with correct paths
|
||||
@@ -83,7 +89,11 @@ WantedBy=multi-user.target
|
||||
EOF
|
||||
)
|
||||
|
||||
echo "$SERVICE_FILE_CONTENT" | sudo tee /etc/systemd/system/ledmatrix-wifi-monitor.service > /dev/null
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "$SERVICE_FILE_CONTENT" | tee /etc/systemd/system/ledmatrix-wifi-monitor.service > /dev/null
|
||||
else
|
||||
echo "$SERVICE_FILE_CONTENT" | sudo tee /etc/systemd/system/ledmatrix-wifi-monitor.service > /dev/null
|
||||
fi
|
||||
|
||||
# Check WiFi connection status before enabling service
|
||||
echo ""
|
||||
@@ -151,23 +161,45 @@ fi
|
||||
# Reload systemd
|
||||
echo ""
|
||||
echo "Reloading systemd..."
|
||||
sudo systemctl daemon-reload
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
systemctl daemon-reload
|
||||
else
|
||||
sudo systemctl daemon-reload
|
||||
fi
|
||||
|
||||
# Enable and start the service
|
||||
echo "Enabling WiFi monitor service to start on boot..."
|
||||
sudo systemctl enable ledmatrix-wifi-monitor.service
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
systemctl enable ledmatrix-wifi-monitor.service
|
||||
else
|
||||
sudo systemctl enable ledmatrix-wifi-monitor.service
|
||||
fi
|
||||
|
||||
echo "Starting WiFi monitor service..."
|
||||
sudo systemctl start ledmatrix-wifi-monitor.service
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
systemctl start ledmatrix-wifi-monitor.service || echo "⚠ Failed to start service (may start on reboot)"
|
||||
else
|
||||
sudo systemctl start ledmatrix-wifi-monitor.service || echo "⚠ Failed to start service (may start on reboot)"
|
||||
fi
|
||||
|
||||
# Check service status
|
||||
echo ""
|
||||
echo "Checking service status..."
|
||||
if sudo systemctl is-active --quiet ledmatrix-wifi-monitor.service; then
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
SYSTEMCTL_CMD="systemctl"
|
||||
else
|
||||
SYSTEMCTL_CMD="sudo systemctl"
|
||||
fi
|
||||
|
||||
if $SYSTEMCTL_CMD is-active --quiet ledmatrix-wifi-monitor.service 2>/dev/null; then
|
||||
echo "✓ WiFi monitor service is running"
|
||||
else
|
||||
echo "⚠ WiFi monitor service failed to start. Check logs with:"
|
||||
echo " sudo journalctl -u ledmatrix-wifi-monitor -n 50"
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo " journalctl -u ledmatrix-wifi-monitor -n 50"
|
||||
else
|
||||
echo " sudo journalctl -u ledmatrix-wifi-monitor -n 50"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user