Skip to content

Instantly share code, notes, and snippets.

@AlexandroPerez
Last active June 23, 2016 01:25
Show Gist options
  • Save AlexandroPerez/4106d1e952ac19496e240fd3b3583052 to your computer and use it in GitHub Desktop.
Save AlexandroPerez/4106d1e952ac19496e240fd3b3583052 to your computer and use it in GitHub Desktop.
#! /bin/bash
## Run this bash file to install MongoDB v3.2.7 in your cloud9 workspace
# message functions {
function msg {
colorCode="\033[0;32m"
clearColorCode="\033[0m"
if [ $# -eq 2 ]; then
colorCode="$2"
fi
echo -e "$colorCode""$1""$clearColorCode"
}
# end of message functions}
# Download and upgrade to mongodb 3.2.7
msg "Downloading mongodb v3.2.7 to ~/downloads..."
mkdir -p ~/downloads
cd ~/downloads
wget --quiet https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.2.7.tgz
msg " Unpacking download to ~/downloads/mongodb..."
tar -zxf mongodb-linux-x86_64-ubuntu1404-3.2.7.tgz
mv mongodb-linux-x86_64-ubuntu1404-3.2.7 mongodb
msg " Removing downnloaded tar file..."
rm mongodb-linux-x86_64-ubuntu1404-3.2.7.tgz
msg "Installing/Upgrading to mongodb v3.2.7..."
yes | sudo cp ~/downloads/mongodb/bin/* /usr/bin/
msg "Cleaning up"
msg " Removing unpacked mongodb tar folder (~/downloads/mongodb)..."
yes | rm -r ~/downloads/mongodb
msg " Removing ~/downloads if empty"
rmdir --ignore-fail-on-non-empty ~/downloads
# create folder for mongo data storage
msg "Creating ~/workspace/data folder for mongodb storage"
mkdir -p ~/workspace/data
cd ~/workspace/data
data=$(pwd)
# create alias in ~/.bash_aliases
msg "Attempting to create a mongodup alias..."
if grep -Fxq "alias mongodup='mongod --bind_ip=\$IP --port 27017 --dbpath=$data --nojournal --rest \"\$@\"'" ~/.bash_aliases
then
# code if found
msg " alias mongodup already exists in ~/.bash_aliases. Which is OK."
msg " Skipping creation of alias."
else
# code if not found
echo "alias mongodup='mongod --bind_ip=\$IP --port 27017 --dbpath=$data --nojournal --rest \"\$@\"'">> ~/.bash_aliases
msg " alias created!"
msg " reloading aliases..."
source ~/.bashrc
msg " aliases reloaded!"
fi
msg "Now you should be able to run mongod with the recommended arguments in Cloud9 by using mongodup!"
echo ""
echo -e " \e[1m\e[32musername\e[39m:\e[34m~/workspace\e[39m $\e[21m mongodup"
echo ""
msg "For your reference this is the mongodup alias:"
echo ""
echo " mongod --bind_ip=\$IP --port 27017 --dbpath=$data --nojournal --rest \"\$@\""
echo ""
msg "DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment