From fc48ef5427ef108a30dca4d42655fe040b0aa5c7 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Fri, 28 Aug 2015 11:53:03 -0300 Subject: Add macros between %% and %% on pfSense.ovf, then simplify the logic of ova_setup_ovf_template() --- tools/builder_common.sh | 66 +++++++++++++++++++---------------------- tools/templates/ovf/pfSense.ovf | 37 ++++++----------------- 2 files changed, 39 insertions(+), 64 deletions(-) diff --git a/tools/builder_common.sh b/tools/builder_common.sh index 1f4fc4d..d4abd2f 100644 --- a/tools/builder_common.sh +++ b/tools/builder_common.sh @@ -851,53 +851,47 @@ create_ova_image() { # called from create_ova_image ova_setup_ovf_template() { - if [ -f ${OVFTEMPLATE} ]; then - cp ${OVFTEMPLATE} ${OVA_TMP}/${PRODUCT_NAME}.ovf - else + if [ ! -f ${OVFTEMPLATE} ]; then echo ">>> ERROR: OVF template file (${OVFTEMPLATE}) not found." print_error_pfS fi - file_search_replace PRODUCT_VERSION $PRODUCT_VERSION ${OVA_TMP}/${PRODUCT_NAME}.ovf - file_search_replace PRODUCT_URL $PRODUCT_URL ${OVA_TMP}/${PRODUCT_NAME}.ovf + # OperatingSystemSection (${PRODUCT_NAME}.ovf) + # 42 FreeBSD 32-Bit + # 78 FreeBSD 64-Bit + if [ "${TARGET}" = "amd64" ]; then + local _os_id="78" + local _os_type="FreeBSD 64-Bit" + elif [ "${TARGET}" = "i386" ]; then + local _os_id="42" + local _os_type="FreeBSD" + else + echo ">>> ERROR: Platform not supported for OVA (${TARGET})" + print_error_pfS + fi - local BUILDPLATFORM=$(uname -p) local POPULATEDSIZE=$(du -d0 -m $FINAL_CHROOT_DIR | cut -f1) local POPULATEDSIZEBYTES=$((${POPULATEDSIZE}*1024^2)) local REFERENCESSIZE=$(stat -f "%z" ${OVA_TMP}/${OVFVMDK}) + echo ">>> Setting REFERENCESSIZE to ${REFERENCESSIZE}..." | tee -a ${LOGFILE} - file_search_replace REFERENCESSIZE ${REFERENCESSIZE} ${OVA_TMP}/${PRODUCT_NAME}.ovf echo ">>> Setting POPULATEDSIZEBYTES to ${POPULATEDSIZEBYTES}..." | tee -a ${LOGFILE} - # OperatingSystemSection (${PRODUCT_NAME}.ovf) - # 42 FreeBSD 32-Bit - # 78 FreeBSD 64-Bit - if [ "$BUILDPLATFORM" = "i386" ]; then - file_search_replace '"101"' '"42"' ${OVA_TMP}/${PRODUCT_NAME}.ovf - file_search_replace 'FreeBSD XX-Bit' 'FreeBSD' ${OVA_TMP}/${PRODUCT_NAME}.ovf - fi - if [ "$BUILDPLATFORM" = "amd64" ]; then - file_search_replace '"101"' '"78"' ${OVA_TMP}/${PRODUCT_NAME}.ovf - file_search_replace 'FreeBSD XX-Bit' 'FreeBSD 64-Bit' ${OVA_TMP}/${PRODUCT_NAME}.ovf - fi - file_search_replace DISKSECTIONPOPULATEDSIZE $POPULATEDSIZEBYTES ${OVA_TMP}/${PRODUCT_NAME}.ovf - # 10737254400 = 10240MB = virtual box vmdk file size XXX grab this value from vbox creation - # 10737418240 = 10GB - echo ">>> Setting DISKSECTIONALLOCATIONUNITS to 10737254400..." | tee -a ${LOGFILE} - file_search_replace DISKSECTIONALLOCATIONUNITS $OVA_DISKSECTIONALLOCATIONUNITS ${OVA_TMP}/${PRODUCT_NAME}.ovf - echo ">>> Setting DISKSECTIONCAPACITY to 10737418240..." | tee -a ${LOGFILE} - file_search_replace DISKSECTIONCAPACITY $OVADISKSIZE ${OVA_TMP}/${PRODUCT_NAME}.ovf -} - -# called from create_ova_image -# This routine will replace a string in a file -file_search_replace() { - local SEARCH="$1" - local REPLACE="$2" - local FILENAME="$3" + echo ">>> Setting DISKSECTIONALLOCATIONUNITS to ${OVA_DISKSECTIONALLOCATIONUNITS}..." | tee -a ${LOGFILE} + echo ">>> Setting DISKSECTIONCAPACITY to ${OVADISKSIZE}..." | tee -a ${LOGFILE} - if [ -f "${FILENAME}" ]; then - sed -i '' -e "s/${SEARCH}/${REPLACE}/g" ${FILENAME} - fi + sed \ + -e "s,%%REFERENCESSIZE%%,${REFERENCESSIZE},g" \ + -e "s,%%DISKSECTIONALLOCATIONUNITS%%,${OVA_DISKSECTIONALLOCATIONUNITS},g" \ + -e "s,%%DISKSECTIONCAPACITY%%,${OVADISKSIZE},g" \ + -e "s,%%DISKSECTIONPOPULATEDSIZE%%,${POPULATEDSIZEBYTES},g" \ + -e "s,%%OS_ID%%,${_os_id},g" \ + -e "s,%%OS_TYPE%%,${_os_type},g" \ + -e "s,%%PRODUCT_NAME%%,${PRODUCT_NAME},g" \ + -e "s,%%PRODUCT_VERSION%%,${PRODUCT_VERSION},g" \ + -e "s,%%PRODUCT_URL%%,${PRODUCT_URL},g" \ + -e "/^%%PRODUCT_LICENSE%%/r ${BUILDER_TOOR}/license.txt" \ + -e "/^%%PRODUCT_LICENSE%%/d" \ + ${OVFTEMPLATE} > ${OVA_TMP}/${PRODUCT_NAME}.ovf } # Cleans up previous builds diff --git a/tools/templates/ovf/pfSense.ovf b/tools/templates/ovf/pfSense.ovf index f70b9bd..84ff184 100644 --- a/tools/templates/ovf/pfSense.ovf +++ b/tools/templates/ovf/pfSense.ovf @@ -1,11 +1,11 @@ - + List of the virtual disks used in the package - + The list of logical networks @@ -19,9 +19,9 @@ pfSense virtual machine pfSense - - FreeBSD XX-Bit - FreeBSD XX-Bit (pfSense) + + %%OS_TYPE%% (pfSense) + %%OS_TYPE%% Virtual hardware requirements @@ -102,9 +102,9 @@ Describes product information for the service pfSense Electric Sheep Fencing, LLC - PRODUCT_VERSION - PRODUCT_URL - PRODUCT_URL + %%PRODUCT_VERSION%% + %%PRODUCT_URL%% + %%PRODUCT_URL%% An annotation @@ -113,26 +113,7 @@ The End User License Agreement -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. +%%PRODUCT_LICENSE%% -- cgit v1.1