summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2015-10-01 13:26:03 -0300
committerRenato Botelho <renato@netgate.com>2015-10-01 13:27:30 -0300
commite4121dde007c66ec9e2f4c9ecb4a94d38c5fa6cc (patch)
tree211ec70afaea8c0610814f461dd3b040f157c158 /src
parent3ece711605c23bda1176e341d8f96417d3b82b5d (diff)
downloadpfsense-e4121dde007c66ec9e2f4c9ecb4a94d38c5fa6cc.zip
pfsense-e4121dde007c66ec9e2f4c9ecb4a94d38c5fa6cc.tar.gz
Introduce read_global_var:
- Add a new script, read_global_var, that returns the value of any item contained in global array $g - Replace all grep and sed magic from shell scripts
Diffstat (limited to 'src')
-rwxr-xr-xsrc/etc/rc25
-rwxr-xr-xsrc/etc/rc.firmware_auto13
-rwxr-xr-xsrc/etc/rc.initial13
-rwxr-xr-xsrc/etc/rc.php_ini_setup27
-rwxr-xr-xsrc/etc/rc.reboot13
-rwxr-xr-xsrc/etc/rc.shutdown13
-rwxr-xr-xsrc/usr/local/sbin/read_global_var31
-rwxr-xr-xsrc/usr/local/sbin/read_xml_tag.sh17
8 files changed, 54 insertions, 98 deletions
diff --git a/src/etc/rc b/src/etc/rc
index 22dec60..a0531c9 100755
--- a/src/etc/rc
+++ b/src/etc/rc
@@ -25,17 +25,9 @@ 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"}
+# Read product_name from $g, defaults to pfSense
+# Use php -n here because we are not ready to load extensions yet
+product=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var product_name pfSense)
# Setup dumpdev/ddb/savecore"
echo "Configuring crash dumps..."
@@ -148,17 +140,16 @@ if [ "$CDDEVICE" != "" ]; then
cdcontrol -f /dev/"$CDDEVICE" eject
fi
-varrunpath=$(cat ${globals_inc} | \
- grep varrun_path | \
- head -n 1 | \
- sed 's/^.*=>* *//; s/["\;,]*//g')
+# Use php -n here because we are not ready to load extensions yet
+varrunpath=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var varrun_path "/var/run")
if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; 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
+# Use php -n here because we are not ready to load extensions yet
+hideplatform=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var hideplatform)
+if [ "$hideplatform" = "true" ]; then
platformbanner="" # hide the platform
else
platformbanner=" on the '${PLATFORM}' platform"
diff --git a/src/etc/rc.firmware_auto b/src/etc/rc.firmware_auto
index 866db66..47ad8c9 100755
--- a/src/etc/rc.firmware_auto
+++ b/src/etc/rc.firmware_auto
@@ -10,17 +10,8 @@ FMBASEURL=$1
FMFILENAME=$2
FETCHFILENAME=$1/$2
-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"}
+# Read product_name from $g, defaults to pfSense
+product=$(/usr/local/sbin/read_global_var product_name pfSense)
# wait 5 seconds before beginning
sleep 5
diff --git a/src/etc/rc.initial b/src/etc/rc.initial
index b6ef02c..3d20ff1 100755
--- a/src/etc/rc.initial
+++ b/src/etc/rc.initial
@@ -44,17 +44,8 @@ fi
/etc/rc.banner
-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"}
+# Read product_name from $g, defaults to pfSense
+product=$(/usr/local/sbin/read_global_var product_name pfSense)
# Check to see if SSH is running.
if pgrep -q -a -F /var/run/sshd.pid sshd >/dev/null 2>&1; then
diff --git a/src/etc/rc.php_ini_setup b/src/etc/rc.php_ini_setup
index 2fd5add..b4038e7 100755
--- a/src/etc/rc.php_ini_setup
+++ b/src/etc/rc.php_ini_setup
@@ -76,16 +76,7 @@ fi
# Set upload directory
if [ "$PLATFORM" = "nanobsd" ]; then
- 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"}
+ UPLOADTMPDIR=$(/usr/local/sbin/read_global_var upload_path "/root")
else
UPLOADTMPDIR="/tmp"
fi
@@ -177,20 +168,8 @@ if [ -z "${TIMEZONE}" ]; then
fi
if [ -z "${TIMEZONE}" ]; then
- # Last option, use default value
- globals_inc="/etc/inc/globals.inc"
- if [ -f /etc/inc/globals_override.inc ]; then
- globals_inc="/etc/inc/globals_override.inc ${globals_inc}"
- fi
- TIMEZONE=$(cat ${globals_inc} | \
- grep default_timezone | \
- head -n 1 | \
- sed 's/^.*=>* *//; s/["\;,]*//g')
-fi
-
-if [ -z "${TIMEZONE}" ]; then
- # It it's still blank, lets avoid PHP errors
- TIMEZONE="Etc/UTC"
+ # Last option, use default value from $g or Etc/UTC
+ TIMEZONE=$(/usr/local/sbin/read_global_var default_timezone "Etc/UTC")
fi
# Get a loaded module list in the stock php
diff --git a/src/etc/rc.reboot b/src/etc/rc.reboot
index 1dae0d2..00169bf 100755
--- a/src/etc/rc.reboot
+++ b/src/etc/rc.reboot
@@ -9,17 +9,8 @@ fi
sleep 1
-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"}
+# Read product_name from $g, defaults to pfSense
+product=$(/usr/local/sbin/read_global_var product_name pfSense)
# If PLATFORM is $product then remove
# temporary files on shutdown from /tmp/
diff --git a/src/etc/rc.shutdown b/src/etc/rc.shutdown
index 55133f0..dec0267 100755
--- a/src/etc/rc.shutdown
+++ b/src/etc/rc.shutdown
@@ -5,17 +5,8 @@ if ! /usr/bin/lockf -s -t 30 /tmp/config.lock /usr/bin/true; then
exit -1
fi
-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"}
+# Read product_name from $g, defaults to pfSense
+product=$(/usr/local/sbin/read_global_var product_name pfSense)
echo
echo "${product} is now shutting down ..."
diff --git a/src/usr/local/sbin/read_global_var b/src/usr/local/sbin/read_global_var
new file mode 100755
index 0000000..2ea8462
--- /dev/null
+++ b/src/usr/local/sbin/read_global_var
@@ -0,0 +1,31 @@
+#!/usr/local/bin/php -f
+<?php
+
+if (empty(ini_get("date.timezone"))) {
+ ini_set("date.timezone", "Etc/UTC");
+}
+
+require_once("/etc/inc/globals.inc");
+
+global $g;
+
+if (!isset($argv[1]) || empty($argv[1])) {
+ exit;
+}
+
+if (isset($g[$argv[1]])) {
+ if (is_bool($g[$argv[1]])) {
+ if ($g[$argv[1]] == true) {
+ echo "true\n";
+ } else {
+ echo "false\n";
+ }
+ } else {
+ echo $g[$argv[1]] . "\n";
+ }
+} else if (isset($argv[2]) && !empty($argv[2])) {
+ // Print default value
+ echo "$argv[2]\n";
+}
+
+?>
diff --git a/src/usr/local/sbin/read_xml_tag.sh b/src/usr/local/sbin/read_xml_tag.sh
index a2d9092..6a3658f 100755
--- a/src/usr/local/sbin/read_xml_tag.sh
+++ b/src/usr/local/sbin/read_xml_tag.sh
@@ -15,18 +15,9 @@ if [ ! -f "$config" ]; then
exit 1
fi
-# Get xml_rootobj
-globals_inc="/etc/inc/globals.inc"
-if [ -f /etc/inc/globals_override.inc ]; then
- globals_inc="/etc/inc/globals_override.inc ${globals_inc}"
-fi
-xml_rootobj=$(cat ${globals_inc} | \
- grep xml_rootobj | \
- head -n 1 | \
- sed 's/^.*=>* *//; s/["\;,]*//g')
-
-# defaults to pfsense
-xml_rootobj=${product:-"pfsense"}
+# Get xml_rootobj, if not defined defaults to pfsense
+# Use php -n here because we are not ready to load extensions yet
+xml_rootobj=$(/usr/local/bin/php -n /usr/local/sbin/read_global_var xml_rootobj pfsense 2>/dev/null)
-/usr/local/bin/xmllint --xpath "${type}(//${xml_rootobj}/${path})" ${config}
+/usr/local/bin/xmllint --xpath "${type}(//${xml_rootobj}/${path})" ${config} 2>/dev/null
exit $?
OpenPOWER on IntegriCloud