Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created August 20, 2024 15:47
Show Gist options
  • Save blackknight36/5204ab48616a451764188b4a9de5b37d to your computer and use it in GitHub Desktop.
Save blackknight36/5204ab48616a451764188b4a9de5b37d to your computer and use it in GitHub Desktop.
#!/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
# URL to monitor
URL="https://downloads.nomachine.com/download/?id=2"
# File to store previous version
DATA_DIR="${HOME}/nomachine_watch"
VERSION_FILE="${DATA_DIR}/previous_version.txt"
touch $VERSION_FILE
# Directory to download files
DOWNLOAD_DIR="${DATA_DIR}"
# Extract the current version using lynx
CURRENT_VERSION=$(lynx -dump "$URL" | grep -A2 "Version:" | tail -n 1 | tr -d ' ')
# Load the previous version from file
if [ -f "$VERSION_FILE" ]; then
PREVIOUS_VERSION=$(cat "$VERSION_FILE")
else
PREVIOUS_VERSION=""
fi
# Compare versions
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "New version detected: $CURRENT_VERSION"
# Find the download link (you'll need to adjust this based on the page structure)
DOWNLOAD_LINK=$(lynx -dump -listonly "$URL" | grep -m 1 ".deb" | awk '{print $2}')
#echo $DOWNLOAD_LINK
# Download the file
cd $DOWNLOAD_DIR
curl -O $DOWNLOAD_LINK >/dev/null
FILE_NAME=$(basename "$DOWNLOAD_LINK")
FILE_PATH="$DOWNLOAD_DIR/$FILE_NAME"
echo "New NoMachine version detected: $CURRENT_VERSION\n\nDownload URL: ${DOWNLOAD_LINK}"
echo "Uploading to cpe-generic repo"
jf rt upload ${FILE_NAME} cpe-generic/nomachine/
# Send a persistent desktop notification
osascript <<EOF
display dialog "New NoMachine version detected: $CURRENT_VERSION\n\nDownload URL: ${DOWNLOAD_LINK}" buttons {"OK"} default button "OK" with title "Version Update"
EOF
# Update the version file
echo "$CURRENT_VERSION" > "$VERSION_FILE"
else
echo "No new version detected."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment