#!/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-get clean
apt-get update

retval=0
for i in `seq 1 3`; do
    apt-get -y -d install dosis dosis-kiosk dosis-updater dosis-loto
	retval=$?
	if [ ${retval} = 0 ]; then
		break
	fi
done

exit ${retval}

