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

UPLOAD_USER=arm64
UPLOAD_KEY=/root/.ssh/id_ed25519
SPECS_DIR=${REPO_DIR}/releases/specs/arm64
SUBARCH=arm64

SETS="
	openrc_23
	openrc_23_su
	systemd_23
	llvm_openrc_23
	llvm_systemd_23
	musl_23
	musl_hardened_23
	musl_llvm_23
	openrc
	llvm_openrc
	musl
	musl_hardened
	musl_llvm
"

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

SET_openrc_23_SPECS="stage1-openrc-23.spec stage3-openrc-23.spec stage3d-openrc-23.spec"
SET_openrc_23_OPTIONAL_SPECS="installcd-stage1.spec installcd-stage2-minimal.spec"

SET_openrc_23_su_SPECS="stage1-openrc-23-su.spec stage3-openrc-23-su.spec"

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

SET_llvm_openrc_SPECS="llvm/stage1-openrc.spec llvm/stage3-openrc.spec"

SET_llvm_openrc_23_SPECS="llvm/stage1-openrc-23.spec llvm/stage3-openrc-23.spec"

SET_llvm_systemd_23_SPECS="llvm/stage1-systemd-23.spec llvm/stage3-systemd-23.spec"

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

SET_musl_hardened_SPECS="musl-hardened/stage1.spec musl-hardened/stage3.spec"

SET_musl_llvm_SPECS="musl-llvm/stage1.spec musl-llvm/stage3.spec"

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

SET_musl_hardened_23_SPECS="musl-hardened/stage1-23.spec musl-hardened/stage3-23.spec"

SET_musl_llvm_23_SPECS="musl-llvm/stage1-23.spec musl-llvm/stage3-23.spec"


KCONFIG_DIR=${REPO_DIR}/releases/kconfig/arm64

EMAIL_SUBJECT_PREPEND="[${SUBARCH}-auto]"

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-${SUBARCH}-*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

	pushd "${BUILD_SRCDIR_BASE}/builds/23.0-default" >/dev/null
	case ${spec} in
	stage3-openrc-23.spec)
		upload stage3-${SUBARCH}-openrc-${TIMESTAMP}*.xz*
		# do not upsync_binpackages, done by extra builder
		;;
	stage3d-openrc-23.spec)
		upload stage3-${SUBARCH}-desktop-openrc-${TIMESTAMP}*.xz*
		# do not upsync_binpackages, done by extra builder
		;;
	stage3-systemd-23.spec)
		upload stage3-${SUBARCH}-systemd-${TIMESTAMP}*.xz*
		# do not upsync_binpackages, done by extra builder
		;;
	stage3d-systemd-23.spec)
		upload stage3-${SUBARCH}-desktop-systemd-${TIMESTAMP}*.xz*
		# do not upsync_binpackages, done by extra builder
		;;
	installcd-stage2-minimal.spec)
		upload install-arm64-*${TIMESTAMP}*.iso*
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/23.0-splitusr" >/dev/null
	case ${spec} in
	stage3-openrc-23-su.spec)
		upload stage3-${SUBARCH}-openrc-splitusr-${TIMESTAMP}*.xz*
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/llvm" >/dev/null
	case ${spec} in
	llvm/stage3-openrc.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/llvm/stage3-arm64" arm64/17.0/arm64_llvm
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/23.0-llvm" >/dev/null
	case ${spec} in
	llvm/stage3-openrc-23.spec)
		upload stage3-${SUBARCH}-llvm-openrc-${TIMESTAMP}*.xz*
		;;
	llvm/stage3-systemd-23.spec)
		upload stage3-${SUBARCH}-llvm-systemd-${TIMESTAMP}*.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-llvm/stage3-arm64" arm64/23.0/arm64_llvm
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/musl" >/dev/null
	case ${spec} in
	musl/stage3.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl/stage3-arm64" arm64/17.0/arm64_musl
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/23.0-musl" >/dev/null
	case ${spec} in
	musl/stage3-23.spec)
		upload stage3-${SUBARCH}-*${TIMESTAMP}*.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl/stage3-arm64" arm64/23.0/arm64_musl
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/musl-hardened" >/dev/null
	case ${spec} in
	musl-hardened/stage3.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl-hardened/stage3-arm64" arm64/17.0/arm64_musl_hardened
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/23.0-musl-hardened" >/dev/null
	case ${spec} in
	musl-hardened/stage3-23.spec)
		upload stage3-${SUBARCH}-*${TIMESTAMP}*.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl-hardened/stage3-arm64" arm64/23.0/arm64_musl_hardened
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/musl-llvm" >/dev/null
	case ${spec} in
	musl-llvm/stage3.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl-llvm/stage3-arm64" arm64/17.0/arm64_musl_llvm
		;;
	esac
	popd >/dev/null

	pushd "${BUILD_SRCDIR_BASE}/builds/23.0-musl-llvm" >/dev/null
	case ${spec} in
	musl-llvm/stage3-23.spec)
		upload stage3-${SUBARCH}-*${TIMESTAMP}*.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl-llvm/stage3-arm64" arm64/23.0/arm64_musl_llvm
		;;
	esac
	popd >/dev/null
}
