define newline


endef

define OPACK_PACKER_CONTENT =
{
	"description": "OpenBSD ${OPACK_SYS_VERSION} ${OPACK_SYS_ARCHITECTURE}",
		"variables": {
			"box_tag": "${OPACK_SYS_HOSTNAME}-${OPACK_TARGET}-{{ timestamp }}",
			"disk_size": "${OPACK_SYS_DISK_SIZE}",
			"memory": "${OPACK_SYS_MEMORY}",
			"cpus": "${OPACK_SYS_CPU}",
			"version": "${OPACK_BOX_VERSION}" },
		"builders": [ {
			"type": "qemu",
			"vm_name": "${OPACK_SYS_HOSTNAME}-${OPACK_TARGET}",
			"cpus": "{{user `cpus`}}",
			"memory": "{{user `memory`}}",
			"headless": ${OPACK_SYS_HEADLESS},
			"boot_key_interval": "10ms",
			"disk_size": "{{user `disk_size`}}",
			"disk_interface": "virtio",
			"disk_compression": true,
			"http_directory": "./http",
			"iso_urls": "${OPACK_SYS_ISO_URL}",
			"iso_checksum": "sha256:${OPACK_SYS_ISO_SHA256SUM}",
			"net_device": "virtio-net",
			"communicator": "ssh",
			"ssh_username": "root",
			"ssh_private_key_file": "vagrant.key",
			"ssh_wait_timeout": "60m",
			"shutdown_command": "shutdown -p now",
			"boot_wait": "30s",
			"boot_command": [ "S<enter><wait>",
				"# ~~~ OPACK - OpenBSD Packing ~~~~<enter>",
				"# ${OPACK_COMMIT} <enter>",
				$(if $(filter-out snapshots 7.0 7.1, ${OPACK_SYS_VERSION}),"dhclient vio0 ","ifconfig vio0 inet autoconf "),
				"& sleep 1 && wait && ftp http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.conf && ftp http://{{ .HTTPIP }}:{{ .HTTPPort }}/autodisklabel && install -af install.conf && echo permit nopass :wheel > /mnt/etc/doas.conf && ",
				$(if $(filter-out snapshots 7.0 7.1, ${OPACK_SYS_VERSION}),"echo dhcp > /mnt/etc/hostname.vio0 && echo http://${OPACK_SYS_SERVER}/pub/OpenBSD/ > /mnt/etc/installurl ","echo inet autoconf > /mnt/etc/hostname.vio0 && echo PubkeyAcceptedAlgorithms +ssh-rsa >> /mnt/etc/ssh/sshd_config "),
				"&& reboot<enter>" ]
		} ],
		"provisioners": [ 
		{
			"type": "shell",
			"scripts": ["../../provision-openbsd.sh"]
    		}
		],
		"post-processors": [ [
				{	"name": "vagrant",
					"type": "vagrant",
					"compression_level": 9,
					"output": "../${OPACK_BOX_FILE}" }
		] ]
}
endef

