PKG update/upgrade dosen't work...How do I update using ports?

Couldn’t quickly find it so posting here, you’re as some interesting prompts, mine is a bit more simple and doesn’t have params, which I wanted to add but never need it so this just runs in a cron task:

#!/bin/sh
# Uses PMS API to check for updates
# Downloads Updates if available
# Installs to jail using ports system

PLEX_PORT_PATH="/usr/ports/multimedia/plexmediaserver"
PLEX_PKG_NAME="plexmediaserver"
SERVER_URL="https://YOUR-LOCAL-IP.some_hash.plex.direct:32400"
JAIL_NAME="ioc-plex"

release_info=""
download_url=""

split_version_sufix()
{
  version_prefix=$(echo $1 | cut -d "-" -f1)
  version_sufix=$(echo $1 | cut -d "-" -f2)
}


check_updates()
{
  ##fetch -qo - SERVER_URL/updater/status | egrep -o '([0-9]+(\.|-)){4}([a-z|0-9]+)'
  ## I wanted no deps but fetch doens't support post/put, and httpie'jq = awesomeness

  echo -e "Checking for updates...\n"
  http PUT $SERVER_URL/updater/check > /dev/null
  release_info=$(http --json -b $SERVER_URL/updater/status | jq '.MediaContainer.Release[]')

  if [ ! -z "$release_info" ]; then

    state=$(echo $release_info| jq -r '.state')
    new_version=$(echo $release_info| jq -r '.version')
    whats_new=$(echo $release_info| jq -r '{added,fixed} |to_entries[] | "  \(.key):   \(.value)"')
    download_url=$(echo $release_info| jq -r '.downloadURL')

    if [ "$state" == "notify" ]; then
      echo -e "New Update Available\nRelease info:\n"
      echo -e "Version: $new_version"
      echo -e "What's New: \n$whats_new\n\n"
    fi
  else
    echo "No updates available what the time"
    exit 1
  fi
}

check_jail_pkg_version()
{
  pkg -j $JAIL_NAME query %v plexmediaserver
}

download_new_version()
{
  cd /usr/ports/distfiles
  http -bd $download_url # TODO: add continue mode; need filename
  cd -
}

update_port_makefile()
{
  # expects version_prefix and sufix as arg1 and arg2
  portVersion=$(make -C $PLEX_PORT_PATH -V PORTVERSION)
  portVersionSufix=$(make -C $PLEX_PORT_PATH -V DISTVERSIONSUFFIX)

  echo "PORTVERSION: $portVersion || DISTVERSIONSUFFIX: $portVersionSufix"

  today=$(date +%F)
  sed -i "_$today.bk" "s/$portVersion/$1/" "$PLEX_PORT_PATH/Makefile"
  sed -i "_$today.bk" "s/$portVersionSufix/$2/" "$PLEX_PORT_PATH/Makefile"

  echo -e "\nMakefile Updated:"
  echo "PORTVERSION: $(make -C $PLEX_PORT_PATH -V PORTVERSION) || DISTVERSIONSUFFIX: $(make -C $PLEX_PORT_PATH -V DISTVERSIONSUFFIX)"
}

make_package()
{
  make -sC $PLEX_PORT_PATH clean
  make -sC $PLEX_PORT_PATH makesum
  make -sC $PLEX_PORT_PATH package
}

upgrade_pkg()
{
  # expects version prefix as arg
  PLEX_JAIL_PATH="$(jls -j $JAIL_NAME path)"

  jexec $JAIL_NAME service plexmediaserver stop
  pkg -j $JAIL_NAME remove -y $PLEX_PKG_NAME
  mv "$PLEX_PORT_PATH/work/pkg/$PLEX_PKG_NAME-$1.txz" "$PLEX_JAIL_PATH/tmp/$PLEX_PKG_NAME-$1.txz"
  pkg -j $JAIL_NAME install -y /tmp/$PLEX_PKG_NAME-$1.txz
  jexec $JAIL_NAME service plexmediaserver start
}


check_updates
pkg_version=check_jail_pkg_version


### Main ###
# TODO: add optional params
if [ ! -z "$pkg_version" ]; then
  split_version_sufix $new_version
  if [ "$version_prefix" == "$pkg_version" ]; then
    echo "This version ($verion_prefix) is already installed in the jail ($JAIL_NAME)!!!"
  else
    download_new_version
    echo -e "\n\nUpdate Port Makefile"
    update_port_makefile $version_prefix $version_sufix
    echo -e "\nTime to make the port/package ..."
    make_package
    echo -e "\nUpgrade the port inside the jail and restart PMS "
    upgrade_pkg $version_prefix
  fi
fi

Just need the server url and port path updated to match the user’s sytem.

The host needs httpie and jq installed (pkg install py37-httpie pkg install jq should do it)

This also respects the pref the user sets for “Channel” in the server, so it will get either public or beta updates regardless of how the port/path is named (that never made any difference anyway and its adds only confusion)

Maybe you can merge the 2 and use the PMS updater API part? In any case feel free to use as you please.

One of the reasons I took so long to post it here, is that honestly I was hoping we would have our own ready to install pkgs, which is still something we do want to have, but sadly the day is to small for all the things :slight_smile: