#!/bin/bash
set -euo pipefail

if [ $# -eq 0 ]; then
    echo "Usage: install_license license_file1.txt [license_file2.md, license_file3.rtf, ...]" >&2
    exit 1
fi

# If we're running at build time, install into `${prefix}`.
# If we're running at extraction time, install into `${extract_dir}`
INSTALL_ROOT="${extract_dir:-${prefix}}"
for file in "$@"; do
    DEST="${INSTALL_ROOT}/share/licenses/${SRC_NAME}/$(basename "${file}")"
    echo "Installing license file \"$file\" to \"${DEST}\"..."
    install -Dm644 "${file}" "${DEST}"
done
