summaryrefslogtreecommitdiffstats
path: root/src/usr/local/sbin
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/usr/local/sbin
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/usr/local/sbin')
-rwxr-xr-xsrc/usr/local/sbin/read_global_var31
-rwxr-xr-xsrc/usr/local/sbin/read_xml_tag.sh17
2 files changed, 35 insertions, 13 deletions
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