From 8f400b8fdd6d4038928194799ef3f0852c86e6d4 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Mon, 17 Aug 2015 17:02:01 -0300 Subject: Move scripts from /tmp -> /usr/local/share/pfSense --- usr/local/share/pfSense/post_upgrade_command | 64 ++++++++++++++++++++++++ usr/local/share/pfSense/post_upgrade_command.php | 31 ++++++++++++ usr/local/share/pfSense/pre_upgrade_command | 58 +++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100755 usr/local/share/pfSense/post_upgrade_command create mode 100755 usr/local/share/pfSense/post_upgrade_command.php create mode 100644 usr/local/share/pfSense/pre_upgrade_command (limited to 'usr/local') diff --git a/usr/local/share/pfSense/post_upgrade_command b/usr/local/share/pfSense/post_upgrade_command new file mode 100755 index 0000000..eea691f --- /dev/null +++ b/usr/local/share/pfSense/post_upgrade_command @@ -0,0 +1,64 @@ +#!/bin/sh + +/etc/rc.conf_mount_rw + +PFSENSETYPE=`cat /etc/platform` + +if [ "${PFSENSETYPE}" = "pfSense" -o "${PFSENSETYPE}" = "nanobsd" ]; then + touch /conf/needs_package_sync +fi + +# Detect interactive logins and display the shell +detect_command='[ -n "$SSH_TTY" -o "$TERM" = "cons25" ] && exec /etc/rc.initial' +echo "${detect_command}" > ${CVS_CO_DIR}/root/.shrc +echo "${detect_command}" >> ${CVS_CO_DIR}/root/.profile + +if [ "${PFSENSETYPE}" = "nanobsd" ]; then + ROOT=/tmp/${1}/ +else + ROOT=/ +fi + +# Now turn on or off serial console as needed +echo "Checking for ${ROOT}tmp/post_upgrade_command.php... " >> /conf/upgrade_log.txt +if [ -x ${ROOT}tmp/post_upgrade_command.php ]; then + echo "Running ${ROOT}tmp/post_upgrade_command.php $1" >> /conf/upgrade_log.txt + ${ROOT}tmp/post_upgrade_command.php $1 >> /conf/upgrade_log.txt 2>&1 +fi + +# Remove any previous MD5 sum files +rm -f /root/*.md5 >/dev/null 2>&1 + +# Fixup permissions on installed files +if [ -f ${ROOT}etc/installed_filesystem.mtree ]; then + if [ -x "/tmp/mtree.old" ]; then + MTREE_BIN=/tmp/mtree.old + else + MTREE_BIN=/usr/sbin/mtree + fi + ${MTREE_BIN} -U -e -q -f ${ROOT}etc/installed_filesystem.mtree -p ${ROOT} > /conf/mtree.log +fi + +# Make sure to preserve existing time zone +if [ "${PFSENSETYPE}" = "nanobsd" -a -f /etc/localtime ]; then + /bin/cp -p /etc/localtime ${ROOT}etc/localtime 2>/dev/null +fi + +# Files may contain spaces +oIFS=${IFS} +IFS=" +" +# Obsolete files - nanobsd doesn't need it since a new image is installed +# on the other partition +if [ "${PFSENSETYPE}" != "nanobsd" -a -f /etc/pfSense.obsoletedfiles ]; then + for f in $(cat /etc/pfSense.obsoletedfiles); do + if [ -n "${f}" -a -f "${f}" ]; then + rm -f "${f}" + elif [ -n "${f}" -a -d "${f}" ]; then + rm -rf "${f}" + fi + done +fi + +# Restore IFS +IFS=${oIFS} diff --git a/usr/local/share/pfSense/post_upgrade_command.php b/usr/local/share/pfSense/post_upgrade_command.php new file mode 100755 index 0000000..c2b6901 --- /dev/null +++ b/usr/local/share/pfSense/post_upgrade_command.php @@ -0,0 +1,31 @@ +#!/usr/local/bin/php -f +> /conf/upgrade_log.txt"); + setup_serial_port("upgrade", $newslicedir); + +?> diff --git a/usr/local/share/pfSense/pre_upgrade_command b/usr/local/share/pfSense/pre_upgrade_command new file mode 100644 index 0000000..2ad365f --- /dev/null +++ b/usr/local/share/pfSense/pre_upgrade_command @@ -0,0 +1,58 @@ +#!/bin/sh + +/etc/rc.conf_mount_rw + +# Record the previous version +PRIOR_VERSION=`uname -r | cut -d'.' -f1` +echo $PRIOR_VERSION > /tmp/pre_upgrade_version + +# De-activate sync on root filesystem. See ticket #4523 +# Back up original fstab +/bin/cp /etc/fstab /etc/fstab.orig +# De-activate sync on the root slice only. This will not match NanoBSD since it already has sync,noatime +/usr/bin/sed -i '' 's/^\(\/.*[[:space:]]*\/[[:space:]]*ufs[[:space:]]*\)rw,sync\([[:space:]]*[[:digit:]][[:space:]]*[[:digit:]]\)$/\1rw\2/' /etc/fstab + +# Hack to workaround ticket #3749 +if [ ${PRIOR_VERSION} -le 8 ] && grep -q 'sh /etc/rc.reboot' /etc/rc.firmware; then + PROC=$(ps axwww | grep '/etc/rc.firmware *pfSenseupgrade') + PID='' + IMG='' + if [ -n "${PROC}" ]; then + PID=$(echo "${PROC}" | awk '{print $1}') + IMG=$(echo "${PROC}" | sed 's,^.*pfSenseupgrade *,,') + fi + + if [ -n "${PID}" -a -n "${IMG}" -a -f "${IMG}" ]; then + cp -fp /bin/sh /tmp/sh.old + kill ${PID} >/dev/null 2>&1 + kill -9 ${PID} >/dev/null 2>&1 + sed -i '' -e 's,sh /,/tmp/sh.old /,' \ + -e 's,/usr/sbin/mtree,/tmp/mtree.old,' /etc/rc.firmware + # To avoid restarting rc.firmware twice because of #4328 + sed -i '' -e '/^restore_chflags()/, /^}/ s/mtree *-PU/mtree -P/' /etc/rc.firmware + /etc/rc.firmware pfSenseupgrade "${IMG}" + exit + fi +fi + +# One more hack to workaround #4328 +if grep -q 'mtree *-PU' /etc/rc.firmware; then + PROC=$(ps axwww | grep '/etc/rc.firmware *pfSenseupgrade') + PID='' + IMG='' + if [ -n "${PROC}" ]; then + PID=$(echo "${PROC}" | awk '{print $1}') + IMG=$(echo "${PROC}" | sed 's,^.*pfSenseupgrade *,,') + fi + + if [ -n "${PID}" -a -n "${IMG}" -a -f "${IMG}" ]; then + kill ${PID} >/dev/null 2>&1 + kill -9 ${PID} >/dev/null 2>&1 + sed -i '' -e '/^restore_chflags()/, /^}/ s/mtree *-PU/mtree -P/' /etc/rc.firmware + /etc/rc.firmware pfSenseupgrade "${IMG}" + exit + fi +fi + +rm /boot/kernel/* + -- cgit v1.1