#!/bin/bash if [[ "$1" == "" ]]; then echo "ERROR: Please specifiy the version" exit 1 else REVISION=$1 fi ################################################################################ # Implementation ################################################################################ # find_revision(version) get_source_tag() { curl -s https://go.googlecode.com/hg/.hgtags | awk '{print $2;}' | grep "$1" > /dev/null 2>&1 if [[ $? -ne 0 ]]; then return 1 fi SOURCE_TAG=`curl -s https://go.googlecode.com/hg/.hgtags | awk '{print $2;}' | grep "$1" | tail -n 1` } # download_revision(revision, destination) download_revision() { hg clone -u $1 https://go.googlecode.com/hg/ $2 if [[ $? -ne 0 ]]; then return 1 fi } # compile_go(source) compile_go() { unset GOARCH unset GOOS unset GOPATH export GOBIN=$1/bin export PATH=$GOBIN:$PATH export GOROOT=$1 cd $1/src && ./all.bash if [[ $? -ne 0 ]]; then return 1 fi } ################################################################################ # Interface ################################################################################ download() { echo " * Downloading..." download_revision $SOURCE_TAG $SOURCE_ROOT > $GVM_ROOT/logs/$SOURCE_TAG-download.log 2>&1 if [[ $? -ne 0 ]]; then echo "Failed to download version $SOURCE_TAG. See logs in $GVM_ROOT/logs/$SOURCE_TAG-download.log for details" exit 1 fi } copy_source() { cp -r $SOURCE_ROOT $INSTALL_ROOT if [[ $? -ne 0 ]]; then echo "Failed to copy from cache" exit 1 fi } setup_install_env() { get_source_tag $REVISION if [[ $? -ne 0 ]]; then echo "Failed to find go release version: '$1'" exit 1 fi SOURCE_ROOT=$GVM_ROOT/archive/$SOURCE_TAG INSTALL_ROOT=$GVM_ROOT/gos/$SOURCE_TAG if [[ -d $INSTALL_ROOT ]]; then echo "Already installed!" exit 1 else echo "Installing version $SOURCE_TAG" fi if [[ ! -d $SOURCE_ROOT ]]; then download fi trap 'rm -rf $INSTALL_ROOT' INT copy_source } compile() { echo " * Compiling..." compile_go $INSTALL_ROOT > $GVM_ROOT/logs/$SOURCE_TAG-compile.log 2>&1 if [[ $? -ne 0 ]]; then echo "Failed to install version $SOURCE_TAG. See logs in $GVM_ROOT/logs/$SOURCE_TAG-compile.log for details" rm -rf $INSTALL_ROOT exit 1 fi } install_gb() { echo " * Installing gb..." goinstall github.com/skelterjohn/go-gb/gb if [[ $? -ne 0 ]]; then echo "Failed to install gb" exit 1 fi } install_goprotobuf() { echo " * Installing goprotobuf..." if [[ "$SOURCE_TAG" == "release.r60.3" ]]; then goinstall goprotobuf.googlecode.com/hg/proto if [[ $? -ne 0 ]]; then echo "Failed to install goprotobuf" exit 1 fi cd $GOROOT/src/pkg/goprotobuf.googlecode.com/hg/compiler make install > $GVM_ROOT/logs/$SOURCE_TAG-pb-compiler.log 2>&1 if [[ $? -ne 0 ]]; then echo "Failed to install goprotobuf compiler" exit 1 fi else echo " Don't know how to install goprotobuf for $SOURCE_TAG" fi } create_env_file() { gvm_go_name=$SOURCE_TAG mkdir -p $GVM_ROOT/environments mkdir -p $GVM_ROOT/pkgsets/$SOURCE_TAG/global new_env_file=$GVM_ROOT/environments/$SOURCE_TAG echo "export gvm_go_name; gvm_go_name=\"$gvm_go_name\"" > $new_env_file echo "unset gvm_pkgset_name" >> $new_env_file echo "export GOROOT; GOROOT=\"\$GVM_ROOT/gos/$gvm_go_name\"" >> $new_env_file echo "export GOPATH; GOPATH=\"\$GVM_ROOT/pkgsets/$gvm_go_name/global\"" >> $new_env_file echo "export PATH; PATH=\"\$GVM_ROOT/pkgsets/$gvm_go_name/global/bin:\$GVM_ROOT/gos/$gvm_go_name/bin:\$GVM_ROOT/bin:\$PATH\"" >> $new_env_file } main() { setup_install_env compile create_env_file install_gb install_goprotobuf } main