diff --git a/binarylane/lib/common.sh b/binarylane/lib/common.sh index 93585d77..c1c97bbe 100644 --- a/binarylane/lib/common.sh +++ b/binarylane/lib/common.sh @@ -72,9 +72,10 @@ binarylane_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"public_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"public_key\":$json_pub_key}" local register_response register_response=$(binarylane_api POST "/account/keys" "$register_body") diff --git a/cherry/lib/common.sh b/cherry/lib/common.sh index ae86cbc8..a1a13409 100755 --- a/cherry/lib/common.sh +++ b/cherry/lib/common.sh @@ -87,9 +87,10 @@ cherry_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"label\":\"$key_name\",\"key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"label\":$json_name,\"key\":$json_pub_key}" local register_response register_response=$(cherry_api POST "/ssh-keys" "$register_body") diff --git a/civo/lib/common.sh b/civo/lib/common.sh index 483848e8..ee0fa599 100644 --- a/civo/lib/common.sh +++ b/civo/lib/common.sh @@ -64,9 +64,10 @@ civo_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"public_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"public_key\":$json_pub_key}" local register_response register_response=$(civo_api POST "/sshkeys" "$register_body") diff --git a/contabo/lib/common.sh b/contabo/lib/common.sh index 237b97aa..49472dc3 100644 --- a/contabo/lib/common.sh +++ b/contabo/lib/common.sh @@ -111,9 +111,10 @@ contabo_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"type\":\"ssh\",\"value\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"type\":\"ssh\",\"value\":$json_pub_key}" local register_response register_response=$(contabo_api POST "/compute/secrets" "$register_body") diff --git a/digitalocean/lib/common.sh b/digitalocean/lib/common.sh index 77387959..63b84f0d 100755 --- a/digitalocean/lib/common.sh +++ b/digitalocean/lib/common.sh @@ -74,9 +74,10 @@ do_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"public_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"public_key\":$json_pub_key}" local register_response register_response=$(do_api POST "/account/keys" "$register_body") diff --git a/gcp/lib/common.sh b/gcp/lib/common.sh index 5e3f3225..37f40ed8 100644 --- a/gcp/lib/common.sh +++ b/gcp/lib/common.sh @@ -108,11 +108,15 @@ create_server() { log_step "Creating GCP instance '${name}' (type: ${machine_type}, zone: ${zone})..." - local userdata - userdata=$(get_cloud_init_userdata) local pub_key pub_key=$(cat "${HOME}/.ssh/id_ed25519.pub") + # Write startup script to a temp file to avoid --metadata comma delimiter issues + local startup_script_file + startup_script_file=$(mktemp) + track_temp_file "${startup_script_file}" + get_cloud_init_userdata > "${startup_script_file}" + local gcloud_err gcloud_err=$(mktemp) track_temp_file "${gcloud_err}" @@ -122,7 +126,8 @@ create_server() { --machine-type="${machine_type}" \ --image-family="${image_family}" \ --image-project="${image_project}" \ - --metadata="startup-script=${userdata},ssh-keys=${GCP_USERNAME}:${pub_key}" \ + --metadata-from-file="startup-script=${startup_script_file}" \ + --metadata="ssh-keys=${GCP_USERNAME}:${pub_key}" \ --project="${GCP_PROJECT}" \ --quiet \ >/dev/null 2>"${gcloud_err}"; then diff --git a/genesiscloud/lib/common.sh b/genesiscloud/lib/common.sh index 13df1ffa..8e069a17 100644 --- a/genesiscloud/lib/common.sh +++ b/genesiscloud/lib/common.sh @@ -72,9 +72,10 @@ genesis_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"value\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"value\":$json_pub_key}" local register_response register_response=$(genesis_api POST "/ssh-keys" "$register_body") diff --git a/hetzner/lib/common.sh b/hetzner/lib/common.sh index 85c146ce..3ef0333d 100755 --- a/hetzner/lib/common.sh +++ b/hetzner/lib/common.sh @@ -68,9 +68,10 @@ hetzner_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"public_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"public_key\":$json_pub_key}" local register_response register_response=$(hetzner_api POST "/ssh_keys" "$register_body") diff --git a/hostinger/lib/common.sh b/hostinger/lib/common.sh index 574707e7..579cd49a 100644 --- a/hostinger/lib/common.sh +++ b/hostinger/lib/common.sh @@ -74,9 +74,10 @@ hostinger_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"public_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"public_key\":$json_pub_key}" local register_response register_response=$(hostinger_api POST "/ssh-keys" "$register_body") diff --git a/hostkey/lib/common.sh b/hostkey/lib/common.sh index 1e1d8d7b..3aa3b4fe 100644 --- a/hostkey/lib/common.sh +++ b/hostkey/lib/common.sh @@ -79,10 +79,11 @@ hostkey_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") + json_name=$(json_escape "$key_name") - local register_body="{\"name\":\"$key_name\",\"public_key\":$json_pub_key}" + local register_body="{\"name\":$json_name,\"public_key\":$json_pub_key}" local register_response register_response=$(hostkey_api POST "/ssh_keys" "$register_body") @@ -243,7 +244,9 @@ destroy_server() { log_step "Destroying instance $instance_id..." local response - response=$(hostkey_api POST "/eq/terminate" "{\"id\":\"$instance_id\"}") + local json_id + json_id=$(json_escape "$instance_id") + response=$(hostkey_api POST "/eq/terminate" "{\"id\":$json_id}") if echo "$response" | grep -qi "error"; then log_error "Failed to destroy instance: $response" diff --git a/linode/lib/common.sh b/linode/lib/common.sh index f4eea909..9fe02319 100644 --- a/linode/lib/common.sh +++ b/linode/lib/common.sh @@ -71,9 +71,10 @@ linode_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"label\":\"$key_name\",\"ssh_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"label\":$json_name,\"ssh_key\":$json_pub_key}" local register_response register_response=$(linode_api POST "/profile/sshkeys" "$register_body") diff --git a/vultr/lib/common.sh b/vultr/lib/common.sh index 5a466399..2d8c972d 100755 --- a/vultr/lib/common.sh +++ b/vultr/lib/common.sh @@ -71,9 +71,10 @@ vultr_register_ssh_key() { local pub_path="$2" local pub_key pub_key=$(cat "$pub_path") - local json_pub_key + local json_pub_key json_name json_pub_key=$(json_escape "$pub_key") - local register_body="{\"name\":\"$key_name\",\"ssh_key\":$json_pub_key}" + json_name=$(json_escape "$key_name") + local register_body="{\"name\":$json_name,\"ssh_key\":$json_pub_key}" local register_response register_response=$(vultr_api POST "/ssh-keys" "$register_body")