Created
November 22, 2023 10:40
-
-
Save johnybradshaw/e0d8ecc40e53ffc42a6d1a91efdacc6c to your computer and use it in GitHub Desktop.
Automatically set the hostname for Akamai Connect Cloud instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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