summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/pkgimg.sh1
-rwxr-xr-xbin/pkgmk.sh1
-rw-r--r--lib/config.sh181
3 files changed, 0 insertions, 183 deletions
diff --git a/bin/pkgimg.sh b/bin/pkgimg.sh
index d093c45..7d0df70 100755
--- a/bin/pkgimg.sh
+++ b/bin/pkgimg.sh
@@ -23,7 +23,6 @@ export LIBDIR="${BASEDIR}/lib"
source ${LIBDIR}/log.sh
source ${LIBDIR}/pkg.sh
-source ${LIBDIR}/config.sh
source ${LIBDIR}/common.sh
export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports}
diff --git a/bin/pkgmk.sh b/bin/pkgmk.sh
index c155297..8b88e0d 100755
--- a/bin/pkgmk.sh
+++ b/bin/pkgmk.sh
@@ -22,7 +22,6 @@ export BASEDIR="$(cd $(dirname ${0})/../ && pwd)"
export LIBDIR="${BASEDIR}/lib"
source ${LIBDIR}/log.sh
-source ${LIBDIR}/config.sh
source ${LIBDIR}/template.sh
source ${LIBDIR}/port.sh
diff --git a/lib/config.sh b/lib/config.sh
deleted file mode 100644
index afc186c..0000000
--- a/lib/config.sh
+++ /dev/null
@@ -1,181 +0,0 @@
-#!/usr/bin/env bash
-#
-# Libconfig provides basic global configuration key/value support
-# Copyright (C) 2016 Aaron Ball <nullspoon@oper.io>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-#
-# libconfig
-# ---------
-# Libconfig provides support for a global configuration associative array
-# called 'configs'.
-#
-# This provides an easy way to store configuration data in a unified location.
-# With this data in a predictable unified location, it can easily be dumped and
-# reviewed.
-#
-# This also provides support to easily load single-dimensional delimited
-# configuration files through the load_config_with_delim function. This will
-# populate the global configs associative array with any key-value pairs that
-# are found.
-#
-
-set -u
-
-# Header guard
-if [[ -z ${!configs[@]} && -z ${__configssetup:-} ]]; then
- # Configs associative array is undefined
- # Define it along with the global reconstruction string, currently empty.
- declare -xA configs
- declare -x __configssetup=''
-elif [[ ! -z ${__configssetup:-} ]]; then
- # Configs undefined, but reconstruction code was found
- # Reconstruct using __configssetup
- # NOTE: This is a terrible hack to work around the bug in bash that disallows
- # passing of arrays and associative arrays to subshells.
- eval ${__configssetup}
-fi
-
-
-#
-# Parses the specified file, loading into the global configs associative array,
-# key-value pairs seperated by the specified delimiter. Leading and trailing
-# whitespace is removed to allow for human-friendly indentation. Comments are
-# also supported where the line starts with the common # comment character.
-#
-# Examples:
-#
-# key = value
-# key-two = value2
-#
-# - or -
-#
-# key: value
-# key-two: value2
-#
-# @param file Path to file to parse and load
-# @param delim Delimiter to use for seperating keys and values.
-#
-function load_config_with_delim {
- [[ -z ${1} ]] && log error "File argument required." && exit 1
- [[ -z ${2} ]] && log error "Delimiter argument required." && exit 1
-
- local file=${1}
- local delim=${2}
-
- [[ ! -f ${file} ]] && log error "Could not find config '${file}'" && exit 1
-
- local contents=$(cat ${file} | grep -v '^ *#' | grep -v '^[ ]*$' | sed 's/^ \+//')
-
- local oldifs=${IFS}
- export IFS=$'\n'
- for i in ${contents[@]}; do
- local key=$(echo ${i} | cut -d "${delim}" -f 1 | sed -e 's/ \+$//' -e 's/["'\'']//g')
- local val=$(echo ${i} | cut -d "${delim}" -f 2 | sed -e 's/^ \+//' -e 's/["'\'']//g')
- configs[$key]="${val}"
- done
- export IFS=${oldifs}
-}
-
-
-#
-# Dumps the global associative array to stdout. Output format is an
-# alphabetically sorted, space-delimited, aligned table (uses the column command
-# for alignment). Output is cumbersome for computers to parse, but easy to read
-# for humans. Useful for debugging.
-#
-# NOTE: Uses the 'ø' character for column delimiting because it is a very rare
-# character in most languages. If a config key or value contains this
-# character, output may be mangled.
-#
-function dump_configs {
- # Using something really strange to reduce the chance that we split on a
- # charcter that exists in a key or value.
- local delim='ø'
-
- # Set the table header
- local header="Key${delim}Value\n---${delim}-----\n"
- local out=''
-
- # configs needs to be a global associative array
- for key in ${!configs[@]}; do
- out="${out}${key}${delim}${configs[$key]}\n"
- done
-
- # Sort the variables
- out="$(echo -e ${out} | sort)"
-
- # Output
- echo -e "\nEnvironment:\n"
- echo -e "${header}${out}" | column -s ${delim} -t
- echo
-}
-
-
-#
-# Setter for the global configs data structure.
-#
-# NOTE: It is *highly* recommended to use this function to update values in the
-# global configs associative array because it will regenerate the
-# reconstruction string used for serializing the global assoc array for
-# passing to subshells.
-#
-# @param key Key to set
-# @param val Value to set
-#
-function config_set {
- local key=${1:-}
- local val=${2:-}
-
- [[ -z ${key} ]] && log error "Key argument (1) required." && exit 1
-
- configs[$key]="${val}"
-
- # Update the reconstruction string so it has the new value
- __configssetup=$(declare -p configs)
-}
-
-
-#
-# Getter for the global configs data structure. This function provides a bit of
-# added safety over the bash square bracket query, since this distinguishes
-# between unset and empty and will error if requested key could not be found.
-#
-# @param key Key to get
-#
-function config_get {
- local key=${1:-}
-
- [[ -z ${key} ]] && log error "Key argument (1) required." && return 1
-
- # Iterrate over the keys and return if a matching key is found.
- #
- # This is less efficient than just querying for the key using the bash square
- # bracket construct. However, this provides more flexibility in that if a
- # variable is not set, it allows us to exit gracefully with a log message
- # instead of just exiting.
- # This also allows the code to distinguish between unset and empty. The bash
- # square bracket functionality does not make this distrinction.
- for i in ${!configs[@]}; do
- if [[ ${i} == ${key} ]]; then
- echo ${configs[$key]}
- return 0
- fi
- done
-
- log error "Config ${key} is not set."
- return 1
-}

Generated by cgit