#!/bin/bash set -eo pipefail main() { echo "Generating filesystem templates..." generate_templates exec $@ } generate_templates() { # Find *.gotmpl files and generate associated configuration files local template_files=$(find / -type f -name '*.gotmpl') for tmpl in $template_files; do local dest_file=${tmpl%".gotmpl"} echo "Generating file '$dest_file'..." gomplate -f "$tmpl" > "$dest_file" chmod $(stat -c '%a' "$tmpl") "$dest_file" chown $(stat -c '%u:%g' "$tmpl") "$dest_file" done } main $@