#!/bin/sh -e

##########################################################################
#   Script description:
#       Check out a new instance of FreeBSD-ports-wip
#
#   Arguments:
#       None
#
#   History:
#   Date        Name        Modification
#   2019-11-17  Jason Bacon Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Function description:
#       Pause until user presses return
##########################################################################

pause()
{
    local junk
    
    printf "Press return to continue..."
    read junk
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

if [ `id -un` != root ]; then
    printf "$0 must be run by root.\n"
    exit 1
fi

case $(auto-ostype) in
FreeBSD)
    if [ ! -e /usr/ports/CHANGES ]; then
	auto-ports-checkout
    fi
    # Need for github cert
    pkg install -y ca_root_nss
    if [ ! -e $(auto-localbase)/sbin/wip-update ] || [ ! -e $PORTSDIR/wip ]; then
	fetch https://github.com//outpaddling/freebsd-ports-wip/raw/master/freebsd-wip-checkout
	sh ./freebsd-wip-checkout
	rm -f freebsd-wip-checkout
    fi
    ;;

DragonFly)
    export PORTSDIR=/usr/dports
    
    if [ ! -e /usr/dports/Makefile ]; then
	auto-ports-checkout
    fi
    # Need for github cert
    pkg install -y ca_root_nss
    if [ ! -e $(auto-localbase)/sbin/wip-update ] || [ ! -e $PORTSDIR/wip ]; then
	fetch https://github.com//outpaddling/freebsd-ports-wip/raw/master/freebsd-wip-checkout
	sh ./freebsd-wip-checkout
	rm -f freebsd-wip-checkout
    fi
    ;;

*)
    auto-unsupported-os $0
    exit 1
    ;;

esac
