Last active
August 29, 2015 14:21
-
-
Save kentquirk/52d8358703c2fb4b0feb to your computer and use it in GitHub Desktop.
Provisioning script for a mongo-backed go server on a vagrant box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Provisioning script for a mongo-backed go server on a vagrant box | |
echo "install basic requirements" | |
apt-get --quiet -y update | |
DEBIAN_FRONTEND=noninteractive apt-get --quiet -y upgrade | |
apt-get --quiet -y install build-essential mercurial git curl libssl-dev pkg-config tree mongodb bison make gcc binutils | |
# turns out that golang doesn't have a good install process for ubuntu (current version on apt-get is 1.0) | |
# so we're going to install gvm to manage go versions. | |
# The gvm installer actually lets you install in a nonstandard location so we download it and | |
# run it locally | |
if [ ! -d /usr/local/gvm ]; then | |
echo "Installing gvm" | |
curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer -O | |
source gvm-installer master /usr/local | |
rm gvm-installer | |
fi | |
source /usr/local/gvm/scripts/gvm | |
if [ ! -x "$(command -v go)" ]; then | |
echo "download Go and install it" | |
gvm install go1.4 --binary | |
fi | |
gvm use go1.4 | |
echo "set environment variables required for the vagrant user" | |
HOMEDIR=/home/vagrant | |
BASHFILE=$HOMEDIR/.bashrc | |
TEMPFILE=$HOMEDIR/_CUSTOM_._TXT_ | |
mkdir -p $HOMEDIR/apps/go/bin $HOMEDIR/apps/go/src $HOMEDIR/apps/go/pkg | |
# fetch some extra bash niceness | |
curl --silent --get https://gist.githubusercontent.com/kentquirk/9820348e451da9fc02b4/raw >$HOMEDIR/.startup | |
# remove any old CUSTOM lines and add these instead | |
grep -v "# CUSTOM" $BASHFILE >$TEMPFILE | |
cat $TEMPFILE > $BASHFILE | |
cat <<EOF1 >> $BASHFILE | |
source /usr/local/gvm/scripts/gvm # CUSTOM | |
gvm use go1.4 # CUSTOM | |
if [ -f "$HOMEDIR/.startup" ] ; then # CUSTOM | |
. "$HOMEDIR/.startup" # CUSTOM | |
fi # CUSTOM | |
EOF1 | |
rm $TEMPFILE | |
chown -R vagrant:vagrant * | |
chown vagrant:vagrant $BASHFILE .startup | |
echo "Provisioning complete." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment