From 256dc91794ad239c4d1554590cc4008b8daae47c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 16 Dec 2009 21:17:00 -0500 Subject: add ec2-is-compat-env as it is in lucid/karmic now --- ec2-is-compat-env | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 ec2-is-compat-env diff --git a/ec2-is-compat-env b/ec2-is-compat-env new file mode 100644 index 00000000..07034670 --- /dev/null +++ b/ec2-is-compat-env @@ -0,0 +1,78 @@ +#!/bin/sh +# vi: ts=4 noexpandtab syntax=sh + +ETC_CONFIG=/etc/ec2-init/is-compat-env +CONFIG_ACTIVE_VAR="compat" +CMDLINE_EC2_COMPAT=ec2init +CR=" +" +VERBOSE=1 +META_DATA_URL=http://169.254.169.254/2009-04-04 +check_md=0 + +Usage() { + cat <&2; exit 2;; + esac + shift; +done + +if [ ${check_md} -ne 0 ]; then + # if we are to check for meta data service + # then check first that there was something there. + index=$(wget --connect-timeout=2 --tries 2 -O - -q "${META_DATA_URL}") || + xit 1 + + # exit true if content of url a line with 'meta-data' at start + [ "${index#*${CR}meta-data}" = "${index}" ] || xit 0 + xit 1 +fi + +# if /proc/cmdline exists and has certain tokens, trust them +# even before looking at config file +if [ -e /proc/cmdline ] && read cmdline < /proc/cmdline; then + # if cmdline has certain tokens in it, trust them + case " ${cmdline} " in + *\ ${CMDLINE_EC2_COMPAT}=1\ ) xit 0;; + *\ ${CMDLINE_EC2_COMPAT}=0\ ) xit 1;; + esac +fi + +# if the config file exists and has a non-empty value set for +# CONFIG_ACTIVE_VAR trust it as definitive source. If no value is set +# fall through +if [ -e "${ETC_CONFIG}" ] && + active=$(sh -c "unset ${CONFIG_ACTIVE_VAR}; + . '${ETC_CONFIG}'; echo \${${CONFIG_ACTIVE_VAR}}") && + [ -n "${active}" ]; then + [ "$active" = "1" ] && xit 0 + xit 1 +fi + +xit 1 -- cgit v1.2.3