define OPACK_PACKER_CLOUD_CONTENT =
{
	"description": "OpenBSD ${OPACK_SYS_VERSION} ${OPACK_SYS_ARCHITECTURE} cloud",
		"variables": {
			"box_tag": "${OPACK_SYS_HOSTNAME}-${OPACK_TARGET}-{{ timestamp }}",
			"disk_size": "${OPACK_SYS_DISK_SIZE}",
			"memory": "${OPACK_SYS_MEMORY}",
			"cpus": "${OPACK_SYS_CPU}",
			"gcloud_account_json": "../../${GCE_JSON_KEY}",
			"gcloud_project_id": "${GCE_PROJECT}",
			"version": "${OPACK_BOX_VERSION}" },
		"builders": [ {
			"type": "qemu",
			"format": "raw",
			"vm_name": "disk.raw",
			"cpus": "{{user `cpus`}}",
			"memory": "{{user `memory`}}",
			"headless": ${OPACK_SYS_HEADLESS},
			"boot_key_interval": "10ms",
			"disk_size": "{{user `disk_size`}}",
			"disk_interface": "virtio",
			"disk_compression": true,
			"http_directory": "./http",
			"iso_urls": "${OPACK_SYS_ISO_URL}",
			"iso_checksum": "sha256:${OPACK_SYS_ISO_SHA256SUM}",
			"net_device": "virtio-net",
			"communicator": "ssh",
			"ssh_username": "root",
			"ssh_private_key_file": "${OPACK_SYS_SSH_PRIVATE_KEY}",
			"ssh_wait_timeout": "60m",
			"shutdown_command": "shutdown -p now",
			"boot_wait": "30s",
			"boot_command": [ "S<enter><wait>",
				"# ~~~ OPACK - OpenBSD Packing ~~~~<enter>",
				"# ${OPACK_COMMIT} <enter>",
				$(if $(filter-out snapshots 7.0 7.1, ${OPACK_SYS_VERSION}),"dhclient vio0 ","ifconfig vio0 inet autoconf "),
				"& sleep 1 && wait && ftp http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.conf && ftp http://{{ .HTTPIP }}:{{ .HTTPPort }}/autodisklabel && install -af install.conf && echo permit nopass :wheel > /mnt/etc/doas.conf && ",
				$(if $(filter-out snapshots 7.0 7.1, ${OPACK_SYS_VERSION}),"echo dhcp > /mnt/etc/hostname.vio0 && echo http://${OPACK_SYS_SERVER}/pub/OpenBSD/ > /mnt/etc/installurl ","echo inet autoconf > /mnt/etc/hostname.vio0 && echo PubkeyAcceptedAlgorithms +ssh-rsa >> /mnt/etc/ssh/sshd_config "),
				"&& reboot<enter>" ]
		} ],
		"provisioners": [ 
			{
				"type": "file",
				"source": "$(PROTECME_TOP_DIR)/src",
				"destination": "/root/magma"
			},
			{
				"type": "file",
				"source": "$(PROTECME_SPEC_DIR)/openbsd",
				"destination": "/var/spec2006src"
			},
			{
				"type": "shell",
				"scripts": ["../../provision-openbsd.sh"]
    			}
		],
		"post-processors": [ [
				{	"name": "Compress",
					"type": "compress",
					"compression_level": 9,
					"output": "disk.raw.tar.gz"
				},
				{	"name": "GCP Import",
					"type": "googlecompute-import",
					"project_id": "{{user `gcloud_project_id`}}",
					"account_file": "{{user `gcloud_account_json`}}",
					"bucket": "${GCE_BUCKET}",
					"image_name": "${OPACK_TARGET}",
					"image_description": "${OPACK_COMMIT}",
					"image_family": "openbsd",
					"keep_input_artifact": true
				}
		] ]
}
endef


define OPACK_INSTALL_CONTENT =
Choose your keyboard layout = fr
System hostname = ${OPACK_SYS_HOSTNAME}-${OPACK_TARGET}
Which network interface = vio0
IPv4 address for vio0 = dhcp
IPv6 address for vio0 = none
Password for root account = ${OPACK_SYS_PASSWORD}
Public ssh key for root account = ${OPACK_SYS_SSH_KEY}
Allow root ssh login = prohibit-password
Do you expect to run the X Window System = ${OPACK_SYS_XENOCARA}
Setup a user = ${OPACK_SYS_USER}
Password for user ${OPACK_SYS_USER} = ${OPACK_SYS_PASSWORD}
Public ssh key for ${OPACK_SYS_USER} = ${OPACK_SYS_SSH_KEY}
Allow root ssh login = prohibit-password
What timezone = ${OPACK_SYS_TIMEZONE}
Which disk = sd0
Use (W)hole disk or (E)dit the MBR = whole
URL to autopartitioning template for disklabel = file:/autodisklabel
Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout = A
Location of sets = ${OPACK_SYS_SETS_LOCATION}
HTTP Server = ${OPACK_SYS_SERVER}
Server directory = pub/OpenBSD/${OPACK_SYS_VERSION}/${OPACK_SYS_ARCHITECTURE}
Unable to connect using https. Use http instead = yes
#Pathname to the sets = ${OPACK_SYS_VERSION_NUMBER}/amd64
Set name(s) = ${OPACK_SYS_SETS} done
Directory does not contain SHA256.sig. Continue without verification = ${OPACK_NO_SIGCHK}
Signature check of SHA256.sig failed. Continue without verification = no
Cannot determine prefetch area. Continue without verification = yes
Location of sets? = done

endef

define OPACK_METADATA_CONTENT =
{
  "name": "${OPACK_BOX_TAG}",
  "description": "OPACK - $(OPACK_COMMIT)",
  "versions": [
    {
      "version": "${OPACK_BOX_VERSION}",
      "providers": [
        {
          "name": "libvirt",
          "url": "${OPACK_BOX_FILE}",
          "checksum_type": "sha256",
          "checksum": "${OPACK_BOX_FILE_SHA256}"
        }
      ]
    }
  ]
}

endef
