Skip to content

Docker friendly scripts: init_settings.tpl.sh

Ryan Fischbach edited this page Oct 23, 2017 · 1 revision
#!/bin/bash

function processCLIArgs
{
    while [[ $# -gt 0 ]] ; do
        case $1 in
            --site-id|--app-id)
                export SITE_ID=$2
                shift # extra beyond the "shift" at the end of the block
                ;;
            --site-landing-page|--home)
                export SITE_LANDING_PAGE=$2
                shift # extra beyond the "shift" at the end of the block
                ;;
            *)
                echo -e "\033[0;93mIgnoring unrecognized option [$1].\033[0m"
                ;;
        esac
        shift # to advance the loop
    done
}

###############################################################################
# MAIN SCRIPT BODY

export SITE_ID=${SITE_ID}
export SITE_LANDING_PAGE=${SITE_LANDING_PAGE}
processCLIArgs $@

if [[ -z ${SITE_ID} ]] ; then
  # if no ID specified, generate one
  SITE_ID=$( "${SITE_PATH}/app/cli/actionGenerateUUID.php" )
fi
if [[ -z ${SITE_LANDING_PAGE} ]] ; then
  # if not specified, use "joka/step"
  SITE_LANDING_PAGE="joka/step"
fi

TPL_SRC_FILE="${SITE_PATH}/res/templates/Settings.tpl"
PHP_DST_FILE="${SITE_PATH}/configs/anyhost/Settings.php"

if [ ! -f ${PHP_DST_FILE} ] ; then
  SED_PATTERN="s/%app_id%/${SITE_ID}/"
  SED_PATTERN+=";s/%landing_page%/${SITE_LANDING_PAGE}/"
  sed ${SED_PATTERN} ${TPL_SRC_FILE} > ${PHP_DST_FILE}
fi

Clone this wiki locally