diff --git a/scripts/remote-provision.sh b/scripts/remote-provision.sh new file mode 100755 index 0000000..46a1e4e --- /dev/null +++ b/scripts/remote-provision.sh @@ -0,0 +1,144 @@ +#!/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: + -h, --help Print help + -r, --reprovision Re-provisioning the device and skips fetching of attestation certificate + -p, --passphrase Expected to be used with IPv4 (required for dev images with ssh access) + -t, --plug-trust Path for plug_and_trust.tar.gz on the host (required for prod images). + Check the worldcoin/plug-and-trust/releases for the appropriate version + based on the device's software release + -y, --assumeyes automatically answer yes for all questions + + Example: + $0 -r -t ~/Downloads/plug_and_trust.tar.gz " +} + +provision_device() { + local remote="${1}" + local reprovision="${2}" + local ssh_prefix="${3}" + local plug_trust="${4}" + local interactive="${5}" + + local user="worldcoin" + local se_dir="/usr/persistent/se" + local key_dir="${se_dir}/keystore" + if [[ "${ssh_prefix}" == "tsh" ]]; then + user="root" + fi + + # If /se/keystore is not present, provisioning process was never executed, or keystore was wiped + # In this case, reprovisioniong is not allowed for fear of wiping the attestation certificate + if [[ ${reprovision} ]]; then + if [[ ${interactive} ]]; then + read -p "Reprovisioning will wipe all provisioning material, continue? [y/N] " -n 1 -r + echo + if [[ ! ${REPLY} =~ ^[Yy]$ ]]; then + echo "Reprovisioning aborted" + exit 0 + fi + fi + ${ssh_prefix} ssh "${user}@${remote}" bash --noprofile --norc < /dev/null 2>&1; then + if [[ -n "${plug_trust}" ]]; then + ${ssh_prefix} scp "${plug_trust}" worldcoin@"${remote}:/tmp/plug_and_trust.tar.gz" + ${ssh_prefix} ssh worldcoin@"${remote}" bash --noprofile --norc <