#!/bin/sh
# SPDX-FileCopyrightText: 2023, 2024 Markus Uhlin <maxxe@rpblc.net>
# SPDX-License-Identifier: ISC

i_data_messages () {
	local _src_prefix _dest _files

	_src_prefix=${1}
	_dest=${2}

# welcome.backup
# welcome.old
	_files="
admotd
login
logout
logout.fancy
motd
unregistered
welcome
"

	echo "installing..."

	for file in ${_files}; do
		printf "%s -> %s: " "${_src_prefix}/${file}" "${_dest}/${file}"

		if [ -r "${_src_prefix}/${file}" ]; then
			if [ -r "${_dest}/${file}" ]; then
				echo "already exists (not overwriting)"
				diff -u -w \
				    "${_dest}/${file}" "${_src_prefix}/${file}"
				continue
			fi

			install -m 0644 "${_src_prefix}/${file}" "${_dest}"

			if [ $? -eq 0 ]; then
				echo "ok"
			else
				echo "error"
			fi
		else
			echo "not found"
		fi
	done
}

i_data_messages "${1}" "${2}"