diff options
author | Renato Botelho <renato@netgate.com> | 2015-10-01 10:21:43 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-10-01 10:21:43 -0300 |
commit | a5c36eb22154a2f17bba4329ee85627eeb64b664 (patch) | |
tree | c3bfe52067f1af8586dd85c2118cb66f55d2b227 /src/etc | |
parent | 339b88930513dec2bc986df7c0cd7255b6815d56 (diff) | |
download | pfsense-a5c36eb22154a2f17bba4329ee85627eeb64b664.zip pfsense-a5c36eb22154a2f17bba4329ee85627eeb64b664.tar.gz |
Introduce read_xml_tag.sh
Create /usr/local/sbin/read_xml_tag.sh, that will read a xml tag from
config file using xmllint. Replace all direct read using cat, grep, sed,
... by this script
Diffstat (limited to 'src/etc')
-rwxr-xr-x | src/etc/rc | 24 | ||||
-rwxr-xr-x | src/etc/rc.embedded | 8 | ||||
-rwxr-xr-x | src/etc/rc.php_ini_setup | 22 | ||||
-rwxr-xr-x | src/etc/rc.reboot | 4 | ||||
-rwxr-xr-x | src/etc/rc.shutdown | 4 | ||||
-rw-r--r-- | src/etc/skel/dot.shrc | 4 | ||||
-rw-r--r-- | src/etc/skel/dot.tcshrc | 4 |
7 files changed, 38 insertions, 32 deletions
@@ -103,8 +103,8 @@ if [ ! "${PLATFORM}" = "cdrom" ]; then fi fi - USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` - if [ "${PLATFORM}" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then + USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar) + if [ "${PLATFORM}" = "nanobsd" ] || [ "${USE_MFS_TMPVAR}" = "true" ]; then /etc/rc.embedded fi fi @@ -153,7 +153,7 @@ varrunpath=$(cat ${globals_inc} | \ head -n 1 | \ sed 's/^.*=>* *//; s/["\;,]*//g') -if [ "$PLATFORM" = "${product}" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then +if [ "$PLATFORM" = "${product}" ] && [ "${USE_MFS_TMPVAR}" != "true" ]; then /sbin/mdmfs -S -M -s 4m md $varrunpath fi @@ -175,13 +175,13 @@ echo 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 + if [ "${USE_MFS_TMPVAR}" != "true" -a -d /root/var/db/pkg ]; then rm -rf /var/db/pkg 2>/dev/null rm -rf /var/cache/pkg 2>/dev/null mv /root/var/db/pkg /var/db mv /root/var/cache/pkg /var/cache # If use MFS var is enabled, move files to a safe place - elif [ ${USE_MFS_TMPVAR} -gt 0 -a ! -d /root/var/db/pkg ]; then + elif [ "${USE_MFS_TMPVAR}" = "true" -a ! -d /root/var/db/pkg ]; then /bin/mkdir -p /root/var/db /root/var/cache mv /var/db/pkg /root/var/db mv /var/cache/pkg /root/var/cache @@ -293,21 +293,19 @@ trap "echo 'Reboot interrupted'; exit 1" 3 /bin/rm -f /var/etc/nameserver* echo -n "." -DISABLESYSLOGCLOG=`/usr/bin/grep -c disablesyslogclog /cf/conf/config.xml` -ENABLEFIFOLOG=`/usr/bin/grep -c usefifolog /cf/conf/config.xml` +DISABLESYSLOGCLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/disablesyslogclog) +ENABLEFIFOLOG=$(/usr/local/sbin/read_xml_tag.sh boolean system/usefifolog) LOG_FILES="system filter dhcpd vpn pptps poes l2tps openvpn portalauth ipsec ppp relayd wireless lighttpd ntpd gateways resolver routing" -DEFAULT_LOG_FILE_SIZE=`/usr/local/bin/xmllint --xpath 'string(//pfsense/syslog/logfilesize)' /conf/config.xml` -if [ ! ${DEFAULT_LOG_FILE_SIZE} ]; then - DEFAULT_LOG_FILE_SIZE=511488 -fi +DEFAULT_LOG_FILE_SIZE=$(/usr/local/sbin/read_xml_tag.sh string syslog/logfilesize) +DEFAULT_LOG_FILE_SIZE=${DEFAULT_LOG_FILE_SIZE:-"511488"} for logfile in $LOG_FILES; do - if [ "$DISABLESYSLOGCLOG" -gt "0" ]; then + if [ "$DISABLESYSLOGCLOG" = "true" ]; then /usr/bin/touch /var/log/$logfile.log else if [ ! -f /var/log/$logfile.log ]; then - if [ "$ENABLEFIFOLOG" -gt "0" ]; then + if [ "$ENABLEFIFOLOG" = "true" ]; then # generate fifolog files /usr/sbin/fifolog_create -s ${DEFAULT_LOG_FILE_SIZE} /var/log/$logfile.log else diff --git a/src/etc/rc.embedded b/src/etc/rc.embedded index 663822d..f08c0ef 100755 --- a/src/etc/rc.embedded +++ b/src/etc/rc.embedded @@ -4,16 +4,16 @@ # For pfSense # Size of /tmp -USE_MFS_TMP_SIZE=`/usr/bin/grep use_mfs_tmp_size /cf/conf/config.xml | /usr/bin/cut -f2 -d'>' | /usr/bin/cut -f1 -d'<'` -if [ ! -z ${USE_MFS_TMP_SIZE} ] && [ ${USE_MFS_TMP_SIZE} -gt 0 ]; then +USE_MFS_TMP_SIZE=$(/usr/local/sbin/read_xml_tag.sh string system/use_mfs_tmp_size) +if [ -n "${USE_MFS_TMP_SIZE}" ] && [ ${USE_MFS_TMP_SIZE} -gt 0 ]; then tmpsize="${USE_MFS_TMP_SIZE}m" else tmpsize="40m" fi # Size of /var -USE_MFS_VAR_SIZE=`/usr/bin/grep use_mfs_var_size /cf/conf/config.xml | /usr/bin/cut -f2 -d'>' | /usr/bin/cut -f1 -d'<'` -if [ ! -z ${USE_MFS_VAR_SIZE} ] && [ ${USE_MFS_VAR_SIZE} -gt 0 ]; then +USE_MFS_VAR_SIZE=$(/usr/local/sbin/read_xml_tag.sh string system/use_mfs_var_size) +if [ -n "${USE_MFS_VAR_SIZE}" ] && [ ${USE_MFS_VAR_SIZE} -gt 0 ]; then varsize="${USE_MFS_VAR_SIZE}m" else varsize="60m" diff --git a/src/etc/rc.php_ini_setup b/src/etc/rc.php_ini_setup index f456e6b..2fd5add 100755 --- a/src/etc/rc.php_ini_setup +++ b/src/etc/rc.php_ini_setup @@ -165,16 +165,19 @@ if [ -f /usr/local/lib/php.ini ]; then fi LOADED_MODULES=`/usr/local/bin/php-cgi -m | /usr/bin/grep -v "\["` +unset TIMEZONE # Fetch the timezone from /var/db/zoneinfo if present if [ -f /var/db/zoneinfo ]; then TIMEZONE=$(cat /var/db/zoneinfo) -# Second option is from config.xml -elif grep -q '<timezone>' /cf/conf/config.xml; then - TIMEZONE=$(/usr/bin/sed -E \ - '/<timezone>/!d; s,^.*<timezone>,,; s,<.*,,' \ - /cf/conf/config.xml) -# Last option, use default value -else +fi + +if [ -z "${TIMEZONE}" ]; then + # Second option is from config.xml + TIMEZONE=$(/usr/local/sbin/read_xml_tag.sh string system/timezone) +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}" @@ -185,6 +188,11 @@ else sed 's/^.*=>* *//; s/["\;,]*//g') fi +if [ -z "${TIMEZONE}" ]; then + # It it's still blank, lets avoid PHP errors + TIMEZONE="Etc/UTC" +fi + # Get a loaded module list in the stock php # Populate a dummy php.ini to avoid # the file being clobbered and the firewall diff --git a/src/etc/rc.reboot b/src/etc/rc.reboot index 3b77520..1dae0d2 100755 --- a/src/etc/rc.reboot +++ b/src/etc/rc.reboot @@ -28,11 +28,11 @@ if [ "$PLATFORM" = "${product}" ]; then rm -rf /tmp/* fi -USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` +USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar) 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}" != "${product}" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then +if [ "${PLATFORM}" != "${product}" ] || [ "${USE_MFS_TMPVAR}" = "true" ] || [ "${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 bf79683..55133f0 100755 --- a/src/etc/rc.shutdown +++ b/src/etc/rc.shutdown @@ -37,11 +37,11 @@ if [ "$PLATFORM" = "${product}" ]; then find -x /tmp/* -type f -exec rm -f {} \; >/dev/null 2>&1 fi -USE_MFS_TMPVAR=`/usr/bin/grep -c use_mfs_tmpvar /cf/conf/config.xml` +USE_MFS_TMPVAR=$(/usr/local/sbin/read_xml_tag.sh boolean system/use_mfs_tmpvar) 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}" != "${product}" ] || [ ${USE_MFS_TMPVAR} -gt 0 ] || [ "${DISK_TYPE}" = "md" ]; then +if [ "${PLATFORM}" != "${product}" ] || [ "${USE_MFS_TMPVAR}" = "true" ] || [ "${DISK_TYPE}" = "md" ]; then /etc/rc.backup_rrd.sh /etc/rc.backup_dhcpleases.sh fi diff --git a/src/etc/skel/dot.shrc b/src/etc/skel/dot.shrc index 6f3c2fc..d3c9208 100644 --- a/src/etc/skel/dot.shrc +++ b/src/etc/skel/dot.shrc @@ -1,6 +1,6 @@ -HTTP_PROXY=`/usr/local/bin/xmllint --xpath 'string(//pfsense/system/proxyurl)' /conf/config.xml` +HTTP_PROXY=`/usr/local/sbin/read_xml_tag.sh string system/proxyurl` if [ "${HTTP_PROXY}" != "" ]; then - HTTP_PROXY_PORT=`/usr/local/bin/xmllint --xpath 'string(//pfsense/system/proxyport)' /conf/config.xml` + HTTP_PROXY_PORT=`/usr/local/sbin/read_xml_tag.sh string system/proxyport` if [ "${HTTP_PROXY_PORT}" != "" ]; then HTTP_PROXY="${HTTP_PROXY}:${HTTP_PROXY_PORT}" fi diff --git a/src/etc/skel/dot.tcshrc b/src/etc/skel/dot.tcshrc index 38cf897..a643e3b 100644 --- a/src/etc/skel/dot.tcshrc +++ b/src/etc/skel/dot.tcshrc @@ -20,9 +20,9 @@ if ($term == "xterm" || $term == "vt100" || $term == "vt102" || $term == "vt220" bindkey "\e[8~" end-of-line # End rxvt/konsole endif -set http_proxy=`/usr/local/bin/xmllint --xpath 'string(//pfsense/system/proxyurl)' /conf/config.xml` +set http_proxy=`/usr/local/sbin/read_xml_tag.sh string system/proxyurl` if (${http_proxy} != "") then - set http_proxy_port=`/usr/local/bin/xmllint --xpath 'string(//pfsense/system/proxyport)' /conf/config.xml` + set http_proxy_port=`/usr/local/sbin/read_xml_tag.sh string system/proxyport` if (${http_proxy_port} != "") then set http_proxy="${http_proxy}:${http_proxy_port}" endif |