Skip to content

Instantly share code, notes, and snippets.

@bnorton
Created December 2, 2016 07:19
Show Gist options
  • Save bnorton/6732d40af93c4f0b4255a01ea51ad0c5 to your computer and use it in GitHub Desktop.
Save bnorton/6732d40af93c4f0b4255a01ea51ad0c5 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
set -e
export MONGODB_VERSION=3.4.0
TAR=mongodb-linux-x86_64-ubuntu1404-$MONGODB_VERSION.tgz
URL=https://fastdl.mongodb.org/linux/$TAR
echo "---------------------------------------"
echo "Removing currently installed MongoDB"
echo "---------------------------------------"
sudo apt-get purge -y mongodb-org*
echo "---------------------------------------"
echo "Installing MongoDB version $MONGODB_VERSION"
echo "---------------------------------------"
# install MongoDB from a pre-packaged archive
if ! [ -e $SEMAPHORE_CACHE_DIR/$TAR ]; then (cd $SEMAPHORE_CACHE_DIR; wget $URL); fi
sudo tar xf $SEMAPHORE_CACHE_DIR/$TAR -C /tmp
sudo dpkg -i /tmp/*.deb
# fix permissions for the /tmp directory so MondoDB is able to start
sudo chown root:root /tmp
sudo chmod 1777 /tmp
# initiate the MongoDB service
sudo service mongod start
# print post-installation info
echo "---------------------------------------"
printf "\nInstallation complete.\n\nDetails:\n $(mongod --version)\n"
printf "\nService status:\n $(sudo service mongod status)\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment