#!/usr/bin/sh
set -eu

if [ "$(id -u)" != "0" ]; then
  echo "PhotonFile package updates must run as root." >&2
  exit 77
fi

manager="${1:-}"
case "$manager" in
  apt)
    if ! command -v apt-get >/dev/null 2>&1; then
      echo "apt-get was not found." >&2
      exit 69
    fi
    export DEBIAN_FRONTEND=noninteractive
    apt-get update
    apt-get install -y --only-upgrade photonfile-desktop
    ;;
  dnf)
    if ! command -v dnf >/dev/null 2>&1; then
      echo "dnf was not found." >&2
      exit 69
    fi
    dnf -y upgrade photonfile-desktop
    ;;
  *)
    echo "Usage: photonfile-linux-package-updater apt|dnf" >&2
    exit 64
    ;;
esac
