Skip to content

Instantly share code, notes, and snippets.

@johnybradshaw
Created November 22, 2023 10:40
Show Gist options
  • Save johnybradshaw/e0d8ecc40e53ffc42a6d1a91efdacc6c to your computer and use it in GitHub Desktop.
Save johnybradshaw/e0d8ecc40e53ffc42a6d1a91efdacc6c to your computer and use it in GitHub Desktop.
Automatically set the hostname for Akamai Connect Cloud instances
#!/bin/bash
################################################################################################
# Usage #
################################################################################################
# Ensure a tag is created in the form: "tld: yourdomain.com" and applied to the Linode
# Add this to /usr/bin/local/acc-set-hostname.sh
# Call this file during the cloud-init <runcmd> block
################################################################################################
METADATA_TOKEN="$(curl -s -X PUT -H 'Metadata-Token-Expiry-Seconds: 3600' 'http://169.254.169.254/v1/token')"
METADATA_URL="http://169.254.169.254/v1/instance"
METADATA=$(curl -s -H "Metadata-Token: $METADATA_TOKEN" "$METADATA_URL")
LABEL=$(echo "$METADATA" | awk '/^label:/ {print $2}')
TLD=$(echo "$METADATA" | awk '/^tags: tld:/ {print $3}')
hostnamectl hostname "$LABEL.$TLD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment