#!/usr/bin/make -f

export PATH := /tmp/go/bin:$(PATH)
export SHELL := env PATH=$(PATH) /bin/bash

export DH_OPTIONS
export DH_GOPKG := github.com/GoogleCloudPlatform/guest-agent
export CGO_ENABLED := 0
export GOCACHE := /tmp/.cache
export GO111MODULE := on

%:
	dh $@  --buildsystem=golang --with=golang,systemd

override_dh_auto_install:
	# Binary-only package.
	dh_auto_install -- --no-source
	install -d debian/google-guest-agent/usr/share/google-guest-agent
	install -p -m 0644 instance_configs.cfg debian/google-guest-agent/usr/share/google-guest-agent

override_dh_golang:
	# We don't use any packaged dependencies, so skip dh_golang step.

override_dh_auto_build:
	dh_auto_build -O--buildsystem=golang -- -ldflags="-s -w -X main.version=$(VERSION)" -mod=readonly

override_dh_installinit:
	# We don't ship sysvinit files or need script changes for them.

override_dh_systemd_enable:
	install -d debian/google-guest-agent/lib/systemd/system
	install -p -m 0644 *.service debian/google-guest-agent/lib/systemd/system/
	install -d debian/google-guest-agent/lib/systemd/system-preset
	install -p -m 0644 *.preset debian/google-guest-agent/lib/systemd/system-preset/
	dh_systemd_enable google-guest-agent.service google-startup-scripts.service google-shutdown-scripts.service

override_dh_systemd_start:
	# Only perform start/stop actions for the guest agent.
	dh_systemd_start google-guest-agent.service
