Problem :
In Ubuntu there is no apt repo for NoMachine.
Need to update frequently, otherwise it show nagging popup asking to update.

This generally can be applied to any other software like Discord.

Solution Plans :

  1. Deploy local repo.
  2. Script to check for nomachine new version.
  3. Download .deb file.
  4. Compile updated local repo list.
  5. Add auto run using cronjob

Details :

  1. How to deploy local repo.
  2. How to find link format for .deb new release, make sure link format static each released, other wise will break the script.
  3. How to compile repo after downloaded new releases.

Python scraper to fetch new nomachine release :

import requests
import os
from bs4 import BeautifulSoup

linuxPageUrl = "https://downloads.nomachine.com/linux/?id=1"
page = requests.get(linuxPageUrl)
soup = BeautifulSoup(page.content, "html.parser")
deb2_div = soup.find("div", id="DEB2")
link = deb2_div.find("div")["onclick"].split("'")[1]
print(link)

download_page = requests.get(link)
download_soup = BeautifulSoup(download_page.content, "html.parser")
download_button = download_soup.find("a", id="link_download")
download_link = download_button["href"]
print(download_link)

file_name = download_link.split("/")[-1]
print(file_name)

# Check if file exists
if not os.path.exists("nomachine_latest.txt"):
    with open("nomachine_latest.txt", "w") as f:
        f.write("")

with open("nomachine_latest.txt", "r") as f:
    latest_version = f.read().strip()

# Compare the latest version with the current version
if file_name != latest_version:
    # Download the new version
    response = requests.get(download_link)
    open(file_name, 'wb').write(response.content)
    print(f"Downloaded {file_name}")

    # Update the latest version file
    with open("nomachine_latest.txt", "w") as f:
        f.write(file_name)
        print(f"{file_name} added to nomachine_latest.txt")

create nomachineVenv.sh file to run python script with virtual env :

#!/usr/bin/env bash
source /home/ammar/nomachineupdater/nmupdt/bin/activate
python3 /home/ammar/nomachineupdater/nomachineUpdater.py

Add the crontab also on the second vm :

0 1 * * * /bin/bash /home/ammar/nomachineupdater/nomachineVenv.sh > /dev/null 2>&1

After .deb file geot update, next step to update local apt-repo :

Create new crontab -e :

0 2 * * * /bin/bash /var/www/apt-repo/nomachine-updater/nomachine_updater.sh > /dev/null 2>&1

#!/bin/bash
# nomachine_updater.sh

# check txt file
file="/home/ammar/nomachineupdater/nomachine_latest.txt"
if [ -f "$file" ]; then
  # get the nomachine deb file name from the txt file
  deb_file=$(cat "$file")
  deb_path="/home/ammar/nomachineupdater/$deb_file"
  
  # check if the deb file exists in /var/www/apt-repo/amd64
  dest_path="/var/www/apt-repo/amd64/$deb_file"
  if [ ! -f "$dest_path" ]; then
    # copy the deb file to /var/www/apt-repo/amd64
    cp "$deb_path" "$dest_path"
  fi
fi

Leave a Reply

Your email address will not be published. Required fields are marked *