#!/bin/sh -eux
set -o pipefail

pkg upgrade -yr FreeBSD
pkg install -Uyr FreeBSD devel/git@lite ftp/curl textproc/jq

# https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/gettingmetadata.htm
curl --fail -H "Authorization: Bearer Oracle" -s \
  http://169.254.169.254/opc/v2/instance \
  | jq . > /var/run/oci.json

export GIT_REPO=$(jq -r .freeformTags.GIT_REPO /var/run/oci.json)
export GIT_BRANCH=$(jq -r .freeformTags.GIT_BRANCH /var/run/oci.json)
export GIT_RUNNER=$(jq -r .freeformTags.GIT_RUNNER /var/run/oci.json)

git clone --branch ${GIT_BRANCH} ${GIT_REPO} /var/run/diy
cd /var/run/diy
sh ./${GIT_RUNNER}
