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

UPLOAD_USER=amd64
UPLOAD_KEY=/root/.ssh/id_ed25519
host=$(hostname)

EMAIL_SUBJECT_PREPEND="[amd64-auto]"

SPECS_DIR=${REPO_DIR}/releases/specs/amd64

SETS="
	openrc_23
	livegui_23
	openrc_23_su
	systemd_23
	nomultilib_openrc_23
	nomultilib_systemd_23
	llvm_openrc_23
	llvm_systemd_23
	hardened_openrc_23
	hardened_systemd_23
	hardened_selinux_openrc_23
	hardened_selinux_systemd_23
	musl_23
	musl_hardened_23
	musl_llvm_23
	x32_openrc_23
	x32_systemd_23
	openrc
	nomultilib_openrc
	llvm_openrc
	hardened_openrc
	hardened_nomultilib_openrc
	hardened_selinux_openrc
	hardened_nomultilib_selinux_openrc
	musl
	musl_hardened
	musl_llvm
	x32_openrc
"

# 17.0

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

SET_hardened_openrc_SPECS="hardened/stage1-openrc.spec hardened/stage3-openrc.spec"

SET_hardened_selinux_openrc_SPECS="hardened-selinux/stage1-openrc.spec hardened-selinux/stage3-openrc.spec"

SET_hardened_nomultilib_selinux_openrc_SPECS="hardened-nomultilib-selinux/stage1-openrc.spec hardened-nomultilib-selinux/stage3-openrc.spec"

SET_hardened_nomultilib_openrc_SPECS="hardened-nomultilib/stage1-openrc.spec hardened-nomultilib/stage3-openrc.spec"

SET_nomultilib_openrc_SPECS="nomultilib/stage1-openrc.spec nomultilib/stage3-openrc.spec"

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

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

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

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

SET_x32_openrc_SPECS="x32/stage1-openrc.spec x32/stage3-openrc.spec"

# 23.0

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

SET_livegui_23_OPTIONAL_SPECS="livegui/livegui-stage1.spec livegui/livegui-stage2.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"
SET_systemd_23_OPTIONAL_SPECS="stage3d-systemd-23.spec"

SET_hardened_openrc_23_SPECS="hardened/stage1-openrc-23.spec hardened/stage3-openrc-23.spec"
SET_hardened_openrc_23_OPTIONAL_SPECS="hardened/admincd-stage1.spec hardened/admincd-stage2.spec"

SET_hardened_systemd_23_SPECS="hardened/stage1-systemd-23.spec hardened/stage3-systemd-23.spec"

SET_hardened_selinux_openrc_23_SPECS="hardened-selinux/stage1-openrc-23.spec hardened-selinux/stage3-openrc-23.spec"

SET_hardened_selinux_systemd_23_SPECS="hardened-selinux/stage1-systemd-23.spec hardened-selinux/stage3-systemd-23.spec"

SET_nomultilib_openrc_23_SPECS="nomultilib/stage1-openrc-23.spec nomultilib/stage3-openrc-23.spec"

SET_nomultilib_systemd_23_SPECS="nomultilib/stage1-systemd-23.spec nomultilib/stage3-systemd-23.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_23_SPECS="musl/stage1-23.spec musl/stage3-23.spec"

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

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

SET_x32_openrc_23_SPECS="x32/stage1-openrc-23.spec x32/stage3-openrc-23.spec"

SET_x32_systemd_23_SPECS="x32/stage1-systemd-23.spec x32/stage3-systemd-23.spec"


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

EXTENSIONS="@(.tar.xz|.tar.bz2|.tar.gz|.tar|.sfs)"

