diff options
author | Aaron Ball <nullspoon@oper.io> | 2018-02-05 22:49:44 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2018-02-05 22:49:44 -0700 |
commit | 935701aeb500ee3dbdf20af998b1553b0d3dba34 (patch) | |
tree | b5e1b73ffdb9518ea2c058811caa0d8c66b209cc /libinstall | |
parent | a942935d2bb03683a6c632abf36ed75717717cc1 (diff) | |
download | pkgself-935701aeb500ee3dbdf20af998b1553b0d3dba34.tar.gz pkgself-935701aeb500ee3dbdf20af998b1553b0d3dba34.tar.xz |
Initial commit of support for libinstall resources
The libinstall resources will be used for packaging installation
libraries, such as a basic templating engine or simple shortcut
functions and aliases.
Updated LENS array to allow for an additional 8 byte archive. Also
updated archive index. Now...
1. header
2. libinstall
3. run.sh
4. payload
Added extract_libinstall function.
Along with this, also added the new libtemplate, which provides a very
basic templating engine to be used by the end user run.sh script if
needed.
Diffstat (limited to 'libinstall')
-rw-r--r-- | libinstall/template.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libinstall/template.sh b/libinstall/template.sh new file mode 100644 index 0000000..7254d8b --- /dev/null +++ b/libinstall/template.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Pkgself builds self-extracting installers +# Copyright (C) 2018 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 <https://www.gnu.org/licenses/>. + +template() { + # Disable trace output in case it is enabled + #set +x + local _src="${1:-}" + local _dest="${2:-}" + local varname # Name of the variable, without double braces + local delim=$'\001' + + local oldifs=${IFS} + export IFS=$'\n' + + # Create the list of all variables referenced in the file + local _vars=($(grep -o -h '{{ [a-Z0-9_\-]\+ }}' ${_src} | sort | uniq)) + + printf "Parsing template %s -> %s\n" "${_src}" "${_dest}" + install -D "${_src}" "${_dest}" + + for _var in ${_vars[@]}; do + printf "Parsing variable %s\n" "${var}" + _varref="$(printf ${_var} | cut -d ' ' -f 2)" + if [ -z "${!_varref:-}" ]; then + printf "Template %s variable '%s' is not set. Skipping.\n" \ + "$(basename ${_src})" \ + "${_varref}" + continue + fi + + echo sed -i "s${delim}{{ ${_varref} }}${delim}${!_varref}${delim}g" "${_dest}" + sed -i "s${delim}{{ ${_varref} }}${delim}${!_varref}${delim}g" "${_dest}" + done + + export IFS=${oldifs} + #set -x +} |