Schedule artifact update: auto deploy of the latest recommended build on Linux

I haven’t found a way via Tx or on the forum; if anyone knows better, please comment. I’m sharing what I’m automating for deployment because of the policy at https://forum.cfx.re/t/important-policy-update-for-server-owners/2726022

Script for add @monthly on server crontab :

#!/usr/bin/env bash
#set -euo pipefail
cd $HOME/FXServer

BASE="https://runtime.fivem.net/artifacts/fivem/build_proot_linux/master/"
FILE="fx.tar.xz"
TMP_HTML="$(mktemp)"
trap 'rm -f "$TMP_HTML"' EXIT

echo "Searching for latest recommended build..."

URL=$(curl -s 'https://changelogs-live.fivem.net/api/changelog/versions/linux/server' | grep -oP '"recommended_download"\s*:\s*"\K[^"]+')
# Validate that $URL is a non-empty HTTPS URL; if not, run fallback.
if [[ -z "$URL" || ! $URL =~ ^https:// ]]; then
  echo "API Fail. Attemping rescue with a web fallback..."
  curl -sS "$BASE" > "$TMP_HTML"
  URL=$(awk -F'"' '/LATEST RECOMMENDED/{print p} {p=$2}' $TMP_HTML)
  URL="${BASE}${URL}"
fi

echo "Downloading: $URL"
wget -q --show-progress -O "$FILE" "$URL"

if [ -f "$FILE" ]; then
  echo "Checking if it's an XZ file using the 'file' command"
  FILE_TYPE=$(file "$FILE")

  if [[ "$FILE_TYPE" == *"XZ compressed data"* ]]; then
    echo "$FILE is OK a valid XZ."

    echo "Stoping FiveM service..."
    sudo /bin/systemctl stop fivem.service

    echo "Renaming existing alpine dir to alpine_old (force)..."
    if [ -d alpine ]; then
      # remove previous alpine_old if exists, then move alpine -> alpine_old
      rm -rf alpine_old
      mv -T alpine alpine_old
    fi

    echo "Extracing the tarball (creates alpine/ or appropriate files)..."
    tar xf "$FILE"
  else
    echo "Error: File $FILE is not an XZ compressed data archive."
    exit 1
  fi
else
  echo "Error: File $FILE not found (download may have failed)."
  exit 1
fi

echo "Starting FiveM service..."
sudo /bin/systemctl start fivem.service

( API obtained from version of Auto update - Docs )

Pre-requisites

This script is intended to run with FiveM as a service, there are some people that run FiveM inside a screen (this is not the way to do so). So in order to have this script we need first to have FiveM as a service.

To do that first we need to create the service.

$ sudo nano /etc/systemd/system/fivem.service

We will write the following content in the file.

[Unit]
Description=FiveM Service
After=network.target

[Service]
ExecStart=/path/to/run.sh
User=fivem # your user
Group=fivem # your group <- usually is you username.

[Install]
WantedBy=multi-user.target

Now we have configured our service! Now our FiveM will run as a service!

So let’s refresh the systemd to allow our service to show.

$ sudo systemctl daemon-reload

(FiveM service quick guide from GitHub - Jonirulah/FiveM-Artifacts-Updater: FiveM Artifacts Updater for Linux · GitHub )

Repository: GitHub - eth3real-code/auto-updater-fivem-artifacts-linux: FiveM Artifacts Updater for Linux · GitHub