summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinstall-header.sh19
-rw-r--r--libinstall/template.sh51
-rwxr-xr-xpkgself.sh16
3 files changed, 77 insertions, 9 deletions
diff --git a/install-header.sh b/install-header.sh
index 766ba0a..a7b9269 100755
--- a/install-header.sh
+++ b/install-header.sh
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
-# This is a pre-allocated string of 30 chars of whitespace
+# This is a pre-allocated string of 39 chars of whitespace
# DO NOT CHANGE THIS without great care - it will break header length
# calculations
-LENS=( )
+LENS=( )
export SELF # Absolute path to the installer script (me!)
export TMP # Path to tmp install staging directory
export PAYLOAD # Path to the extracted payload directory
@@ -23,7 +23,7 @@ extract_chunk_index() {
skip=$(( skip + LENS[$i] ))
done
- [ "${dest}" != '-' ] && of="${dest}"
+ [ "${dest}" != '-' ] && of="of=${dest}"
# Extract the requested chunk index
dd bs=1 count=${LENS[$index]} iflag=skip_bytes skip=${skip} \
if=${src} ${of} 2>/dev/null
@@ -33,12 +33,16 @@ extract_header() {
extract_chunk_index "${SELF}" "${TMP}/header.sh" 0
}
+extract_libinstall() {
+ extract_chunk_index "${SELF}" '-' 1 | xz -d -c | tar -C "${TMP}" -x
+}
+
extract_runscript() {
- extract_chunk_index "${SELF}" '-' 1 | xz -d -c > "${TMP}/run.sh"
+ extract_chunk_index "${SELF}" '-' 2 | xz -d -c > "${TMP}/run.sh"
}
extract_payload() {
- extract_chunk_index "${SELF}" '-' 2 | xz -d -c | tar -C "${TMP}" -x
+ extract_chunk_index "${SELF}" '-' 3 | xz -d -c | tar -C "${TMP}" -x
export PAYLOAD="${TMP}/pkg"
}
@@ -48,10 +52,13 @@ main() {
TMP="$(mktemp -d /tmp/installer-XXXXXXX)"
extract_header
+ extract_libinstall
extract_runscript
- #extract_chunks "${self}" "${tmp}"
cd "${TMP}"
+
+ source libinstall/template.sh
+
source run.sh
# Function 'deploy' is provided by run.sh
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
+}
diff --git a/pkgself.sh b/pkgself.sh
index faba888..6e75b33 100755
--- a/pkgself.sh
+++ b/pkgself.sh
@@ -105,9 +105,14 @@ main() {
# Copy the installer header script into the tmp directory, with the right name
cp ${selfdir}/install-header.sh "${output}"
+
+ # Copy in libinstall directory to include useful install libraries
+ cp -r ${selfdir}/libinstall ${tmp}/libinstall
+
# Copy the run script into the tmp dir
install "${pkgdir}/run.sh" "${PKGSRC}/run.sh"
+
# Download all the source files (if needed)
cd "${pkgdir}"
for src in ${source[@]}; do
@@ -123,6 +128,10 @@ main() {
headsize=$(wc -c < ${output})
+ # Package up the libinstall libraries
+ tar -C "${tmp}" -c libinstall | xz -c > ${tmp}/libinstall.tar.xz
+ libinstallsize=$(wc -c < ${tmp}/libinstall.tar.xz)
+
# Compress and calculate byte size for run.sh
xz -c ${PKGSRC}/run.sh > ${tmp}/run.sh.xz
runsize="$(wc -c < ${tmp}/run.sh.xz)"
@@ -137,7 +146,7 @@ main() {
# 1. header: 8 byte digits allows a 95 MB header
# 2. run script: 8 byte digits allows a 95 MB run script
# 3. payload: 12 byte digits allows for a 931 GB file
- lens="$(printf '%8s %8s %12s' ${headsize} ${runsize} ${payloadsize})"
+ lens="$(printf '%8s %8s %8s %12s' ${headsize} ${libinstallsize} ${runsize} ${payloadsize})"
# Interpolate chunk lengths
# This space between ( and ) must be 60 chars so as to not change the header
@@ -145,8 +154,9 @@ main() {
sed -i "s/LENS=(.*)/LENS=(${lens})/g" "${output}"
# Append chunks to output file
- cat "${tmp}/run.sh.xz" >> "${output}"
- cat "${PKG}.tar.xz" >> "${output}"
+ cat "${tmp}/libinstall.tar.xz" >> "${output}"
+ cat "${tmp}/run.sh.xz" >> "${output}"
+ cat "${PKG}.tar.xz" >> "${output}"
# Cleanup
rm -rf ${tmp}

Generated by cgit