feat(kit): restore data and store credentials
This commit is contained in:
37
build-sbx.sh
37
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 "$@"
|
||||
|
||||
Reference in New Issue
Block a user