# This is the config file for the catalyst-auto script. It should be pretty
# self-explanatory.

UPLOAD_USER=m68k
UPLOAD_KEY=/root/.ssh/id_ed25519

host=$(hostname)

SPECS_DIR=${REPO_DIR}/releases/specs-qemu/m68k

EMAIL_SUBJECT_PREPEND="[m68k-qemu-auto]"

SETS="
	openrc_23
	systemd_23
	musl_23
	openrc
	musl
"

SET_openrc_SPECS="stage1-openrc.spec stage3-openrc.spec"

SET_musl_SPECS="stage1-musl.spec stage3-musl.spec"

SET_openrc_23_SPECS="stage1-openrc-23.spec stage3-openrc-23.spec"

SET_systemd_23_SPECS="stage1-systemd-23.spec stage3-systemd-23.spec"

SET_musl_23_SPECS="stage1-musl-23.spec stage3-musl-23.spec"

update_symlinks() {
	# Symlink the latest stages3 to build from
	local d f
	for d in "${BUILD_SRCDIR_BASE}/builds"/* ; do
		mkdir -p "${d}"
		pushd "${d}" >/dev/null
		for f in $(ls stage3*xz | grep -v latest | give_latest_from_dates) ; do
			local of=$(echo "${f}" | convert_filename)
			ln -sf "${f}" "${of}"
		done
		popd >/dev/null
	done
}

post_build() {
	local set=$1 spec=$2

	case ${spec} in
		stage3-openrc.spec)
			pushd "${BUILD_SRCDIR_BASE}/builds/default" >/dev/null
			upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/default/stage3-m68k" m68k/17.0/m68k
			popd >/dev/null
			;;
		stage3-musl.spec)
			pushd "${BUILD_SRCDIR_BASE}/builds/musl" >/dev/null
			upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl/stage3-m68k_musl" m68k/17.0/m68k_musl
			popd >/dev/null
			;;
		stage3-openrc-23.spec)
			pushd "${BUILD_SRCDIR_BASE}/builds/23.0-default" >/dev/null
			upload stage3-m68k-openrc-${TIMESTAMP}*.xz*
			popd >/dev/null
			;;
		stage3-systemd-23.spec)
			pushd "${BUILD_SRCDIR_BASE}/builds/23.0-default" >/dev/null
			upload stage3-m68k-systemd-${TIMESTAMP}*.xz*
			upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-default/stage3-m68k" m68k/23.0/m68k
			popd >/dev/null
			;;
		stage3-musl-23.spec)
			pushd "${BUILD_SRCDIR_BASE}/builds/23.0-musl" >/dev/null
			upload stage3-m68k_musl-${TIMESTAMP}*.xz*
			upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl/stage3-m68k_musl" m68k/23.0/m68k_musl
			popd >/dev/null
			;;
		*)
			echo "Finished ${spec}"
			;;
	esac
}
