diff --git a/scripts/remote-provision.sh b/scripts/remote-provision.sh new file mode 100644 index 00000000..f0c5cac2 --- /dev/null +++ b/scripts/remote-provision.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +set -o errexit # abort on nonzero exit status +set -o errtrace # pass ERR trap down to functions, substitutions, etc +set -o nounset # abort on unbound variable +set -o pipefail # don’t hide errors within pipes + +[[ "${BASH_VERSINFO:-0}" -ge 4 ]] || { echo "Bash version 4 or higher is required."; exit 1; } + +usage() { + echo "Usage $0 [OPTIONS] + + Options: + -r, --reprovision Re-provisioning the device and skips fetching of attestation certificate + -t, --plug-trust Path for plug_and_trust.tar.gz on the host (required for prod images) + -p, --passphrase Expected to be used with IPv4 (required for dev images with ssh access)" +} + +setup_plug_and_trust() { + local remote="${1}" + local plug_trust="${2}" + local ssh_prefix="${3}" + + if ${ssh_prefix} ssh "worldcoin@${remote}" '! [[ -d /service_mode ]]'; then + # NOTE: The following case, should only be met in production images, where tsh + # is the only available option for remote access. SOON will be deprecated + if [[ -n "${plug_trust}" ]]; then + ${ssh_prefix} scp "${plug_trust}" "root@${remote}:/tmp/plug_and_trust.tar.gz" + ${ssh_prefix} ssh "root@${remote}" <