Skip to content

Instantly share code, notes, and snippets.

@noinarisak
Last active June 13, 2016 17:04
Show Gist options
  • Save noinarisak/648294937d053b46d1f9cbc8ba2f1730 to your computer and use it in GitHub Desktop.
Save noinarisak/648294937d053b46d1f9cbc8ba2f1730 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Provision help for MongoDB on C9.io.
#
# Copyright 2016 Narisak Inc.
# Written by:
# Noi Narisak <[email protected]>
#
# c9.io setup script for MongoDB
# ===============================
# This script configures a fresh c9.io workspace
# with local instances of MongoDB
set -e
check_os() {
if [ ! -f /etc/os-release ]; then
echo "Woah, /etc/os-release doesn't exist"
echo "What are you running, Mac?"
echo "This script is indended for c9.io, go and setup a workspace there"
exit 255
fi
. /etc/os-release
if [ $ID != "ubuntu" ]; then
echo "Only Ubuntu is currently supported on c9.io"
exit 254
fi
if [ $VERSION_ID != "14.04" ]; then
echo "Only Ubuntu 14.04 is currently supported on c9.io"
exit 253
fi
}
mkdir_src() {
if [ -d "$HOME/src" ]; then
echo "mkdir ~/src: ok"
else
echo "Creating ~/src for all our external code"
mkdir -p "$HOME/src"
fi
}
mkdir_bin() {
if [ -d "$HOME/bin" ]; then
echo "mkdir ~/bin: ok"
else
echo "Creating ~/bin for all our scripting needs"
mkdir -p "$HOME/bin"
export PATH="$PATH:$HOME/bin"
echo "NOTE: you have to open a new terminal changes to PATH"
fi
}
mkdir_data() {
if [ -d "$HOME/data" ]; then
echo "mkdir ~/data: ok"
else
echo "Creating ~/data to store MongoDB assets"
mkdir -p "$HOME/data"
fi
}
_is_installed() {
[ "$(dpkg-query -s $1 2>/dev/null | grep '^Status:')" = "Status: install ok installed" ]
}
mongodb_create_binary() {
if [ -f $HOME/src/mongodbctl ]; then
echo "mongodbctl src: ok"
else
echo "Create mongodbctl"
echo 'mongod --bind_ip=$IP --dbpath=$HOME/data --nojournal --rest "$@"' > $HOME/src/mongodbctl
chmod a+x $HOME/src/mongodbctl
fi
}
mongodb_get_deps() {
local wanted_pkgs="git git-flow mongodb-org"
local pkgs_to_install=""
local pkg=""
for pkg in $wanted_pkgs; do
if ! _is_installed $pkg; then
echo "Installing package $pkg"
pkgs_to_install="$pkgs_to_install $pkg"
fi
done
if [ -z "$pkgs_to_install" ]; then
echo "acbuild deps: ok"
else
sudo apt-get update
sudo apt-get install --quiet --yes $pkgs_to_install
fi
}
mongodb_install_symlink() {
if [ -f $HOME/bin/mongodbctl ] && [ $(readlink $HOME/bin/mongodctl) = "$HOME/src/mongodbctl" ]; then
echo "mongodbctl exec: ok"
else
echo "Installing mongodbctl into ~/bin"
ln -fs $HOME/src/mongodbctl $HOME/bin/mongodbctl
fi
}
setup_mongodb() {
mkdir_src
mkdir_bin
mkdir_data
mongodb_get_deps
mongodb_create_binary
mongodb_install_symlink
}
setup_mongodb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment