#!/bin/bash
set -e
set -o pipefail

usage() {
    cat << EOF
Usage: openqa-auto-update
Trigger automatic system upgrade and reboot if devel:openQA packages are stable

Options:
 -h, --help         display this help
EOF
    exit "$1"
}

opts=$(getopt -o h --long help -n "$0" -- "$@") || usage 1
eval set -- "$opts"
while true; do
  case "$1" in
    -h | --help ) usage 0; shift ;;
    -- ) shift; break ;;
    * ) break ;;
  esac
done

"$(dirname "${BASH_SOURCE[0]}")"/openqa-check-devel-repo
zypper -n dup --replacefiles --auto-agree-with-licenses --force-resolution --download-in-advance
# shellcheck disable=SC2015
needs-restarting --reboothint >/dev/null || (command -v rebootmgrctl >/dev/null && rebootmgrctl reboot ||:)
