Last active
January 3, 2016 21:59
-
-
Save DBLaw/8524787 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| set -o pipefail | |
| ## | |
| ### Copyright 2011-2013, Boundary | |
| ### | |
| ### Licensed under the Apache License, Version 2.0 (the "License"); | |
| ### you may not use this file except in compliance with the License. | |
| ### You may obtain a copy of the License at | |
| ### | |
| ### http://www.apache.org/licenses/LICENSE-2.0 | |
| ### | |
| ### Unless required by applicable law or agreed to in writing, software | |
| ### distributed under the License is distributed on an "AS IS" BASIS, | |
| ### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| ### See the License for the specific language governing permissions and | |
| ### limitations under the License. | |
| ### | |
| PLATFORMS=("Ubuntu" "Debian" "CentOS" "Amazon" "RHEL" "SmartOS") | |
| # Put additional version numbers here. | |
| # These variables take the form ${platform}_VERSIONS, where $platform matches | |
| # the tags in $PLATFORMS | |
| Ubuntu_VERSIONS=("10.04" "10.10" "11.04" "11.10" "12.04" "12.10" "13.04" "13.10") | |
| Debian_VERSIONS=("5" "6" "7") | |
| CentOS_VERSIONS=("5" "6") | |
| Amazon_VERSIONS=("2012.09" "2013.03") | |
| RHEL_VERSIONS=("5" "6") | |
| SmartOS_VERSIONS=("1" "12" "13") | |
| # sed strips out obvious things in a version number that can't be used as | |
| # a bash variable | |
| function map() { eval "$1"`echo $2 | sed 's/[\. -]//g'`='$3' ; } | |
| function get() { eval echo '${'"$1`echo $2 | sed 's/[\. -]//g'`"'#hash}' ; } | |
| # Map distributions to common strings. | |
| map Ubuntu 10.04 lucid | |
| map Ubuntu 10.10 maverick | |
| map Ubuntu 11.04 natty | |
| map Ubuntu 11.10 oneiric | |
| map Ubuntu 12.04 precise | |
| map Ubuntu 12.10 quantal | |
| map Ubuntu 13.04 raring | |
| map Ubuntu 13.10 saucy | |
| map Debian 5 lenny | |
| map Debian 6 squeeze | |
| map Debian 7 wheezy | |
| map RHEL 5 Tikanga | |
| map RHEL 6 Santiago | |
| # For version number updates you hopefully don't need to modify below this line | |
| # ----------------------------------------------------------------------------- | |
| APIHOST="api.boundary.com" | |
| TARGET_DIR="/etc/bprobe" | |
| EC2_INTERNAL="http://169.254.169.254/latest/meta-data" | |
| TAGS="instance-type placement/availability-zone" | |
| SUPPORTED_ARCH=0 | |
| SUPPORTED_PLATFORM=0 | |
| APT="apt.boundary.com" | |
| YUM="yum.boundary.com" | |
| SMARTOS="smartos.boundary.com" | |
| APT_CMD="apt-get -q -y --force-yes" | |
| YUM_CMD="yum -d0 -e0 -y" | |
| DEPS="false" | |
| STAGING="false" | |
| CACERTS= | |
| # forked - hostname mod for AWS begin | |
| export HOSTNAME=`ec2-describe-tags --filter "resource-id=\`curl -s http://169.254.169.254/latest/meta-data/instance-id\`" | grep Name | sed 's/[ \t]/ /g' | cut -d " " -f 5-` | |
| # forked - hostname mode for AWS end | |
| trap "exit" INT TERM EXIT | |
| function print_supported_platforms() { | |
| echo "Supported platforms are:" | |
| for d in ${PLATFORMS[*]} | |
| do | |
| echo -n " * $d:" | |
| foo="\${${d}_VERSIONS[*]}" | |
| versions=`eval echo $foo` | |
| for v in $versions | |
| do | |
| echo -n " $v" | |
| done | |
| echo "" | |
| done | |
| } | |
| function check_distro_version() { | |
| PLATFORM=$1 | |
| DISTRO=$2 | |
| VERSION=$3 | |
| TEMP="\${${DISTRO}_versions[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| if [ $DISTRO = "Ubuntu" ]; then | |
| MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'` | |
| MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'` | |
| PATCH_VERSION=`echo $VERSION | awk -F. '{print $3}'` | |
| TEMP="\${${DISTRO}_VERSIONS[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| for v in $VERSIONS ; do | |
| if [ "$MAJOR_VERSION.$MINOR_VERSION" = "$v" ]; then | |
| return 0 | |
| fi | |
| done | |
| elif [ $DISTRO = "CentOS" ] || [ $DISTRO = "RHEL" ]; then | |
| MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'` | |
| MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'` | |
| TEMP="\${${DISTRO}_VERSIONS[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| for v in $VERSIONS ; do | |
| if [ "$MAJOR_VERSION" = "$v" ]; then | |
| return 0 | |
| fi | |
| done | |
| elif [ $DISTRO = "Amazon" ]; then | |
| VERSION=`echo $PLATFORM | awk '{print $5}'` | |
| # Some of these include minor numbers. Trim. | |
| VERSION=${VERSION:0:7} | |
| TEMP="\${${DISTRO}_VERSIONS[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| for v in $VERSIONS ; do | |
| if [ "$VERSION" = "$v" ]; then | |
| return 0 | |
| fi | |
| done | |
| elif [ $DISTRO = "Debian" ]; then | |
| MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'` | |
| MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'` | |
| TEMP="\${${DISTRO}_VERSIONS[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| for v in $VERSIONS ; do | |
| if [ "$MAJOR_VERSION" = "$v" ]; then | |
| return 0 | |
| fi | |
| done | |
| elif [ $DISTRO = "SmartOS" ]; then | |
| # SmartOS does not have version numbers | |
| TEMP="\${${DISTRO}_VERSIONS[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| for v in $VERSIONS ; do | |
| if [ "$VERSION" = "$v" ]; then | |
| return 0 | |
| fi | |
| done | |
| fi | |
| echo "Detected $DISTRO but with an unsupported version ($VERSION)" | |
| return 1 | |
| } | |
| function print_help() { | |
| echo " $0 [-d] -i ORGID:APIKEY" | |
| echo " -i: Required input for authentication. The ORGID and APIKEY can be found" | |
| echo " in the Account Settings in the Boundary WebUI." | |
| echo " -d: Optional flag to install all dependencies, such as curl and" | |
| echo " apt-transport-https, required for Meter Install." | |
| exit 0 | |
| } | |
| function create_meter() { | |
| if [ "${HOSTNAME}" = "" ]; then | |
| echo "Host does not appear to have a hostname set!" | |
| echo "For assistance, please contain [email protected]" | |
| exit 1 | |
| fi | |
| RESULT=`$CURL --connect-timeout 5 -i -s -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -d "{\"name\": \"$HOSTNAME\"}" -u "$1:" \ | |
| https://$APIHOST/$2/meters \ | |
| | tr -d "\r" \ | |
| | awk '/^HTTP\/1\./ {split($0,a," "); http=a[2]} /^Location: https:\/\// {split($0,a," "); url=a[2]} END {print http; print url}'` | |
| exit_status=$? | |
| # an exit status of 1 indicates an unsupported protocol. (e.g., | |
| # https hasn't been baked in.) | |
| if [ "$exit_status" -eq "1" ]; then | |
| echo "Your local version of curl has not been built with HTTPS support: `which curl`" | |
| exit 1 | |
| elif [ "$exit_status" -eq "6" ]; then | |
| echo "Could not resolve $APIHOST, check network connectivity or DNS settings" | |
| exit 1 | |
| # if the exit code is 7, that means curl couldnt connect so we can bail | |
| elif [ "$exit_status" -eq "7" ]; then | |
| echo "Could not connect to create meter" | |
| exit 1 | |
| # it appears that an exit code of 28 is also a can't connect error | |
| elif [ "$exit_status" -eq "28" ]; then | |
| echo "Could not connect to create meter" | |
| exit 1 | |
| elif [ "$exit_status" -ne "0" ]; then | |
| echo "Error connecting to $APIHOST; status $exit_status." | |
| exit 1 | |
| fi | |
| STATUS=`echo $RESULT | awk '{print $1}'` | |
| if [ "$STATUS" = "" ]; then | |
| echo "Unknown error communicating with $APIHOST." | |
| exit 1 | |
| elif [ "$STATUS" = "401" ]; then | |
| echo "Authentication error, bad Org ID or API key (http status $STATUS)." | |
| echo "Verify that you have passed in the correct credentials. The ORGID and APIKEY" | |
| echo "can be found in the Account Settings in the Boundary WebUI." | |
| exit 1 | |
| elif [ "$STATUS" = "403" ]; then | |
| echo "Forbidden error (http status $STATUS)." | |
| echo "Verify that you have not exceeded your meter limit." | |
| echo "If you haven't, please contact support at [email protected]." | |
| exit 1 | |
| else | |
| if [ "$STATUS" = "201" ] || [ "$STATUS" = "409" ]; then | |
| echo $RESULT | awk '{print $2}' | |
| else | |
| echo "An Error occurred during the meter creation (http status $STATUS)." | |
| echo "Please contact support at [email protected]." | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| function do_install() { | |
| if [ "$DISTRO" = "Ubuntu" ]; then | |
| echo "Updating apt repository cache..." | |
| sudo $APT_CMD update > /dev/null | |
| APT_STRING="deb https://${APT}/ubuntu/ `get $DISTRO $MAJOR_VERSION.$MINOR_VERSION` universe" | |
| echo "Adding repository $APT_STRING" | |
| sudo sh -c "echo \"$APT_STRING\" > /etc/apt/sources.list.d/boundary.list" | |
| $CURL -s https://${APT}/APT-GPG-KEY-Boundary | sudo apt-key add - | |
| if [ $? -gt 0 ]; then | |
| echo "Error downloading GPG key from https://${APT}/APT-GPG-KEY-Boundary!" | |
| exit 1 | |
| fi | |
| echo "Updating apt repository cache..." | |
| sudo $APT_CMD update > /dev/null | |
| sudo $APT_CMD install bprobe | |
| return $? | |
| elif [ "$DISTRO" = "Debian" ]; then | |
| echo "Updating apt repository cache..." | |
| sudo $APT_CMD update > /dev/null | |
| APT_STRING="deb https://${APT}/debian/ `get $DISTRO $MAJOR_VERSION` main" | |
| echo "Adding repository $APT_STRING" | |
| sudo sh -c "echo \"$APT_STRING\" > /etc/apt/sources.list.d/boundary.list" | |
| $CURL -s https://${APT}/APT-GPG-KEY-Boundary | sudo apt-key add - | |
| if [ $? -gt 0 ]; then | |
| echo "Error downloading GPG key from https://${APT}/APT-GPG-KEY-Boundary!" | |
| exit 1 | |
| fi | |
| echo "Updating apt repository cache..." | |
| sudo $APT_CMD update > /dev/null | |
| sudo $APT_CMD install bprobe | |
| return $? | |
| elif [ "$DISTRO" = "CentOS" ] || [ $DISTRO = "Amazon" ] || [ $DISTRO = "RHEL" ]; then | |
| GPG_KEY_LOCATION=/etc/pki/rpm-gpg/RPM-GPG-KEY-Boundary | |
| if [ $MACHINE = "i686" ]; then | |
| ARCH_STR="i386/" | |
| elif [ $MACHINE = "x86_64" ]; then | |
| ARCH_STR="x86_64/" | |
| fi | |
| # Amazon hack: we know the Amazon Linux AMIs are binary | |
| # compatible with CentOS | |
| if [ $DISTRO = "Amazon" ]; then | |
| MAJOR_VERSION=6 | |
| fi | |
| echo "Adding repository http://${YUM}/centos/os/$MAJOR_VERSION/$ARCH_STR" | |
| sudo sh -c "cat - > /etc/yum.repos.d/boundary.repo <<EOF | |
| [boundary] | |
| name=boundary | |
| baseurl=http://${YUM}/centos/os/$MAJOR_VERSION/$ARCH_STR | |
| gpgcheck=1 | |
| gpgkey=file://$GPG_KEY_LOCATION | |
| enabled=1 | |
| EOF" | |
| $CURL -s https://$YUM/RPM-GPG-KEY-Boundary | sudo tee /etc/pki/rpm-gpg/RPM-GPG-KEY-Boundary > /dev/null | |
| if [ $? -gt 0 ]; then | |
| echo "Error downloading GPG key from https://$YUM/RPM-GPG-KEY-Boundary!" | |
| exit 1 | |
| fi | |
| sudo $YUM_CMD install bprobe | |
| return $? | |
| elif [ "$DISTRO" = "SmartOS" ]; then | |
| grep "http://${SMARTOS}/${MACHINE}" /opt/local/etc/pkgin/repositories.conf > /dev/null | |
| if [ "$?" = "1" ]; then | |
| echo "http://${SMARTOS}/${MACHINE}/" >> /opt/local/etc/pkgin/repositories.conf | |
| fi | |
| pkgin -fy up | |
| pkgin -y install bprobe | |
| svccfg import /opt/custom/smf/boundary-meter.xml | |
| svcadm enable boundary/meter | |
| return $? | |
| fi | |
| } | |
| function setup_cert_key() { | |
| trap "exit" INT TERM EXIT | |
| test -d $TARGET_DIR | |
| if [ $? -eq 1 ]; then | |
| echo "Creating meter config directory ($TARGET_DIR) ..." | |
| if [ $DISTRO = "SmartOS" ]; then | |
| mkdir $TARGET_DIR | |
| else | |
| sudo mkdir $TARGET_DIR | |
| fi | |
| fi | |
| test -f $TARGET_DIR/key.pem | |
| if [ $? -eq 1 ]; then | |
| echo "Key file is missing, attempting to download ..." | |
| echo "Downloading meter key for $2" | |
| if [ $DISTRO = "SmartOS" ]; then | |
| $CURL -s -u $1: $2/key.pem | tee $TARGET_DIR/key.pem > /dev/null | |
| else | |
| $CURL -s -u $1: $2/key.pem | sudo tee $TARGET_DIR/key.pem > /dev/null | |
| fi | |
| if [ $? -gt 0 ]; then | |
| echo "Error downloading key ..." | |
| exit 1 | |
| fi | |
| if [ $DISTRO = "SmartOS" ]; then | |
| chmod 600 $TARGET_DIR/key.pem | |
| else | |
| sudo chmod 600 $TARGET_DIR/key.pem | |
| fi | |
| fi | |
| test -f $TARGET_DIR/cert.pem | |
| if [ $? -eq 1 ]; then | |
| echo "Cert file is missing, attempting to download ..." | |
| echo "Downloading meter certificate for $2" | |
| if [ $DISTRO = "SmartOS" ]; then | |
| $CURL -s -u $1: $2/cert.pem | tee $TARGET_DIR/cert.pem > /dev/null | |
| else | |
| $CURL -s -u $1: $2/cert.pem | sudo tee $TARGET_DIR/cert.pem > /dev/null | |
| fi | |
| if [ $? -gt 0 ]; then | |
| echo "Error downloading certificate ..." | |
| exit 1 | |
| fi | |
| if [ $DISTRO = "SmartOS" ]; then | |
| chmod 600 $TARGET_DIR/cert.pem | |
| else | |
| sudo chmod 600 $TARGET_DIR/cert.pem | |
| fi | |
| fi | |
| } | |
| function cert_key_check() { | |
| SIZE=`du $TARGET_DIR/cert.pem | awk '{print $1}'` | |
| if [ $SIZE -lt 1 ]; then | |
| echo "Error downloading certificate (file size 0) ..." | |
| exit 1 | |
| fi | |
| SIZE=`du $TARGET_DIR/key.pem | awk '{print $1}'` | |
| if [ $SIZE -lt 1 ]; then | |
| echo "Error downloading key (file size 0) ..." | |
| exit 1 | |
| fi | |
| } | |
| function ec2_tag() { | |
| trap "exit" INT TERM EXIT | |
| EC2=`$CURL -s --connect-timeout 5 "$EC2_INTERNAL"` | |
| exit_code=$? | |
| if [ "$exit_code" -eq "0" ]; then | |
| # check to see if we *really* are on EC2 | |
| $CURL -is --connect-timeout 5 "$EC2_INTERNAL" | grep 'Server: EC2ws' > /dev/null | |
| exit_code=$? | |
| if [ "$exit_code" -eq "0" ]; then | |
| echo -n "Auto generating ec2 tags for this meter...." | |
| else | |
| return 0 | |
| fi | |
| else | |
| return 0 | |
| fi | |
| for tag in $TAGS; do | |
| local AN_TAG | |
| local exit_code | |
| AN_TAG=`$CURL -s --connect-timeout 5 "$EC2_INTERNAL/$tag"` | |
| exit_code=$? | |
| # if the exit code is 7, that means curl couldnt connect so we can bail | |
| # since we probably are not on ec2. | |
| if [ "$exit_code" -eq "7" ]; then | |
| # do nothing | |
| return 0 | |
| fi | |
| # it appears that an exit code of 28 is also a can't connect error | |
| if [ "$exit_code" -eq "28" ]; then | |
| # do nothing | |
| return 0 | |
| fi | |
| # otherwise, maybe there was as timeout or something, skip that tag. | |
| if [ "$exit_code" -ne "0" ]; then | |
| continue | |
| fi | |
| for an_tag in $AN_TAG; do | |
| # create the tag | |
| $CURL -H "Content-Type: application/json" -s -u "$1:" -X PUT "$2/tags/$an_tag" | |
| done | |
| done | |
| #tags update begin | |
| #we know we're in EC2 because we didnt bomb out yet | |
| #set EC2_ACCESS_KEY and EC2_SECRET_KEY_ID via export prior to script run | |
| #because AWS is awesomely inconsistent in command line tools, safest to set the following, but I don't know how to test which are actually used: | |
| #AWS_ACCESS_KEY, AWS_SECRET_KEY_ID, AWS_SECRET_KEY, EC2_ACCESS_KEY, EC2_SECRET_KEY, EC2_SECRET_KEY_ID | |
| for tag in `ec2-describe-tags --filter "resource-id=\`curl -s http://169.254.169.254/latest/meta-data/instance-id\`" | grep -v Name | sed 's/[ \t]/ /g' | cut -d " " -f 5-`; do | |
| $CURL -H "Content-Type: application/json" -s -u "$1:" -X PUT "$2/tags/$tag" | |
| done | |
| #tags update end | |
| $CURL -H "Content-Type: application/json" -s -u "$1:" -X PUT "$2/tags/ec2" | |
| echo "done." | |
| } | |
| function pre_install_sanity() { | |
| SUDO=`which sudo` | |
| if [ $? -ne 0 ]; then | |
| echo "This script requires that sudo be installed and configured for your user." | |
| echo "Please install sudo. For assistance, [email protected]" | |
| exit 1 | |
| fi | |
| if [ $DISTRO = "SmartOS" ]; then | |
| TARGET_DIR="/opt/local/etc/bprobe" | |
| fi | |
| which curl > /dev/null | |
| if [ $? -gt 0 ]; then | |
| echo "The 'curl' command is either not installed or not on the PATH ..." | |
| if [ $DEPS = "true" ]; then | |
| echo "Installing curl ..." | |
| if [ $DISTRO = "Ubuntu" ] || [ $DISTRO = "Debian" ]; then | |
| echo "Updating apt repository cache..." | |
| sudo $APT_CMD update > /dev/null | |
| sudo $APT_CMD install curl | |
| elif [ $DISTRO = "CentOS" ] || [ $DISTRO = "Amazon" ] || [ $DISTRO = "RHEL" ]; then | |
| if [ $MACHINE = "i686" ]; then | |
| sudo $YUM_CMD install curl.i686 | |
| fi | |
| if [ $MACHINE = "x86_64" ]; then | |
| sudo $YUM_CMD install curl.x86_64 | |
| fi | |
| fi | |
| else | |
| echo "To automatically install required components for Meter Install, rerun $0 with -d flag." | |
| exit 1 | |
| fi | |
| fi | |
| if [ $DISTRO = "SmartOS" ]; then | |
| CURL="`which curl` -k" | |
| else | |
| CURL="`which curl` --sslv3" | |
| fi | |
| if [ $DISTRO = "Ubuntu" ] || [ $DISTRO = "Debian" ]; then | |
| test -f /usr/lib/apt/methods/https | |
| if [ $? -gt 0 ];then | |
| echo "apt-transport-https is not installed to access Boundary's HTTPS based APT repository ..." | |
| if [ $DEPS = "true" ]; then | |
| echo "Updating apt repository cache..." | |
| sudo $APT_CMD update > /dev/null | |
| echo "Installing apt-transport-https ..." | |
| sudo $APT_CMD install apt-transport-https | |
| else | |
| echo "To automatically install required components for Meter Install, rerun $0 with -d flag." | |
| exit 1 | |
| fi | |
| fi | |
| fi | |
| } | |
| # Grab some system information | |
| if [ -f /etc/redhat-release ] ; then | |
| PLATFORM=`cat /etc/redhat-release` | |
| DISTRO=`echo $PLATFORM | awk '{print $1}'` | |
| if [ "$DISTRO" != "CentOS" ]; then | |
| if [ "$DISTRO" = "Red" ]; then | |
| DISTRO="RHEL" | |
| VERSION=`echo $PLATFORM | awk '{print $7}'` | |
| else | |
| DISTRO="unknown" | |
| PLATFORM="unknown" | |
| VERSION="unknown" | |
| fi | |
| elif [ "$DISTRO" = "CentOS" ]; then | |
| VERSION=`echo $PLATFORM | awk '{print $3}'` | |
| fi | |
| MACHINE=`uname -m` | |
| elif [ -f /etc/system-release ]; then | |
| PLATFORM=`cat /etc/system-release | head -n 1` | |
| DISTRO=`echo $PLATFORM | awk '{print $1}'` | |
| VERSION=`echo $PLATFORM | awk '{print $5}'` | |
| MACHINE=`uname -m` | |
| elif [ -f /etc/lsb-release ] ; then | |
| #Ubuntu version lsb-release - https://help.ubuntu.com/community/CheckingYourUbuntuVersion | |
| . /etc/lsb-release | |
| PLATFORM=$DISTRIB_DESCRIPTION | |
| DISTRO=$DISTRIB_ID | |
| VERSION=$DISTRIB_RELEASE | |
| MACHINE=`uname -m` | |
| elif [ -f /etc/debian_version ] ; then | |
| #Debian Version /etc/debian_version - Source: http://www.debian.org/doc/manuals/debian-faq/ch-software.en.html#s-isitdebian | |
| DISTRO="Debian" | |
| VERSION=`cat /etc/debian_version` | |
| INFO="$DISTRO $VERSION" | |
| PLATFORM=$INFO | |
| MACHINE=`uname -m` | |
| else | |
| PLATFORM=`uname -sv | grep 'SunOS joyent'` > /dev/null | |
| if [ "$?" = "0" ]; then | |
| PLATFORM="SmartOS" | |
| DISTRO="SmartOS" | |
| MACHINE="i386" | |
| VERSION=13 | |
| if [ -x /etc/product ]; then | |
| grep "base64" /etc/product > /dev/null | |
| if [ "$?" = "0" ]; then | |
| MACHINE="x86_64" | |
| fi | |
| VERSION=`grep 'Image' /etc/product | awk '{ print $3}' | awk -F. '{print $1}'` | |
| fi | |
| elif [ "$?" != "0" ]; then | |
| PLATFORM="unknown" | |
| DISTRO="unknown" | |
| MACHINE=`uname -m` | |
| fi | |
| fi | |
| echo "Detected $DISTRO $VERSION..." | |
| echo "" | |
| while getopts "hdsi:" opts; do | |
| case $opts in | |
| h) print_help;; | |
| d) DEPS="true";; | |
| s) STAGING="true";; | |
| i) APICREDS="$OPTARG";; | |
| [?]) print_help;; | |
| esac | |
| done | |
| if [ $STAGING = "true" ]; then | |
| APT="apt-staging.boundary.com" | |
| YUM="yum-staging.boundary.com" | |
| SMARTOS="smartos-staging.boundary.com" | |
| fi | |
| if [ -z $APICREDS ]; then | |
| print_help | |
| fi | |
| APIID=`echo $APICREDS | awk -F: '{print $1}'` | |
| APIKEY=`echo $APICREDS | awk -F: '{print $2}'` | |
| if [ $MACHINE = "i686" ] || | |
| [ $MACHINE = "i586" ] || | |
| [ $MACHINE = "i386" ] ; then | |
| ARCH="32" | |
| SUPPORTED_ARCH=1 | |
| fi | |
| #determine hard vs. soft float using readelf | |
| if [[ "$MACHINE" == arm* ]] ; then | |
| if [ -x /usr/bin/readelf ] ; then | |
| HARDFLOAT=`readelf -a /proc/self/exe | grep armhf` | |
| if [ -z "$HARDFLOAT" ]; then | |
| if [ $MACHINE = "armv7l" ] || | |
| [ $MACHINE = "armv6l" ] || | |
| [ $MACHINE = "armv5tel" ] || | |
| [ $MACHINE = "armv5tejl" ] ; then | |
| ARCH="32" | |
| SUPPORTED_ARCH=1 | |
| echo "Detected $MACHINE running armel" | |
| fi | |
| else | |
| if [ $MACHINE = "armv7l" ] ; then | |
| ARCH="32" | |
| SUPPORTED_ARCH=1 | |
| echo "Detected $MACHINE running armhf" | |
| else | |
| echo "$MACHINE with armhf ABI is not supported. Try the armel ABI" | |
| fi | |
| fi | |
| else | |
| echo "Cannot determine ARM ABI, please install the 'binutils' package" | |
| fi | |
| fi | |
| if [ $MACHINE = "x86_64" ] || [ $MACHINE = "amd64" ]; then | |
| ARCH="64" | |
| SUPPORTED_ARCH=1 | |
| fi | |
| if [ $SUPPORTED_ARCH -eq 0 ]; then | |
| echo "Unsupported architecture ($MACHINE) ..." | |
| echo "This is an unsupported platform for the Boundary Meter." | |
| echo "Please contact [email protected] to request support for this architecture." | |
| exit 1 | |
| fi | |
| # Check the distribution | |
| for d in ${PLATFORMS[*]} ; do | |
| if [ $DISTRO = $d ]; then | |
| SUPPORTED_PLATFORM=1 | |
| break | |
| fi | |
| done | |
| if [ $SUPPORTED_PLATFORM -eq 0 ]; then | |
| echo "Your platform is not supported." | |
| print_supported_platforms | |
| exit 0 | |
| fi | |
| # Check the version number | |
| UNSUPPORTED_RELEASE=0 | |
| check_distro_version "$PLATFORM" $DISTRO $VERSION | |
| if [ $? -ne 0 ]; then | |
| UNSUPPORTED_RELEASE=1 | |
| echo "Detected $PLATFORM $DISTRO $VERSION" | |
| fi | |
| # The version number hasn't been found; let's just try and masquerade | |
| # (and tell users what we're doing) | |
| if [ $UNSUPPORTED_RELEASE -eq 1 ] ; then | |
| TEMP="\${${DISTRO}_VERSIONS[*]}" | |
| VERSIONS=`eval echo $TEMP` | |
| # Assume ordered list; grab latest version | |
| VERSION=`echo $VERSIONS | awk '{print $NF}'` | |
| MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'` | |
| MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'` | |
| echo "" | |
| echo "Continuing; for reference, script is masquerading as: $DISTRO $VERSION" | |
| echo "" | |
| fi | |
| # At this point, we think we have a supported OS. | |
| pre_install_sanity $d $v | |
| METER_LOCATION=`create_meter $APIKEY $APIID` | |
| if [ $? -gt 0 ]; then | |
| echo "Error creating meter:" | |
| echo "$METER_LOCATION" | |
| echo "Please contact [email protected]" | |
| exit 1 | |
| fi | |
| KEY_CERT=`setup_cert_key $APIKEY $METER_LOCATION` | |
| if [ $? -eq 1 ]; then | |
| echo "Error setting up cert and/or key ..." | |
| echo "Please contact [email protected]" | |
| echo $KEY_CERT | |
| exit 1 | |
| fi | |
| CERT_KEY_CHECK=`cert_key_check` | |
| if [ $? -eq 1 ]; then | |
| echo "Error setting up cert and/or key ..." | |
| echo "Please contact [email protected]" | |
| echo $CERT_KEY_CHECK | |
| exit 1 | |
| fi | |
| ec2_tag $APIKEY $METER_LOCATION | |
| do_install | |
| if [ $? -ne 0 ]; then | |
| echo "I added the correct repositories, but the meter installation failed." | |
| echo "Please contact [email protected] about this problem." | |
| exit 1 | |
| fi | |
| if [ -n "$CACERTS" ]; then | |
| rm -f $CACERTS | |
| fi | |
| echo "" | |
| echo "The meter has been installed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment