#!/bin/sh
# FreeBSD system upgade script
#
# Licence: BSDLike - http://rickvanderzwet.nl/LICENSE
# Rick van der Zwet <info@rickvanderzwet.nl>

. /etc/rc.subr

if [ `id -u` -ne 0 ]; then
    echo "Sorry root only" 1>&2
    exit 128
fi

DIRNAME=`dirname $0`
BATCH=${BATCH-""}

$DIRNAME/port-list.sh

# Update port tree
echo "# Updating portstree .."
portsnap update

# Update ports listing
echo "# Checking ports which needs updating ..."
NEWPORTS=`pkg_version -qL=`

if [ -z "$NEWPORTS" ]; then
  echo "# System up2date"
  exit 0
fi

if [ -z "$BATCH" ]; then
  # Make sure we have read the (new) UPDATING announcements
  less /usr/ports/UPDATING

  echo $NEWPORTS
  # And agree to the terms of the game
  echo -n "Do you like to upgrade the affected ports [no]: "; read INPUT

  INPUT=${INPUT:-"no"}
  checkyesno INPUT || exit 1
  echo "Foo"
fi

portupgrade -r -mBATCH=yes -a $NEWPORTS
