#!/bin/sh
#
# Unattended FreeBSD Ports upgrade cycle, please note that starting and stopping
# of services is taken care of in the pkgtools.conf
#
# Rick van der Zwet <info@rickvanderzwet.nl>
#
PATH=$PATH:/usr/local/sbin:/usr/local/bin
WC=`cd $(dirname $0); pwd -P`

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

# Make sure we always using the latest version
svn up --non-interactive `dirname $0` | grep '^[A-Z] ' && {
  sh $0
  exit 0
}

portmaster --version 1>/dev/null 2>/dev/null || make -C /usr/ports/ports-mgmt/portmaster BATCH=yes install clean

# Fetch the latest details and provide listing of packages to be updated
portsnap fetch update || exit 1

# Make sure the internal database is consistent
pkgdb -Fa || exit 1

# Install via portmaster
portmaster -adG
