Last Updated: February 25, 2016
·
770
· joseluisq

MongoDB Shell Installer for Red Hat Enterprise, CentOS or Fedora 64-bit system

#!/bin/sh

# Mongodb Shell 64-bit System Installer 
# OS: Red Hat Enterprise, CentOS, Fedora or a related linux system.

# Miscellaneous
B=`tput bold`
N=`tput sgr0`

# Checks if package is installed on system
FILEPATH="`type -P mongod`"

# Define 64-bit system repo
FILECONTENT="[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1"

# Define repo file path
FILEPATH="/etc/yum.repos.d/mongodb.repo"

# Check if repo exists
if [ -z $FILEPATH ];
then
echo "${B}MongoDB Installer"
echo "Initializing the installation..."

# Save mongodb.repo on repos directory
sudo echo "${FILECONTENT}" > "${FILEPATH}"

# Install MongoDB on system via yum
sudo yum install mongodb-org

# Start MongoDB service
sudo service mongod start

# Add MongoDB for automatically boot time.
sudo chkconfig mongod on

echo "${B}MongoDB${N} has been installed successfully!"
else
echo "${B}MongoDB${N} is already installed!"
fi