Upgrading lang/php5 to lang/php56

The 20150220 entry in /usr/ports/UPDATING contains no instructions for upgrading lang/php5 to lang/php56, at least not for us compiling our own ports.

I learned the hard way using portupgrade what needs to be done. I have summarised my steps into the script below. Use the script as a guide, and if you do run my script, then you’re on your own. To save you some effort, here’s the script ready for downloading.

#!/bin/sh

# Copyright © 2015, Trond Endrestøl <Trond.Endrestol@ximalas.info>
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Check to see if lang/php5 exists and abort if it doesn't.
/usr/local/sbin/pkg query %o php5 >/dev/null 2>&1 || (echo "${0}: lang/php5 not installed" >/dev/stderr; exit 69)

# Forcefully upgrade lang/php5 to lang/php56, only this port.
/usr/local/sbin/portupgrade -ncfpvo lang/php56 lang/php5 || exit
/usr/local/sbin/portupgrade -fpvo lang/php56 lang/php5 || exit

# Gather a list of ports named php5- or _php5$ (regexp).
PHP5_PORTS=`/usr/local/sbin/pkg query -a %o | /usr/bin/egrep '(php5-)|(_php5$)'`

# Stop if there's nothing more to be done.
if [ -z "${PHP5_PORTS}" ]; then
  echo "${0}: no installed ports named php5-* nor *_php5" >/dev/stderr;
  exit 69;
fi

MISSING_PORTS=""
EXCLUDED_PORTS="-x lang/php56"

# Give the user a chance to configure the new ports, and gather any missing dependencies.
for p in ${PHP5_PORTS}; do
  PHP56_PORT_ORIGIN=`echo ${p} | /usr/bin/sed 's/php5/php56/'`;
  MISSING_PORTS="${MISSING_PORTS} `/usr/bin/make -C /usr/ports/${PHP56_PORT_ORIGIN} missing`";
  EXCLUDED_PORTS="${EXCLUDED_PORTS} -x ${PHP56_PORT_ORIGIN}";
  /usr/local/sbin/portupgrade -ncfpvo ${PHP56_PORT_ORIGIN} ${p} || exit;
done

# Sort the list of new dependencies and remove any duplicates.
MISSING_PORTS=`echo ${MISSING_PORTS} | /usr/bin/sort | /usr/bin/uniq`

# If there's anything missing, now's the chance to configure and install them.
if [ -n "${MISSING_PORTS}" ]; then
  /usr/local/sbin/portupgrade -ncNfprv ${MISSING_PORTS} || exit;
  /usr/local/sbin/portupgrade -Nfprv ${MISSING_PORTS} || exit;
fi
# Hopefully portupgrade should have done its job by now, but don't hold your breath.

# Upgrade each PHP5 port individually.
for p in ${PHP5_PORTS}; do
  PHP56_PORT_ORIGIN=`echo ${p} | /usr/bin/sed 's/php5/php56/'`;
  /usr/local/sbin/portupgrade -fpvo ${PHP56_PORT_ORIGIN} ${p} || exit;
done

# Forcefully recreate anything depending on lang/php56 including user applications, e.g. Moodle, WordPress, etc.
/usr/local/sbin/portupgrade -fprv ${EXCLUDED_PORTS} lang/php56 || exit

# Tell the user what to do next.
echo
echo "${0}: now you should stop and start Apache"