diff --git a/bin/gvm b/bin/gvm index 7070530..171e20d 100755 --- a/bin/gvm +++ b/bin/gvm @@ -10,7 +10,7 @@ if [ -z "$GVM_ROOT" ]; then exit 1 fi -. $GVM_ROOT/scripts/functions +. $GVM_ROOT/scripts/functions || exit 1 command=$1 if [[ $command == "implode" ]]; then diff --git a/extra/DEBIAN/control b/extra/DEBIAN/control new file mode 100644 index 0000000..d139561 --- /dev/null +++ b/extra/DEBIAN/control @@ -0,0 +1,5 @@ +Package: gvm +Version: 1.0.15 +Architecture: all +Maintainer: Joshua Bussdieker +Description: Go Version Manager diff --git a/scripts/diff b/scripts/diff index 6d2d255..874f014 100755 --- a/scripts/diff +++ b/scripts/diff @@ -5,14 +5,14 @@ version=$1 if [ "$version" != "" ]; then fuzzy_match=`$LS_PATH $GVM_ROOT/gos | $SORT_PATH | $GREP_PATH "$version" | $HEAD_PATH -n 1 | $GREP_PATH "$version"` || - display_error "Invalid version $version" + display_fatal "Invalid version $version" foldername=$GVM_ROOT/gos/$fuzzy_match else if [[ "$gvm_go_name" != "" ]]; then foldername=$GVM_ROOT/gos/$gvm_go_name else - display_error "No version selected" + display_fatal "No version selected" fi fi @@ -26,5 +26,5 @@ if [[ -d $foldername ]]; then display_message "*Dirty* $foldername" fi else - display_error "Invalid version" + display_fatal "Invalid version" fi diff --git a/scripts/env/gvm b/scripts/env/gvm index 2f1cfac..75ad254 100644 --- a/scripts/env/gvm +++ b/scripts/env/gvm @@ -1,11 +1,5 @@ #!/bin/bash -function display_error() { - tput sgr0 - tput setaf 1 - echo "ERROR: $1" >&2 - tput sgr0 - return 1 -} +. $GVM_ROOT/scripts/functions || return 1 function gvm() { if [[ "$GVM_ROOT" == "" ]]; then diff --git a/scripts/env/pkgset-use b/scripts/env/pkgset-use index 59b964f..0195764 100644 --- a/scripts/env/pkgset-use +++ b/scripts/env/pkgset-use @@ -1,22 +1,4 @@ #!/bin/bash -. $GVM_ROOT/scripts/function/tools - -function display_error() { - tput sgr0 - tput setaf 1 - echo "ERROR: $1" >&2 - tput sgr0 - return 1 -} - -function display_message() { - # GREEN! - tput sgr0 - tput setaf 2 - echo "$1" - tput sgr0 -} - function gvm_pkgset_use() { [[ "$1" != "" ]] || display_error "Please specify a package set" || return 1 diff --git a/scripts/env/use b/scripts/env/use index dd38798..45a6a09 100644 --- a/scripts/env/use +++ b/scripts/env/use @@ -1,22 +1,4 @@ #!/bin/bash -. $GVM_ROOT/scripts/function/tools - -function display_error() { - tput sgr0 - tput setaf 1 - echo "ERROR: $1" >&2 - tput sgr0 - return 1 -} - -function display_message() { - # GREEN! - tput sgr0 - tput setaf 2 - echo "$1" - tput sgr0 -} - function gvm_use() { [[ "$1" != "" ]] || display_error "Please specifiy the version" || return 1 diff --git a/scripts/function/display_error b/scripts/function/display_error index 89361a2..fe632ad 100644 --- a/scripts/function/display_error +++ b/scripts/function/display_error @@ -3,6 +3,6 @@ display_error() { tput setaf 1 echo "ERROR: $1" >&2 tput sgr0 - exit 1 + return 1 } diff --git a/scripts/function/display_fatal b/scripts/function/display_fatal new file mode 100644 index 0000000..68fa12d --- /dev/null +++ b/scripts/function/display_fatal @@ -0,0 +1,8 @@ +display_fatal() { + tput sgr0 + tput setaf 1 + echo "ERROR: $1" >&2 + tput sgr0 + exit 1 +} + diff --git a/scripts/function/tools b/scripts/function/tools index e5f5d59..6cdd140 100644 --- a/scripts/function/tools +++ b/scripts/function/tools @@ -1,8 +1,8 @@ #!/bin/bash -LS_ERROR="Couldn't find ls" -GREP_ERROR="Couldn't find grep" -SORT_ERROR="Couldn't find sort" -HEAD_ERROR="Couldn't find head" +LS_ERROR="GVM couldn't find ls" +GREP_ERROR="GVM couldn't find grep" +SORT_ERROR="GVM couldn't find sort" +HEAD_ERROR="GVM couldn't find head" LS_PATH=`unalias ls &> /dev/null; which ls` || display_error "$LS_ERROR" || return 1 GREP_PATH=`unalias grep &> /dev/null; which grep` || display_error "$GREP_ERROR" || return 1 diff --git a/scripts/get b/scripts/get index b562895..d242909 100755 --- a/scripts/get +++ b/scripts/get @@ -2,19 +2,19 @@ . $GVM_ROOT/scripts/functions [[ -d $GVM_ROOT/.git ]] || mv $GVM_ROOT/git.bak $GVM_ROOT/.git &> /dev/null || - display_error "Couldn't find git info" + display_fatal "Couldn't find git info" cd $GVM_ROOT && git checkout -f || - display_error "Failed to clean install" + display_fatal "Failed to clean install" if [[ -n $1 ]]; then cd $GVM_ROOT && git checkout $1 -f || - display_error "Failed to checkout $1 branch" + display_fatal "Failed to checkout $1 branch" fi cd $GVM_ROOT && git pull || - display_error "Failed to update" + display_fatal "Failed to update" mv $GVM_ROOT/.git $GVM_ROOT/git.bak || - display_error "Couldn't backup git info" + display_fatal "Couldn't backup git info" diff --git a/scripts/install b/scripts/install index cc66e94..6749e8f 100755 --- a/scripts/install +++ b/scripts/install @@ -44,7 +44,7 @@ download_source() { [[ -d $GO_CACHE_PATH ]] && return display_message "Downloading Go source..." hg clone $GO_SOURCE_URL $GO_CACHE_PATH >> $GVM_ROOT/logs/go-download.log 2>&1 || - display_error "Couldn't download Go source" + display_fatal "Couldn't download Go source" } check_tag() { @@ -54,12 +54,12 @@ check_tag() { update_source() { display_message "Updating Go source..." hg pull -R $GO_CACHE_PATH >> $GVM_ROOT/logs/go-download.log 2>&1 || - display_error "Couldn't get latest Go version info" + display_fatal "Couldn't get latest Go version info" } copy_source() { hg clone -u $version $GO_CACHE_PATH $GO_INSTALL_ROOT >> $GVM_ROOT/logs/go-$version-install.log 2>&1 || - display_error "Couldn't copy source to target folder" + display_fatal "Couldn't copy source to target folder" } @@ -71,7 +71,7 @@ compile_go() { export GOROOT=$GO_INSTALL_ROOT && #cd $GO_INSTALL_ROOT/src && ./all.bash &> $GVM_ROOT/logs/go-$version-compile.log || cd $GO_INSTALL_ROOT/src && ./make.bash &> $GVM_ROOT/logs/go-$version-compile.log || - (rm -rf $GO_INSTALL_ROOT && display_error "Failed to compile") + (rm -rf $GO_INSTALL_ROOT && display_fatal "Failed to compile") } create_enviroment() { @@ -84,19 +84,19 @@ create_enviroment() { echo "export PATH; PATH=\"\$GVM_ROOT/pkgsets/$version/global/bin:\$GVM_ROOT/gos/$version/bin:\$GVM_ROOT/bin:\$PATH\"" >> $new_env_file . $GVM_ROOT/scripts/env/use gvm_use $version &> /dev/null || - display_error "Failed to use installed version" + display_fatal "Failed to use installed version" gvm pkgset create global unset GOPATH } install_go() { GO_INSTALL_ROOT=$GVM_ROOT/gos/$version - trap 'rm -rf $GO_INSTALL_ROOT; display_error "Canceled!"' INT + trap 'rm -rf $GO_INSTALL_ROOT; display_fatal "Canceled!"' INT # Check for existing install if [[ -d "$GO_INSTALL_ROOT" ]]; then [[ -f "$GO_INSTALL_ROOT/manifest" ]] && - display_error "Already installed!" + display_fatal "Already installed!" display_warning "Removing corrupt install..." gvm uninstall $version fi @@ -105,7 +105,7 @@ install_go() { # Create the global package set folder mkdir -p $GVM_ROOT/pkgsets/$version >> $GVM_ROOT/logs/go-$version-install.log 2>&1 || - display_error "Couldn't create global package set folder" + display_fatal "Couldn't create global package set folder" copy_source compile_go @@ -140,11 +140,11 @@ install_goprotobuf() { } main() { - trap 'display_error "Canceled!"' INT + trap 'display_fatal "Canceled!"' INT read_command_line $@ - [[ "$VERSION" == "" ]] && display_error "No version specified" + [[ "$VERSION" == "" ]] && display_fatal "No version specified" download_source - check_tag || (update_source && check_tag) || display_error "Unrecognized Go version" + check_tag || (update_source && check_tag) || display_fatal "Unrecognized Go version" install_go GVM_GOINSTALL="goinstall" diff --git a/scripts/listall b/scripts/listall index 06f6985..f41cd4f 100755 --- a/scripts/listall +++ b/scripts/listall @@ -34,7 +34,7 @@ display_message "gvm gos (available)" echo versions=`curl -s https://go.googlecode.com/hg/.hgtags | awk '{ print $2 }' | $SORT_PATH` if [[ $? -ne 0 ]]; then - display_error "Failed to get version list from Google" + display_fatal "Failed to get version list from Google" fi for version in $versions; do if [[ "$tag_filter" == "release" ]]; then diff --git a/scripts/pkgset b/scripts/pkgset index 0ec359f..cddbc3b 100755 --- a/scripts/pkgset +++ b/scripts/pkgset @@ -2,18 +2,18 @@ . $GVM_ROOT/scripts/functions [[ $gvm_go_name != "" ]] || - display_error "No Go version selected" + display_fatal "No Go version selected" [[ -d $GVM_ROOT/gos/$gvm_go_name ]] || - display_error "Invalid or corrupt Go version" + display_fatal "Invalid or corrupt Go version" [[ -d $GVM_ROOT/pkgsets/$gvm_go_name ]] || - display_error "Missing package set folder for this Go version" + display_fatal "Missing package set folder for this Go version" command=$1 if [[ -f $GVM_ROOT/scripts/pkgset-$command ]]; then shift $GVM_ROOT/scripts/pkgset-$command $@ elif [[ -n $command ]]; then - display_error "Unrecognized command line argument: '$command'" + display_fatal "Unrecognized command line argument: '$command'" else echo "= gvm pkgset diff --git a/scripts/pkgset-create b/scripts/pkgset-create index e82c518..fc8a051 100755 --- a/scripts/pkgset-create +++ b/scripts/pkgset-create @@ -2,19 +2,19 @@ . $GVM_ROOT/scripts/functions [[ $1 != "" ]] || - display_error "Please specifiy the name" + display_fatal "Please specifiy the name" [[ ! -f "$GVM_ROOT/environments/$gvm_go_name@$1" ]] || - display_error "Packageset already exists!" + display_fatal "Packageset already exists!" mkdir -p $GVM_ROOT/pkgsets/$gvm_go_name/$1 || - display_error "Could not create folder" + display_fatal "Could not create folder" cp $GVM_ROOT/environments/$gvm_go_name $GVM_ROOT/environments/$gvm_go_name@$1 || - display_error "Could copy environment" + display_fatal "Could copy environment" echo "export gvm_pkgset_name=\"$1\"" >> $GVM_ROOT/environments/$gvm_go_name@$1 || - display_error "Could not extend environment" + display_fatal "Could not extend environment" echo "export GOPATH; GOPATH=\"$GVM_ROOT/pkgsets/$gvm_go_name/$1:\$GOPATH\"" >> $GVM_ROOT/environments/$gvm_go_name@$1 || - display_error "Could not extend environment" + display_fatal "Could not extend environment" echo "export PATH; PATH=\"$GVM_ROOT/pkgsets/$gvm_go_name/$1/bin:\$PATH\"" >> $GVM_ROOT/environments/$gvm_go_name@$1 || - display_error "Could not extend environment" + display_fatal "Could not extend environment" diff --git a/scripts/pkgset-delete b/scripts/pkgset-delete index 5df756b..ab2d87c 100755 --- a/scripts/pkgset-delete +++ b/scripts/pkgset-delete @@ -2,17 +2,17 @@ . $GVM_ROOT/scripts/functions [[ $gvm_go_name != "" ]] || - display_error "No Go version selected" + display_fatal "No Go version selected" [[ $1 != "" ]] || - display_error "Please specifiy the name" + display_fatal "Please specifiy the name" [[ -d $GVM_ROOT/pkgsets/$gvm_go_name/$1 ]] || - display_error "Packageset doesn't exist!" + display_fatal "Packageset doesn't exist!" rm -rf $GVM_ROOT/pkgsets/$gvm_go_name/$1 || - display_error "Could not delete package set" + display_fatal "Could not delete package set" rm -rf $GVM_ROOT/environments/$gvm_go_name@$1 || - display_error "Could not delete package set" + display_fatal "Could not delete package set" diff --git a/scripts/pkgset-empty b/scripts/pkgset-empty index 3356483..1de11b1 100755 --- a/scripts/pkgset-empty +++ b/scripts/pkgset-empty @@ -2,7 +2,7 @@ . $GVM_ROOT/scripts/functions [[ $gvm_pkgset_name != "" ]] || - display_error "No Package set selected" + display_fatal "No Package set selected" rm -rf $GVM_ROOT/pkgsets/$gvm_go_name/$gvm_pkgset_name/* || - display_error "Could not delete package set files" + display_fatal "Could not delete package set files" diff --git a/scripts/uninstall b/scripts/uninstall index 779bc44..0404d8f 100755 --- a/scripts/uninstall +++ b/scripts/uninstall @@ -2,21 +2,21 @@ . $GVM_ROOT/scripts/functions [[ "$1" == "" ]] && - display_error "Please specifiy the version" + display_fatal "Please specifiy the version" fuzzy_match=`$LS_PATH $GVM_ROOT/gos | $SORT_PATH | $GREP_PATH "$1" | $HEAD_PATH -n 1 | $GREP_PATH "$1"` || - display_error "Invalid version $1" + display_fatal "Invalid version $1" if [[ -d $GVM_ROOT/gos/$fuzzy_match ]]; then rm -rf $GVM_ROOT/pkgsets/$fuzzy_match &> /dev/null || - display_error "Couldn't remove pkgsets" + display_fatal "Couldn't remove pkgsets" rm -f $GVM_ROOT/environments/$fuzzy_match &> /dev/null || - display_error "Couldn't remove environment files" + display_fatal "Couldn't remove environment files" rm -f "$GVM_ROOT/environments/$fuzzy_match@"* &> /dev/null || - display_error "Couldn't remove pkgset environment files" + display_fatal "Couldn't remove pkgset environment files" rm -rf $GVM_ROOT/gos/$fuzzy_match &> /dev/null || - display_error "Couldn't remove Go folder" + display_fatal "Couldn't remove Go folder" display_message "Uninstalled version $fuzzy_match" else - display_error "Invalid version" + display_fatal "Invalid version" fi diff --git a/scripts/update b/scripts/update index 7fd6f0a..855b126 100755 --- a/scripts/update +++ b/scripts/update @@ -2,8 +2,8 @@ . $GVM_ROOT/scripts/functions cd $GVM_ROOT/archive/go &> /dev/null || - display_error "Failed to find local Go source" + display_fatal "Failed to find local Go source" cd $GVM_ROOT/archive/go && hg pull || - display_error "Failed to update" + display_fatal "Failed to update"