#!/bin/bash
# Put direct CLI jobs in the same budget as dashboard/service jobs.
set -euo pipefail
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [ "$#" -gt 1 ]; then echo 'Usage: sync_repos [7|8|9|10]' >&2; exit 2; fi
case "${1:-}" in
    ''|7|8|9|10) ;;
    -h|--help) exec /usr/bin/python3 "$(dirname "$(readlink -f "$0")")/sync_repos.py" --help ;;
    *) echo 'Usage: sync_repos [7|8|9|10]' >&2; exit 2 ;;
esac
helper="$(dirname "$(readlink -f "$0")")/sync_repos.py"
if [ "${MYKOS_REPO_SYNC_MANAGED:-}" != 1 ]; then
    exec systemd-run --wait --pipe --collect --unit=mykos-repo-sync-cli \
        --slice=mykosreposync.slice --property=Type=oneshot \
        --property=TimeoutStartSec=24h --property=Nice=15 \
        --property=IOSchedulingClass=best-effort --property=IOSchedulingPriority=7 \
        --property=CPUWeight=10 --property=IOWeight=10 --property=OOMScoreAdjust=500 \
        /usr/bin/python3 "$helper" "$@"
fi
exec /usr/bin/python3 "$helper" "$@"
