Refactor gvm script. Add some comments.

This commit is contained in:
Marco Vermeulen
2012-09-14 21:46:34 +01:00
parent ff800b8107
commit 4e9f0fe46e

119
bin/gvm
View File

@@ -2,32 +2,9 @@
GVM_VERSION="v0.1"
echo "Groovy enVironment Manager $GVM_VERSION"
if [ ! $(which curl) ]; then
echo "Please install curl through your package manager before using this tool."
exit 0
fi
if [ ! "$GVM_SERVICE" ]; then
GVM_SERVICE="http://localhost:8080/gvm-service"
fi
if [ ! "$GVM_DIR" ]; then
GVM_DIR="$HOME/.gvm"
fi
if [ ! -d "$GVM_DIR" ]; then
mkdir "$GVM_DIR"
fi
CANDIDATES=$(curl -s "$GVM_SERVICE/candidate/all")
if [ ! "$CANDIDATES" ]; then
echo "------------------------------------------"
echo " This is serious! Service is down! "
echo " Please notify: @freshgroovy immediately! "
echo "------------------------------------------"
exit 0
fi
#
# function definitions
#
function help {
echo "Usage: gvm <command> <candidate> [version]"
@@ -39,33 +16,6 @@ function help {
echo "eg: gvm install grails 2.1.0"
}
if [ "$1" == "help" -o -z "$1" -o -z "$2" ]; then
help
exit 0
fi
if [ "$1" != "install" -a "$1" != "use" -a "$1" != "uninstall" -a "$1" != "list" -a "$1" != "help" ]; then
echo "Invalid command: $1"
help
exit 0
fi
CANDIDATE_VALID=$(curl -s "$GVM_SERVICE/candidate/all/$2")
if [ "$CANDIDATE_VALID" != 'true' ]; then
echo "Invalid candidate: $2"
help
exit 0
fi
function download {
CANDIDATE="$1"
VERSION="$2"
echo ""
DOWNLOAD_URL=$(curl -s "$GVM_SERVICE/$CANDIDATE/download/$VERSION")
curl -L "$DOWNLOAD_URL" >> "/tmp/$CANDIDATE-$VERSION.zip"
echo ""
}
function determine_candidate_version {
if [ -z "$1" ]; then
VERSION=$(curl -s "$GVM_SERVICE/$CANDIDATE/version/current")
@@ -122,6 +72,67 @@ function determine_current_version {
CURRENT=$(readlink "$GVM_DIR/$CANDIDATE/current" | sed -e "s_$GVM_DIR/$CANDIDATE/__g")
}
function download {
CANDIDATE="$1"
VERSION="$2"
echo ""
DOWNLOAD_URL=$(curl -s "$GVM_SERVICE/$CANDIDATE/download/$VERSION")
curl -L "$DOWNLOAD_URL" >> "/tmp/$CANDIDATE-$VERSION.zip"
echo ""
}
#
# Various sanity checks and default settings
#
if [ ! $(which curl) ]; then
echo "Please install curl through your package manager before using this tool."
exit 0
fi
if [ ! "$GVM_SERVICE" ]; then
GVM_SERVICE="http://localhost:8080/gvm-service"
fi
if [ ! "$GVM_DIR" ]; then
GVM_DIR="$HOME/.gvm"
fi
if [ ! -d "$GVM_DIR" ]; then
mkdir "$GVM_DIR"
fi
CANDIDATES=$(curl -s "$GVM_SERVICE/candidate/all")
if [ ! "$CANDIDATES" ]; then
echo "------------------------------------------"
echo " This is serious! Service is down! "
echo " Please notify: @freshgroovy immediately! "
echo "------------------------------------------"
exit 0
fi
if [ "$1" == "help" -o -z "$1" -o -z "$2" ]; then
help
exit 0
fi
if [ "$1" != "install" -a "$1" != "use" -a "$1" != "uninstall" -a "$1" != "list" -a "$1" != "help" ]; then
echo "Invalid command: $1"
help
exit 0
fi
CANDIDATE_VALID=$(curl -s "$GVM_SERVICE/candidate/all/$2")
if [ "$CANDIDATE_VALID" != 'true' ]; then
echo "Invalid candidate: $2"
help
exit 0
fi
#
# Command functions
#
function gvm-install {
CANDIDATE="$1"
determine_candidate_version "$2"
@@ -161,4 +172,6 @@ function gvm-list {
echo "$FRAGMENT"
}
# Main command
gvm-"$1" "$2" "$3"