#!/usr/bin/env bash

. /usr/share/dosis2/bin/shell-support-functions

enforce_root

OS="`getos`"
WHICH_REPO=""

echo_help() {
echo "prep-for-update [-h] [-s] [-l] -[-t]
-h | --help          show help
-s | --stable        set dosis-repo to stable (default) 
-l | --latest        set dosis-repo to latest
-t | --testing       set dosis-repo to testing
-x | --experimental  set dosis-repo to experimental
"
}


if [ "$1" = "" ]; then
	echo "No repo selected"
	echo_help
	exit 1
else
    case $1 in 
        -s | --stable )       shift
                            WHICH_REPO="-s"
                            ;;
        -l | --latest )     shift
                            WHICH_REPO="-l"
                            ;;
        -t | --testing )    shift
                            WHICH_REPO="-t"
                            ;;
        -x | --experimental )    shift
                            WHICH_REPO="-x"
                            ;;
        -h | --help )       echo_help
                            exit
                            ;;
        * )                 echo_help
                            exit 1
    esac
fi

/opt/dosis2/bin/change-dosis-repo "${WHICH_REPO}"

apt-mark unhold dosis dosis-base dosis-config dosis-os* openjdk-11*

apt-get clean
apt-get update
apt-get install dosis-updater

/opt/dosis2/bin/python3-venv /opt/dosis-updater/updater_cli.py -p -a -f -m $WHICH_REPO
