Created
July 24, 2017 20:19
-
-
Save technmsg/76e43ecdf098941c57d638655706cb69 to your computer and use it in GitHub Desktop.
detect cloud platform
This file contains hidden or 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 | |
# | |
# 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