#!/bin/sh
# $BSDnet: config/freebsd/enterprise/root/bin/run-pm-for-enterprise-base.sh,v 1.1 2018-02-20 12:08:53 trond Exp $

temporary_commandfile="/tmp/run-pm-for-enterprise-base-resume.sh"

for nv in `pkg version -vIL= | awk '{print $1}'`; do
  r_list="${r_list} -r ${nv}"
done
unset nv

if [ -z "${r_list}" ]; then
  echo "$0: empty list of outdated packages" >/dev/stderr
  echo "$0: maybe you should run svn up /usr/ports" >/dev/stderr
  exit 69
fi

commandline="portmaster --no-confirm --no-term-title --no-index-fetch --index-first -g -w -D -v -x enterprise-base ${r_list}"

echo "#!/bin/sh"                                        >  ${temporary_commandfile}
echo "export BATCH=yes"                                 >> ${temporary_commandfile}
echo "export DISABLE_VULNERABILITIES=yes"               >> ${temporary_commandfile}
echo "export PAGER=:"                                   >> ${temporary_commandfile}
echo "${commandline} -R && rm ${temporary_commandfile}" >> ${temporary_commandfile}
chmod u+x,o-rwx ${temporary_commandfile}

export BATCH=yes
export DISABLE_VULNERABILITIES=yes
export PAGER=:

${commandline} && rm ${temporary_commandfile}
