Skip to content

Instantly share code, notes, and snippets.

@TomMalbran
Last active August 29, 2015 14:16
Show Gist options
  • Save TomMalbran/15c843650c1dc9019622 to your computer and use it in GitHub Desktop.
Save TomMalbran/15c843650c1dc9019622 to your computer and use it in GitHub Desktop.
DigitalOcean Bash Script
#!/bin/bash
export IP=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
export HOSTNAME=$(curl -s http://169.254.169.254/metadata/v1/hostname)
export LAST=${IP##*.}
HOSTNAME=${HOSTNAME/XXX/$LAST}
export HOST=${HOSTNAME%%.*}
export DOMAIN=${HOSTNAME/$HOST./}
sed -i "/HOSTNAME/c\HOSTNAME=${HOSTNAME}" /etc/sysconfig/network
sed -i "/127.0.0.1/a ${IP}\t${HOST}\t${HOSTNAME}\t${DOMAIN}" /etc/hosts
#cloud-config
output: {all: '| tee -a /var/log/cloud-init-output.log'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment