#!/bin/bash
set -u

COMMON=/usr/lib/onix/onix-pkg-common
if [[ ! -r "$COMMON" ]]; then
    echo "onix: package helper is missing: $COMMON" >&2
    exit 1
fi
# shellcheck disable=SC1091
. "$COMMON"

echo "OnixOS system updater"
echo "Refreshing mirrors and applying a complete system upgrade..."
refresh_mirrors || exit 1
full_upgrade
status=$?

if (( status == 0 )); then
    echo "OnixOS update completed."
else
    echo "OnixOS update failed; resolve the pacman error before retrying." >&2
fi
exit "$status"