update_symlinks() {
	# Symlink the latest stages3 to build from
	for d in "${BUILD_SRCDIR_BASE}/builds"/* ; do
		mkdir -p "${d}"
		pushd "${d}" >/dev/null || exit
		shopt -s extglob
		for f in $(ls stage3*${EXTENSIONS} | grep -v latest | give_latest_from_dates ) ; do
			# 20yymmddThhmmssZ
			# 20yymmddhhmmss
			# 20yymmdd
			# 20yy.n
			of=$(perl -p \
				-e 's/20\d{6}T\d{6}Z/latest/g;' \
				-e 's/20\d{6}\d{6}/latest/g;' \
				-e 's/20\d{6}/latest/g;' \
				-e 's/20\d{2}\.\d{2}/latest/g;' \
				<<<"$f")
			ln -sf "$f" "$of"
		done
		popd >/dev/null || exit
	done
}

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

	pushd "${BUILD_SRCDIR_BASE}"/builds/default >/dev/null || exit
	case ${spec} in
	x32/stage3-openrc.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/default/stage3-x32" amd64/17.0/x32
		;;
	esac
	popd >/dev/null || exit

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

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

	pushd "${BUILD_SRCDIR_BASE}"/builds/clang >/dev/null || exit
	case ${spec} in
	clang/stage3-openrc.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/clang/stage3-amd64" amd64/17.1/x86-64_llvm
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/23.0-llvm >/dev/null || exit
	case ${spec} in
	llvm/stage3-openrc-23.spec)
		upload stage3-amd64-llvm-openrc-${TIMESTAMP}.tar.xz*
		;;
	llvm/stage3-systemd-23.spec)
		upload stage3-amd64-llvm-systemd-${TIMESTAMP}.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-llvm/stage3-amd64" amd64/23.0/x86-64_llvm
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/hardened >/dev/null || exit
	case ${spec} in
	hardened/stage3-openrc.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/hardened/stage3-amd64" amd64/17.1/x86-64_hardened
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/23.0-hardened >/dev/null || exit
	case ${spec} in
	hardened/stage3-openrc-23.spec)
		upload stage3-amd64-hardened-openrc-${TIMESTAMP}.tar.xz*
		;;
	hardened/stage3-systemd-23.spec)
		upload stage3-amd64-hardened-systemd-${TIMESTAMP}.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-hardened/stage3-amd64" amd64/23.0/x86-64_hardened
		;;
	hardened/admincd-stage2.spec)
		upload admincd-amd64-${TIMESTAMP}.iso*
		;;
	hardened-nomultilib/stage3-openrc-23.spec)
		upload stage3-amd64-hardened-nomultilib-openrc-${TIMESTAMP}.tar.xz*
		;;
	hardened-nomultilib/stage3-systemd-23.spec)
		upload stage3-amd64-hardened-nomultilib-systemd-${TIMESTAMP}.tar.xz*
		;;
	hardened-selinux/stage3-openrc-23.spec)
		upload stage3-amd64-hardened-selinux-openrc-${TIMESTAMP}.tar.xz*
		;;
	hardened-nomultilib-selinux/stage3-openrc-23.spec)
		upload stage3-amd64-hardened-nomultilib-selinux-openrc-${TIMESTAMP}.tar.xz*
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/musl >/dev/null || exit
	case ${spec} in
	musl/stage3.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl/stage3-amd64" amd64/17.1/x86-64_musl
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/23.0-musl >/dev/null || exit
	case ${spec} in
	musl/stage3-23.spec)
		upload stage3-amd64-musl-${TIMESTAMP}.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl/stage3-amd64" amd64/23.0/x86-64_musl
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/musl-clang >/dev/null || exit
	case ${spec} in
	musl-clang/stage3.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl-clang/stage3-amd64" amd64/17.1/x86-64_musl_llvm
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/23.0-musl-llvm >/dev/null || exit
	case ${spec} in
	musl-llvm/stage3-23.spec)
		upload stage3-amd64-musl-llvm-${TIMESTAMP}.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl-llvm/stage3-amd64" amd64/23.0/x86-64_musl_llvm
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/musl-hardened >/dev/null || exit
	case ${spec} in
	musl-hardened/stage3.spec)
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/musl-hardened/stage3-amd64" amd64/17.1/x86-64_musl_hardened
		;;
	esac
	popd >/dev/null || exit

	pushd "${BUILD_SRCDIR_BASE}"/builds/23.0-musl-hardened >/dev/null || exit
	case ${spec} in
	musl-hardened/stage3-23.spec)
		upload stage3-amd64-musl-hardened-${TIMESTAMP}.tar.xz*
		upsync_binpackages "${BUILD_SRCDIR_BASE}/packages/23.0-musl-hardened/stage3-amd64" amd64/23.0/x86-64_musl_hardened
		;;
	esac
	popd >/dev/null || exit
}

# vim:ft=sh:
