Skip to content

Instantly share code, notes, and snippets.

@technmsg
Created July 24, 2017 20:19
Show Gist options
  • Save technmsg/76e43ecdf098941c57d638655706cb69 to your computer and use it in GitHub Desktop.
Save technmsg/76e43ecdf098941c57d638655706cb69 to your computer and use it in GitHub Desktop.
detect cloud platform
#!/bin/bash
#
# detect cloud platform and query for instance type
#
platform='unknown'
instance_type="unknown"
# AWS EC2
if [ -f /sys/hypervisor/uuid ] ; then
instance_uuid=$(cat /sys/hypervisor/uuid)
if [[ $instance_uuid == ec2* ]] ; then
platform='ec2'
instance_type=$(curl -s http://169.254.169.254/latest/meta-data/instance-type)
fi
fi
# GCP GCE
dmesg | grep -q "BIOS Google"
if [ $? -eq 0 ] ; then
platform='gce'
instance_type=$(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/machine-type" -H "Metadata-Flavor: Google" | cut -d/ -f4)
fi
echo "PLATFORM: $platform"
echo "INSTANCE: $instance_type"
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment