1#!/bin/sh 2set -o xtrace # Write all commands first to stderr 3set -o errexit # Exit the script with error if any of the commands fail 4 5get_distro () 6{ 7 if [ -f /etc/os-release ]; then 8 . /etc/os-release 9 DISTRO="${ID}-${VERSION_ID}" 10 elif command -v lsb_release 2>/dev/null; then 11 name=$(lsb_release -s -i) 12 if [ "$name" = "RedHatEnterpriseServer" ]; then # RHEL 6.2 at least 13 name="rhel" 14 fi 15 version=$(lsb_release -s -r) 16 DISTRO="${name}-${version}" 17 elif [ -f /etc/redhat-release ]; then 18 release=$(cat /etc/redhat-release) 19 20 if [[ "$release" =~ "Red Hat" ]]; then 21 name="rhel" 22 elif [[ "$release" =~ "Fedora" ]]; then 23 name="fedora" 24 fi 25 version=$(echo $release | sed 's/.*\([[:digit:]]\).*/\1/g') 26 DISTRO="${name}-${version}" 27 elif [ -f /etc/lsb-release ]; then 28 . /etc/lsb-release 29 DISTRO="${DISTRIB_ID}-${DISTRIB_RELEASE}" 30 fi 31 32 OS=$(uname -s) 33 MARCH=$(uname -m) 34 DISTRO=$(echo "$OS-$DISTRO-$MARCH" | tr '[:upper:]' '[:lower:]') 35 36 echo $DISTRO 37} 38 39# get_mongodb_download_url_for "linux-distro-version-architecture" "latest|34|32|30|28|26|24" 40# Sets EXTRACT to aproprate extract command 41# Sets MONGODB_DOWNLOAD_URL to the aproprate download url 42get_mongodb_download_url_for () 43{ 44 _DISTRO=$1 45 _VERSION=$2 46 47 VERSION_34="3.4.0" 48 VERSION_32="3.2.11" 49 VERSION_30="3.0.14" 50 VERSION_26="2.6.12" 51 VERSION_24="2.4.12" 52 53 EXTRACT="tar zxf" 54 # getdata matrix on: 55 # https://evergreen.mongodb.com/version/5797f0493ff12235e5001f05 56 case "$_DISTRO" in 57 darwin*) 58 MONGODB_LATEST="http://downloads.10gen.com/osx/mongodb-osx-x86_64-enterprise-latest.tgz" 59 MONGODB_34="http://downloads.10gen.com/osx/mongodb-osx-x86_64-enterprise-${VERSION_34}.tgz" 60 MONGODB_32="http://downloads.10gen.com/osx/mongodb-osx-x86_64-enterprise-${VERSION_32}.tgz" 61 MONGODB_30="https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-${VERSION_30}.tgz" 62 MONGODB_26="https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-${VERSION_26}.tgz" 63 MONGODB_24="https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-${VERSION_24}.tgz" 64 ;; 65 linux-rhel-7.2-s390x) 66 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-s390x-enterprise-rhel72-latest.tgz" 67 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-s390x-enterprise-rhel72-${VERSION_34}.tgz" 68 MONGODB_32="" 69 MONGODB_30="" 70 MONGODB_26="" 71 MONGODB_24="" 72 ;; 73 linux-rhel-7.1-ppc64le) 74 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-ppc64le-enterprise-rhel71-latest.tgz" 75 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-ppc64le-enterprise-rhel71-${VERSION_34}.tgz" 76 MONGODB_32="http://downloads.10gen.com/linux/mongodb-linux-ppc64le-enterprise-rhel71-${VERSION_32}.tgz" 77 MONGODB_30="" 78 MONGODB_26="" 79 MONGODB_24="" 80 ;; 81 linux-rhel-7.0*) 82 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel70-latest.tgz" 83 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel70-${VERSION_34}.tgz" 84 MONGODB_32="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel70-${VERSION_32}.tgz" 85 MONGODB_30="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel70-${VERSION_30}.tgz" 86 MONGODB_26="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel70-${VERSION_26}.tgz" 87 MONGODB_24="" 88 ;; 89 linux-rhel-6.2*) 90 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel62-latest.tgz" 91 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel62-${VERSION_34}.tgz" 92 MONGODB_32="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel62-${VERSION_32}.tgz" 93 MONGODB_30="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel62-${VERSION_30}.tgz" 94 MONGODB_26="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel62-${VERSION_26}.tgz" 95 MONGODB_24="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-rhel62-${VERSION_24}.tgz" 96 ;; 97 linux-rhel-5.5*) 98 MONGODB_LATEST="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel55-latest.tgz" 99 MONGODB_34="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel55-${VERSION_34}.tgz" 100 MONGODB_32="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel55-${VERSION_32}.tgz" 101 MONGODB_30="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel55-${VERSION_30}.tgz" 102 MONGODB_26="" 103 MONGODB_24="" 104 ;; 105 linux-sles-12.1-s390x) 106 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-s390x-enterprise-suse12-latest.tgz" 107 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-s390x-enterprise-suse12-${VERSION_34}.tgz" 108 MONGODB_32="" 109 MONGODB_30="" 110 MONGODB_26="" 111 MONGODB_24="" 112 ;; 113 linux-debian-8*) 114 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-debian81-latest.tgz" 115 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-debian81-${VERSION_34}.tgz" 116 MONGODB_32="" 117 MONGODB_30="" 118 MONGODB_26="" 119 MONGODB_24="" 120 ;; 121 linux-ubuntu-16.04-s390x) 122 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-s390x-enterprise-ubuntu1604-latest.tgz" 123 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-s390x-enterprise-ubuntu1604-${VERSION_34}.tgz" 124 MONGODB_32="" 125 MONGODB_30="" 126 MONGODB_26="" 127 MONGODB_24="" 128 ;; 129 linux-ubuntu-16.04-ppc64le) 130 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-ppc64le-enterprise-ubuntu1604-latest.tgz" 131 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-ppc64le-enterprise-ubuntu1604-${VERSION_34}.tgz" 132 MONGODB_32="" 133 MONGODB_30="" 134 MONGODB_26="" 135 MONGODB_24="" 136 ;; 137 linux-ubuntu-16.04-aarch64) 138 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-arm64-enterprise-ubuntu1604-latest.tgz" 139 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-arm64-enterprise-ubuntu1604-${VERSION_34}.tgz" 140 MONGODB_32="" 141 MONGODB_30="" 142 MONGODB_26="" 143 MONGODB_24="" 144 ;; 145 linux-ubuntu-16.04*) 146 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1604-latest.tgz" 147 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1604-${VERSION_34}.tgz" 148 MONGODB_32="" 149 MONGODB_30="" 150 MONGODB_26="" 151 MONGODB_24="" 152 ;; 153 linux-ubuntu-14.04*) 154 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-latest.tgz" 155 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-${VERSION_34}.tgz" 156 MONGODB_32="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-${VERSION_32}.tgz" 157 MONGODB_30="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-${VERSION_30}.tgz" 158 MONGODB_26="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1404-${VERSION_26}.tgz" 159 MONGODB_24="" 160 ;; 161 linux-ubuntu-12.04*) 162 MONGODB_LATEST="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1204-latest.tgz" 163 MONGODB_34="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1204-${VERSION_34}.tgz" 164 MONGODB_32="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1204-${VERSION_32}.tgz" 165 MONGODB_30="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1204-${VERSION_30}.tgz" 166 MONGODB_26="http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-ubuntu1204-${VERSION_26}.tgz" 167 MONGODB_24="http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-ubuntu1204-${VERSION_24}.tgz" 168 ;; 169 windows32*) 170 EXTRACT="/cygdrive/c/Progra~2/7-Zip/7z.exe x" 171 MONGODB_LATEST="https://fastdl.mongodb.org/win32/mongodb-win32-i386-latest.zip" 172 MONGODB_34="https://fastdl.mongodb.org/win32/mongodb-win32-i386-${VERSION_34}.zip" 173 MONGODB_32="https://fastdl.mongodb.org/win32/mongodb-win32-i386-${VERSION_32}.zip" 174 MONGODB_30="https://fastdl.mongodb.org/win32/mongodb-win32-i386-${VERSION_30}.zip" 175 MONGODB_26="https://fastdl.mongodb.org/win32/mongodb-win32-i386-${VERSION_26}.zip" 176 MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-i386-${VERSION_24}.zip" 177 ;; 178 windows64*) 179 EXTRACT="/cygdrive/c/Progra~2/7-Zip/7z.exe x" 180 MONGODB_LATEST="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-latest.zip" 181 MONGODB_34="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-${VERSION_34}.zip" 182 MONGODB_32="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-${VERSION_32}.zip" 183 MONGODB_30="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-${VERSION_30}.zip" 184 MONGODB_26="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-${VERSION_26}.zip" 185 MONGODB_24="https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-${VERSION_24}.zip" 186 ;; 187 cygwin*) 188 EXTRACT="/cygdrive/c/Progra~2/7-Zip/7z.exe x" 189 MONGODB_LATEST="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64-latest.zip" 190 MONGODB_34="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64-${VERSION_34}.zip" 191 MONGODB_32="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64-${VERSION_32}.zip" 192 MONGODB_30="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64-${VERSION_30}.zip" 193 MONGODB_26="http://downloads.10gen.com/win32/mongodb-win32-x86_64-enterprise-windows-64-${VERSION_26}.zip" 194 MONGODB_24="" 195 ;; 196 *linux*x86_64) 197 MONGODB_LATEST="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-latest.tgz" 198 MONGODB_34="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-${VERSION_34}.tgz" 199 MONGODB_32="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-${VERSION_32}.tgz" 200 MONGODB_30="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-${VERSION_30}.tgz" 201 MONGODB_26="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-${VERSION_26}.tgz" 202 MONGODB_24="http://downloads.mongodb.org/linux/mongodb-linux-x86_64-${VERSION_24}.tgz" 203 ;; 204 esac 205 206 MONGODB_DOWNLOAD_URL="" 207 case "$_VERSION" in 208 latest) MONGODB_DOWNLOAD_URL=$MONGODB_LATEST ;; 209 3.4) MONGODB_DOWNLOAD_URL=$MONGODB_34 ;; 210 3.2) MONGODB_DOWNLOAD_URL=$MONGODB_32 ;; 211 3.0) MONGODB_DOWNLOAD_URL=$MONGODB_30 ;; 212 2.6) MONGODB_DOWNLOAD_URL=$MONGODB_26 ;; 213 2.4) MONGODB_DOWNLOAD_URL=$MONGODB_24 ;; 214 esac 215 216 [ -z "$MONGODB_DOWNLOAD_URL" ] && MONGODB_DOWNLOAD_URL="Unknown version: $_VERSION for $_DISTRO" 217 218 echo $MONGODB_DOWNLOAD_URL 219} 220 221download_and_extract () 222{ 223 MONGODB_DOWNLOAD_URL=$1 224 EXTRACT=$2 225 226 if ! test -d mongodb -a -x mongodb/bin/mongod; then 227 curl --retry 5 $MONGODB_DOWNLOAD_URL --silent --max-time 120 --fail --output mongodb-binaries.tgz 228 229 $EXTRACT mongodb-binaries.tgz 230 231 rm -rf mongodb*tgz mongodb/ 232 mv mongodb* mongodb 233 chmod -R +x mongodb 234 find . -name vcredist_x64.exe -exec {} /install /quiet \; 235 fi 236 ./mongodb/bin/mongod --version 237} 238