#!/bin/bash set -Eeuo pipefail if [[ "$UID" -ne 0 ]]; then echo "This command must be run as root!" exit 1 fi # Get the directory of this script SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # This function iterates over all files contained in the directory passed as the first argument # and install them to the directory passed as the second argument, using the install command. # It preserves the directory structure of the source directory. # The remaining arguments are passed to the install command. function install_files() { local src_dir="$1" local dest_dir="$2" shift 2 find "$src_dir" -type f | while read -r file; do local relative_path="${file#$src_dir/}" local dest_path="$dest_dir/$relative_path" install "$@" "$file" "$dest_path" done } # Same but for directories function install_directories() { local src_dir="$1" local dest_dir="$2" shift 2 find "$src_dir" -type d | while read -r dir; do local relative_path="${dir#$src_dir}" relative_path="${relative_path#/}" # Remove leading slash if present local dest_path="$dest_dir/$relative_path" install "$@" -d "$dest_path" done } # This function templates a kickstart file by replacing placeholders with actual values. # The templates are located in the www/ks directory. # The output files are written to /var/www/ks. # The placeholders are in the format expected by envsubst. # The output files are named as /var/www/ks/