# Contributor: Will Sinatra <wpsinatra@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=amazon-ssm-agent
pkgver=3.3.859.0
pkgrel=0
pkgdesc="Amazon SSM Agent for managing EC2 Instances using the SSM APIs."
url="https://aws.amazon.com/documentation/systems-manager/"
license="Apache-2.0"
arch="all !s390x !riscv64 !ppc64le !loongarch64"
# armv7/armhf/x86 complains about cgo linking not being enabled
makedepends="go gcompat bash"
source="https://github.com/aws/amazon-ssm-agent/archive/$pkgver/amazon-ssm-agent-$pkgver.tar.gz
	amazon-ssm-agent.initd
	001_sanitize_makefile.patch"
subpackages="$pkgname-openrc"
options="!check net"
_binaries="amazon-ssm-agent
	ssm-agent-worker
	ssm-cli
	ssm-document-worker
	ssm-session-logger
	ssm-session-worker
	ssm-setup-cli
	"

case "$CARCH" in
	armhf) _build_arch=arm ;;
	armv7) _build_arch=arm ;;
	x86) _build_arch=386 ;;
	x86_64) _build_arch=amd64 ;;
	aarch64) _build_arch=arm64 ;;
esac

build() {
	make build-linux-$_build_arch
}

package() {
	for bin in $_binaries; do
		install -Dm0755 "$builddir"/bin/linux_$_build_arch/$bin "$pkgdir"/usr/bin/$bin
	done

	install -Dm0644 "$builddir"/bin/amazon-ssm-agent.json.template \
		"$pkgdir"/etc/amazon/ssm/amazon-ssm-agent.json.template
	install -Dm0644 "$builddir"/bin/seelog_unix.xml \
		"$pkgdir"/etc/amazon/ssm/seelog.xml
	install -Dm0644 "$builddir"/bin/seelog_windows.xml.template \
		"$pkgdir"/etc/amazon/ssm/seelog_windows.xml.template

	install -Dm0755 "$srcdir"/amazon-ssm-agent.initd \
		"$pkgdir"/etc/init.d/amazon-ssm-agent
}

sha512sums="
28343ad74af757d34127493a160759c3c0c321b6e2659580db9d992483fc343ad30027c32f63981ef9bd90e82301ce83c7933b56253d7369fcb0808f591163f8  amazon-ssm-agent-3.3.859.0.tar.gz
2c07d6777ad0d3994f09838818bff2c0bc061238e2c3ca757a9bd04cd25924ce24bdc2ecd7edbd4b10717ba3c8806398626e0718acf8e7ba5c66853369b20f48  amazon-ssm-agent.initd
d90a10ed7f3cf0a58bb73f737c2d10d56b3942886535df7d9215e2cf809c59ef708ed4d9775062e46343cf64726d25adaf048c86f39d4a7647deebd91d69c2f9  001_sanitize_makefile.patch
"
