From e532c6ee9c3767334181094cd40b55a3310fac33 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Fri, 28 Aug 2026 09:32:04 +0200 Subject: [PATCH] feat(kit): restore data and store credentials --- build-sbx.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/build-sbx.sh b/build-sbx.sh index 8096271..c08c616 100755 --- a/build-sbx.sh +++ b/build-sbx.sh @@ -164,6 +164,43 @@ main() { printf 'Unable to create Docker sbx image: %s\n' "$new_sandbox_name" >&2 exit 1 fi + + local tmp='' api_key + if [[ "$build_from_scratch" == false ]]; then + tmp=$(mktemp -d) || { + printf 'Unable to create a temporary directory.\n' >&2 + exit 1 + } + trap 'rm -rf "${tmp:?}"' EXIT + + if ! sbx cp "${selected_sandbox}:/home/agent/.local" "$tmp"; then + printf 'Unable to copy /home/agent/.local from Docker sbx image: %s\n' \ + "$selected_sandbox" >&2 + exit 1 + fi + + if ! sbx cp "$tmp/.local" "${new_sandbox_name}:/home/agent/"; then + printf 'Unable to copy the temporary .local directory into Docker sbx image: %s\n' \ + "$new_sandbox_name" >&2 + exit 1 + fi + fi + + if ! read -rsp 'HYPOPORT_API_KEY: ' api_key; then + printf '\nUnable to read the HYPOPORT_API_KEY.\n' >&2 + exit 1 + fi + printf '\n' + + if ! printf '%s\n' "$api_key" | + sbx exec "$new_sandbox_name" bash -c \ + 'umask 077; read -r api_key; printf "export HYPOPORT_API_KEY=%q\n" "$api_key" > /etc/sandbox-persistent.sh'; then + unset api_key + printf 'Unable to store the HYPOPORT_API_KEY in Docker sbx image: %s\n' \ + "$new_sandbox_name" >&2 + exit 1 + fi + unset api_key } main "$@"