147 lines
4.3 KiB
Bash
Executable File
147 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# Oculog Client Update Script
|
|
# Updates the Oculog client with success/failure reporting for each step
|
|
#
|
|
# Usage:
|
|
# sudo bash update-client.sh [OCULOG_SERVER_URL]
|
|
# Example: sudo bash update-client.sh http://YOUR_SERVER_IP:3001
|
|
#
|
|
# Or set environment variable:
|
|
# export OCULOG_SERVER=http://YOUR_SERVER_IP:3001
|
|
# sudo bash update-client.sh
|
|
|
|
set -e # Exit on error (we'll handle errors manually)
|
|
|
|
# Configuration - use argument, environment variable, or default
|
|
if [ -n "$1" ]; then
|
|
OCULOG_SERVER="$1"
|
|
elif [ -n "$OCULOG_SERVER" ]; then
|
|
OCULOG_SERVER="$OCULOG_SERVER"
|
|
else
|
|
echo "Error: Oculog server URL not specified"
|
|
echo ""
|
|
echo "Usage: sudo bash update-client.sh [OCULOG_SERVER_URL]"
|
|
echo "Example: sudo bash update-client.sh http://YOUR_SERVER_IP:3001"
|
|
echo ""
|
|
echo "Or set environment variable:"
|
|
echo " export OCULOG_SERVER=http://YOUR_SERVER_IP:3001"
|
|
echo " sudo bash update-client.sh"
|
|
exit 1
|
|
fi
|
|
|
|
echo "=== Oculog Client Update Script ==="
|
|
echo "Server: $OCULOG_SERVER"
|
|
echo ""
|
|
|
|
# Function to check command success
|
|
check_success() {
|
|
if [ $? -eq 0 ]; then
|
|
echo "✓ Success"
|
|
return 0
|
|
else
|
|
echo "✗ Failed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# 1. Stop the Oculog client service
|
|
echo -n "Step 1: Stopping oculog-client service... "
|
|
if sudo systemctl stop oculog-client.service 2>/dev/null; then
|
|
echo "✓ Success"
|
|
else
|
|
echo "✗ Failed (service may not be running)"
|
|
fi
|
|
|
|
# 2. Download the updated client script
|
|
echo -n "Step 2: Downloading updated client script... "
|
|
if sudo curl -s "$OCULOG_SERVER/api/client-script" | sudo tee /opt/oculog/client.py.new > /dev/null 2>&1; then
|
|
if [ -f /opt/oculog/client.py.new ] && [ -s /opt/oculog/client.py.new ]; then
|
|
echo "✓ Success"
|
|
else
|
|
echo "✗ Failed - File not created or empty"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "✗ Failed - Download error"
|
|
exit 1
|
|
fi
|
|
|
|
# 3. Backup the current client script
|
|
echo -n "Step 3: Backing up current client script... "
|
|
if [ -f /opt/oculog/client.py ]; then
|
|
if sudo cp /opt/oculog/client.py /opt/oculog/client.py.backup 2>/dev/null; then
|
|
echo "✓ Success"
|
|
else
|
|
echo "✗ Failed"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "⚠ Skipped - No existing client.py found"
|
|
fi
|
|
|
|
# 4. Replace the client script
|
|
echo -n "Step 4: Replacing client script... "
|
|
if sudo mv /opt/oculog/client.py.new /opt/oculog/client.py 2>/dev/null; then
|
|
echo "✓ Success"
|
|
else
|
|
echo "✗ Failed"
|
|
exit 1
|
|
fi
|
|
|
|
# 5. Verify version was injected
|
|
echo -n "Step 5: Verifying version injection... "
|
|
if sudo grep -q 'CLIENT_VERSION_BUILD_TIMESTAMP = "[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}"' /opt/oculog/client.py 2>/dev/null; then
|
|
VERSION=$(sudo grep 'CLIENT_VERSION_BUILD_TIMESTAMP = "' /opt/oculog/client.py | head -1 | sed 's/.*"\(.*\)".*/\1/')
|
|
echo "✓ Success (Version: $VERSION)"
|
|
else
|
|
echo "⚠ Warning - Version may not have been injected (will use file modification time)"
|
|
fi
|
|
|
|
# 6. Ensure the script is executable
|
|
echo -n "Step 6: Setting executable permissions... "
|
|
if sudo chmod +x /opt/oculog/client.py 2>/dev/null; then
|
|
echo "✓ Success"
|
|
else
|
|
echo "✗ Failed"
|
|
exit 1
|
|
fi
|
|
|
|
# 7. Restart the service
|
|
echo -n "Step 7: Starting oculog-client service... "
|
|
if sudo systemctl start oculog-client.service 2>/dev/null; then
|
|
echo "✓ Success"
|
|
else
|
|
echo "✗ Failed"
|
|
exit 1
|
|
fi
|
|
|
|
# 8. Wait a moment for service to start
|
|
sleep 2
|
|
|
|
# 9. Verify the service is running
|
|
echo -n "Step 8: Verifying service status... "
|
|
if sudo systemctl is-active --quiet oculog-client.service 2>/dev/null; then
|
|
echo "✓ Success - Service is running"
|
|
else
|
|
echo "✗ Failed - Service is not running"
|
|
echo ""
|
|
echo "Checking service status:"
|
|
sudo systemctl status oculog-client.service --no-pager -l || true
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== Update Complete ==="
|
|
echo ""
|
|
echo "Note: The client version in the web UI will update after the client sends"
|
|
echo " its next metrics update (usually within 30 seconds)."
|
|
echo ""
|
|
echo "To view logs, run:"
|
|
echo " sudo journalctl -u oculog-client.service -f"
|
|
echo ""
|
|
echo "To check service status, run:"
|
|
echo " sudo systemctl status oculog-client.service"
|
|
echo ""
|
|
echo "To verify the client version immediately, check logs for:"
|
|
echo " sudo journalctl -u oculog-client.service -n 50 | grep -i version"
|