|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Function to check internet connection |
| 4 | +check_internet() { |
| 5 | + if ! ping -c 1 -W 1 google.com &> /dev/null; then |
| 6 | + echo "No internet connection. Aborting." |
| 7 | + exit 1 |
| 8 | + fi |
| 9 | +} |
| 10 | + |
| 11 | +# Check internet before proceeding |
| 12 | +check_internet |
| 13 | + |
| 14 | +# Path to local release-info.json |
| 15 | +LOCAL_FILE="/usr/share/HackerOS/Config-Files/release-info.json" |
| 16 | + |
| 17 | +# Download remote version file to /tmp |
| 18 | +REMOTE_URL="https://raw.githubusercontent.com/HackerOS-Linux-System/HackerOS-Updates/main/version.hacker" |
| 19 | +curl -s -o /tmp/version.hacker "$REMOTE_URL" || { echo "Failed to download remote version file."; exit 1; } |
| 20 | + |
| 21 | +# Extract local version from JSON (assuming jq is installed; if not, use sed/awk alternative) |
| 22 | +if command -v jq &> /dev/null; then |
| 23 | + LOCAL_VERSION=$(jq -r '.version' "$LOCAL_FILE" | awk '{print $1}') |
| 24 | +else |
| 25 | + LOCAL_VERSION=$(grep '"version"' "$LOCAL_FILE" | sed 's/.*: "\(.*\) ->.*/\1/') |
| 26 | +fi |
| 27 | + |
| 28 | +# Extract remote version |
| 29 | +REMOTE_VERSION=$(sed 's/^\[\(.*\)\]$/\1/' /tmp/version.hacker) |
| 30 | + |
| 31 | +# Compare versions numerically (using sort -V for version comparison) |
| 32 | +if [[ $(echo -e "$LOCAL_VERSION\n$REMOTE_VERSION" | sort -V | tail -n1) != "$LOCAL_VERSION" ]]; then |
| 33 | + # Clone the repo to /tmp |
| 34 | + git clone https://github.com/HackerOS-Linux-System/HackerOS-Updates.git /tmp/HackerOS-Updates || { echo "Failed to clone repository."; exit 1; } |
| 35 | + |
| 36 | + # Give execute permissions to unpack.sh |
| 37 | + sudo chmod a+x /tmp/HackerOS-Updates/unpack.sh |
| 38 | + |
| 39 | + # Run the script |
| 40 | + /tmp/HackerOS-Updates/unpack.sh |
| 41 | +else |
| 42 | + # No newer version, do nothing |
| 43 | + : |
| 44 | +fi |
| 45 | + |
| 46 | +# Clean up temporary file |
| 47 | +rm -f /tmp/version.hacker |
0 commit comments