From c580e34c6fe24107817d6a72956e77b23f043beb Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Wed, 30 Sep 2015 14:33:12 -0300 Subject: Consider globals_override.inc and replace hard coded pfSense string by product_name --- src/etc/rc | 32 +++++++++++++++++++++++--------- src/etc/rc.firmware_auto | 18 ++++++++++++++---- src/etc/rc.initial | 15 ++++++++++++--- src/etc/rc.php_ini_setup | 11 ++++++++++- src/etc/rc.reboot | 18 +++++++++++++++--- src/etc/rc.shutdown | 18 ++++++++++++++---- 6 files changed, 88 insertions(+), 24 deletions(-) diff --git a/src/etc/rc b/src/etc/rc index 06f9e91..af3f775 100755 --- a/src/etc/rc +++ b/src/etc/rc @@ -25,9 +25,21 @@ PLATFORM=`/bin/cat /etc/platform` # Set our current version version=`/bin/cat /etc/version` +globals_inc="/etc/inc/globals.inc" +if [ -f /etc/inc/globals_override.inc ]; then + globals_inc="/etc/inc/globals_override.inc ${globals_inc}" +fi +product=$(cat ${globals_inc} | \ + grep product_name | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') + +# product cannot be blank +product=${product:-"pfSense"} + # Setup dumpdev/ddb/savecore" echo "Configuring crash dumps..." -if [ "$PLATFORM" = "pfSense" ]; then +if [ "$PLATFORM" = "${product}" ]; then /etc/rc.dumpon fi @@ -106,7 +118,7 @@ if [ "${PLATFORM}" = "nanobsd" ]; then if [ $? -eq 0 ]; then /sbin/kldunload zfs fi -elif [ "$PLATFORM" = "pfSense" ]; then +elif [ "$PLATFORM" = "${product}" ]; then # Handle ZFS read-only case /sbin/kldstat -qm zfs if [ $? -eq 0 ]; then @@ -136,14 +148,16 @@ if [ "$CDDEVICE" != "" ]; then cdcontrol -f /dev/"$CDDEVICE" eject fi -product=`/usr/bin/grep product_name /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4` -hideplatform=`/usr/bin/grep hideplatform /etc/inc/globals.inc | /usr/bin/wc -l` -varrunpath=`/usr/bin/grep varrun_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4` +varrunpath=$(cat ${globals_inc} | \ + grep varrun_path | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') -if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then +if [ "$PLATFORM" = "${product}" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then /sbin/mdmfs -S -M -s 4m md $varrunpath fi +hideplatform=$(egrep -c 'hideplatform.*=>* *true' ${globals_inc} 2>/dev/null) if [ "$hideplatform" -gt "0" ]; then platformbanner="" # hide the platform else @@ -159,7 +173,7 @@ echo /sbin/conscontrol mute off >/dev/null -if [ "$PLATFORM" = "pfSense" ]; then +if [ "$PLATFORM" = "${product}" ]; then # If use MFS var is disabled, move files back to place if [ ${USE_MFS_TMPVAR} -eq 0 -a -d /root/var/db/pkg ]; then rm -rf /var/db/pkg 2>/dev/null @@ -205,7 +219,7 @@ fi # make some directories in /var /bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/db/rrd /var/at/jobs/ /var/empty 2>/dev/null /bin/rm -rf $varrunpath/* -if [ "$PLATFORM" != "pfSense" ]; then +if [ "$PLATFORM" != "${product}" ]; then /bin/rm /var/log/* 2>/dev/null fi @@ -355,7 +369,7 @@ if [ "$PLATFORM" = "nanobsd" ]; then fi # Launch external configuration loader for supported platforms -if [ "$PLATFORM" = "pfSense" ]; then +if [ "$PLATFORM" = "${product}" ]; then /usr/local/sbin/fcgicli -f /etc/ecl.php fi diff --git a/src/etc/rc.firmware_auto b/src/etc/rc.firmware_auto index 5b355df..866db66 100755 --- a/src/etc/rc.firmware_auto +++ b/src/etc/rc.firmware_auto @@ -10,7 +10,17 @@ FMBASEURL=$1 FMFILENAME=$2 FETCHFILENAME=$1/$2 -product=`cat /etc/inc/globals.inc | grep product_name | cut -d'"' -f4` +globals_inc="/etc/inc/globals.inc" +if [ -f /etc/inc/globals_override.inc ]; then + globals_inc="/etc/inc/globals_override.inc ${globals_inc}" +fi +product=$(cat ${globals_inc} | \ + grep product_name | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') + +# product cannot be blank +product=${product:-"pfSense"} # wait 5 seconds before beginning sleep 5 @@ -56,12 +66,12 @@ if [ "$DLHASH" = "$FILEHASH" ]; then /usr/local/bin/php-cgi /etc/rc.conf_mount_rw fi if [ -r "/tmp/custom.tgz" ]; then - sh /etc/rc.firmware pfSenseupgrade /tmp/latest.tgz /tmp/custom.tgz + sh /etc/rc.firmware ${product}upgrade /tmp/latest.tgz /tmp/custom.tgz else if [ "$PLATFORM" = "nanobsd" ]; then - sh /etc/rc.firmware pfSenseNanoBSDupgrade /tmp/latest.tgz + sh /etc/rc.firmware ${product}NanoBSDupgrade /tmp/latest.tgz else - sh /etc/rc.firmware pfSenseupgrade /tmp/latest.tgz + sh /etc/rc.firmware ${product}upgrade /tmp/latest.tgz fi fi exit 0 diff --git a/src/etc/rc.initial b/src/etc/rc.initial index 4a38341..b6ef02c 100755 --- a/src/etc/rc.initial +++ b/src/etc/rc.initial @@ -44,8 +44,17 @@ fi /etc/rc.banner -product=`grep product_name /etc/inc/globals.inc | cut -d'"' -f4` -hidebanner=`grep hidebanner /etc/inc/globals.inc | cut -d'"' -f4` +globals_inc="/etc/inc/globals.inc" +if [ -f /etc/inc/globals_override.inc ]; then + globals_inc="/etc/inc/globals_override.inc ${globals_inc}" +fi +product=$(cat ${globals_inc} | \ + grep product_name | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') + +# product cannot be blank +product=${product:-"pfSense"} # Check to see if SSH is running. if pgrep -q -a -F /var/run/sshd.pid sshd >/dev/null 2>&1; then @@ -128,7 +137,7 @@ case ${opmode} in /usr/local/sbin/pfSsh.php ;; 13) - /bin/sh /usr/local/sbin/pfSense-upgrade + /bin/sh /usr/local/sbin/${product}-upgrade ;; 14) php -f /etc/rc.initial.toggle_sshd diff --git a/src/etc/rc.php_ini_setup b/src/etc/rc.php_ini_setup index be66023..880f0f7 100755 --- a/src/etc/rc.php_ini_setup +++ b/src/etc/rc.php_ini_setup @@ -76,7 +76,16 @@ fi # Set upload directory if [ "$PLATFORM" = "nanobsd" ]; then - UPLOADTMPDIR=`/usr/bin/grep upload_path /etc/inc/globals.inc | /usr/bin/cut -d'"' -f4` + globals_inc="/etc/inc/globals.inc" + if [ -f /etc/inc/globals_override.inc ]; then + globals_inc="/etc/inc/globals_override.inc ${globals_inc}" + fi + UPLOADTMPDIR=$(cat ${globals_inc} | \ + grep upload_path | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') + + UPLOADTMPDIR=${UPLOADTMPDIR:-"/root"} else UPLOADTMPDIR="/tmp" fi diff --git a/src/etc/rc.reboot b/src/etc/rc.reboot index afdc93c..3b77520 100755 --- a/src/etc/rc.reboot +++ b/src/etc/rc.reboot @@ -9,10 +9,22 @@ fi sleep 1 -# If PLATFORM is pfSense then remove +globals_inc="/etc/inc/globals.inc" +if [ -f /etc/inc/globals_override.inc ]; then + globals_inc="/etc/inc/globals_override.inc ${globals_inc}" +fi +product=$(cat ${globals_inc} | \ + grep product_name | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') + +# product cannot be blank +product=${product:-"pfSense"} + +# If PLATFORM is $product then remove # temporary files on shutdown from /tmp/ PLATFORM=`cat /etc/platform` -if [ "$PLATFORM" = "pfSense" ]; then +if [ "$PLATFORM" = "${product}" ]; then rm -rf /tmp/* fi @@ -20,7 +32,7 @@ USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` DISK_NAME=`/bin/df /var/db/rrd | /usr/bin/tail -1 | /usr/bin/awk '{print $1;}'` DISK_TYPE=`/usr/bin/basename ${DISK_NAME} | /usr/bin/cut -c1-2` # If we are not on a full install, or if the full install wants RAM disks, or if the full install _was_ using RAM disks, but isn't for the next boot... -if [ "${PLATFORM}" != "pfSense" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then +if [ "${PLATFORM}" != "${product}" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then /etc/rc.backup_rrd.sh /etc/rc.backup_dhcpleases.sh fi diff --git a/src/etc/rc.shutdown b/src/etc/rc.shutdown index aa6468a..bf79683 100755 --- a/src/etc/rc.shutdown +++ b/src/etc/rc.shutdown @@ -5,7 +5,17 @@ if ! /usr/bin/lockf -s -t 30 /tmp/config.lock /usr/bin/true; then exit -1 fi -product=`cat /etc/inc/globals.inc | grep product_name | cut -d'"' -f4` +globals_inc="/etc/inc/globals.inc" +if [ -f /etc/inc/globals_override.inc ]; then + globals_inc="/etc/inc/globals_override.inc ${globals_inc}" +fi +product=$(cat ${globals_inc} | \ + grep product_name | \ + head -n 1 | \ + sed 's/^.*=>* *//; s/["\;,]*//g') + +# product cannot be blank +product=${product:-"pfSense"} echo echo "${product} is now shutting down ..." @@ -20,10 +30,10 @@ HOME=/; export HOME PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH -# If PLATFORM is pfSense then remove +# If PLATFORM is $product then remove # temporary files on shutdown from /tmp/ PLATFORM=`cat /etc/platform` -if [ "$PLATFORM" = "pfSense" ]; then +if [ "$PLATFORM" = "${product}" ]; then find -x /tmp/* -type f -exec rm -f {} \; >/dev/null 2>&1 fi @@ -31,7 +41,7 @@ USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` DISK_NAME=`/bin/df /var/db/rrd | /usr/bin/tail -1 | /usr/bin/awk '{print $1;}'` DISK_TYPE=`/usr/bin/basename ${DISK_NAME} | /usr/bin/cut -c1-2` # If we are not on a full install, or if the full install wants RAM disks, or if the full install _was_ using RAM disks, but isn't for the next boot... -if [ "${PLATFORM}" != "pfSense" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then +if [ "${PLATFORM}" != "${product}" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then /etc/rc.backup_rrd.sh /etc/rc.backup_dhcpleases.sh fi -- cgit v1.1