#!/bin/bash
# dev/package/config - package configuration file support

set -e

lib_load 'dev/package/versions'


######
# Library Settings

dev_package_versions_config_init() {
	script_setting_vars package_config_list_sort
	package_config_list_sort=true
}


######
# Package configuration

package_config() {
	local version
	version=$(package_version_build_full)
	local gen_date=$(date +'%a %b %d, %Y')
	local gen_time=$(date +%H:%M:%S)
	cat<<CONFIG
# package.i7 - ${PKG} package configuration
# Regenerated by $script_name $package_version on $gen_date at $gen_time.
CONFIG

	package_config_header 'Package Settings'
	cat<<CONFIG
PKG_NAME="$PKG_NAME"
PKG="$PKG"
VERSION=$version
CONFIG

	if [ "$RELEASE_TYPE" -o "$PREFIX" ]; then
		package_config_header 'System Settings'
		[ -z "$PREFIX" ] || echo "PREFIX=$PREFIX"
		[ -z "$RELEASE_TYPE" ] || echo "RELEASE_TYPE=$RELEASE_TYPE"
	fi

	if [ "$SITE_BRANCH" -o "$SITE_VERSION" ]; then
		package_config_header 'Site Settings'
		[ -z "$SITE_BRANCH" ] || echo "SITE_BRANCH=$SITE_BRANCH"
		[ -z "$SITE_VERSION" ] || echo "SITE_VERSION=$SITE_VERSION"
	fi

	package_config_header 'Support Settings'
	cat<<CONFIG
AUTHOR="$AUTHOR"
URL="$URL"
SUPPORT_NAME="$SUPPORT_NAME"
SUPPORT_EMAIL="$SUPPORT_EMAIL"
CONFIG

	package_config_header 'Release Settings'
	cat <<CONFIG
RELEASE_BRANCH="$RELEASE_BRANCH"
CONFIG

	package_config_header 'Download Settings'
	cat <<CONFIG
DOWNLOAD_SCHEME="$DOWNLOAD_SCHEME"
DOWNLOAD_HOST="$DOWNLOAD_HOST"
DOWNLOAD_PATH="$DOWNLOAD_PATH"
CONFIG

	package_config_header 'Publishing Settings'
	cat <<CONFIG
PUBLISH_SSH_HOST="$PUBLISH_SSH_HOST"
PUBLISH_SSH_PATH="$PUBLISH_SSH_PATH"
CONFIG

	package_config_header 'Runtime Script'
	echo "RUNTIME=$RUNTIME"

	package_config_header 'Script Categories'
	package_config_list_sort=false \
		package_config_list GROUP_ORDER "${GROUP_ORDER[@]}"
	package_config_map GROUP_NAMES "${GROUP_ORDER[@]}"

	package_config_header 'Applications'
	package_config_list APPS "${APPS[@]}"

	package_config_header 'Libraries'
	package_config_list LIBS "${LIBS[@]}"

	package_config_header 'Configuration'
	package_config_list CONF "${CONF[@]}"

	package_config_header 'Distribution'
	local package_config_list_sort=false
	package_config_list DIST "${DIST[@]}"

	echo -e "\n\n# vim: syntax=sh"
}

package_config_header() {
	cat <<HDR

######
# $*

HDR
}

package_config_list() {
	local name=$1
	shift
	local -a names=( "$@" )
	! $package_config_list_sort || qsort_list names
	echo -e "\n$name=("
	for_each package_config_list_value "${names[@]}"
	echo $'\t'")"
}

package_config_list_value() { echo $'\t'"$1"; }

# package_config_map() - Regenerates the given elements ($@) of the named
# associated array ($1).
# $1 - Name of associative array variable
# $@ - Names of keys to regenerate.  If none are given, regenerates the
#      values for all of the keys in the array.
package_config_map() {
	local name=$1
	shift
	local -a keys=( "$@" )
	[ "$*" ] || eval "keys=( \"\${!$name[@]}\" )"
	for_each "package_config_map_item $name" "${keys[@]}"
}

# package_config_map_item() - Generates an assignment of the value held
# in the associative array ($1) in slot ($2).
package_config_map_item() {
	local var=$1
	local key=$2
	eval "val=\${$var[\$key]}"
	echo "$var[$key]='$val'"
}

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:35:18 PDT 2017 by mcsh d14 v0.23.0.