mirror of
https://github.com/wahyd4/gvm.git
synced 2026-08-09 04:46:19 +10:00
166 lines
4.9 KiB
Bash
Executable File
166 lines
4.9 KiB
Bash
Executable File
#!/bin/bash
|
|
. $GVM_ROOT/scripts/functions
|
|
|
|
function show_usage() {
|
|
echo "Usage: gvm install [version] [options]"
|
|
echo " -s, --source=SOURCE Install Go from specified source."
|
|
echo " -pb, --with-protobuf Install Go protocol buffers."
|
|
echo " -h, --help Display this message."
|
|
}
|
|
|
|
read_command_line() {
|
|
VERSION=$1
|
|
if [[ "${VERSION:0:1}" != "-" ]]; then
|
|
shift
|
|
else
|
|
display_warning "Invalid version: $1"
|
|
show_usage
|
|
exit 1
|
|
fi
|
|
GO_SOURCE_URL=https://go.googlecode.com/hg/
|
|
for i in $*; do
|
|
case $i in
|
|
-s=*|--source=*)
|
|
GO_SOURCE_URL=$i
|
|
;;
|
|
-pb|--with-protobuf)
|
|
INSTALL_PB="true"
|
|
;;
|
|
-h|--help)
|
|
show_usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
display_warning "Invalid option $i"
|
|
show_usage
|
|
exit 65 # Bad arguments
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
download_source() {
|
|
GO_CACHE_PATH=$GVM_ROOT/archive/go
|
|
[[ -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"
|
|
}
|
|
|
|
check_tag() {
|
|
version=`hg tags -R $GO_CACHE_PATH | awk '{print $1}' | $SORT_PATH | $GREP_PATH "$VERSION" | $HEAD_PATH -n 1 | $GREP_PATH "$VERSION"`
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
|
|
compile_go() {
|
|
display_message " * Compiling..."
|
|
unset GOARCH && unset GOOS && unset GOPATH && unset GOBIN && unset GOROOT &&
|
|
export GOBIN=$GO_INSTALL_ROOT/bin &&
|
|
export PATH=$GOBIN:$PATH &&
|
|
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")
|
|
}
|
|
|
|
create_enviroment() {
|
|
new_env_file=$GVM_ROOT/environments/$version
|
|
echo "export GVM_ROOT; GVM_ROOT=\"$GVM_ROOT\"" > $new_env_file
|
|
echo "export gvm_go_name; gvm_go_name=\"$version\"" >> $new_env_file
|
|
echo "export gvm_pkgset_name; gvm_pkgset_name=\"global\"" >> $new_env_file
|
|
echo "export GOROOT; GOROOT=\"\$GVM_ROOT/gos/$version\"" >> $new_env_file
|
|
echo "export GOPATH; GOPATH=\"\$GVM_ROOT/pkgsets/$version/global\"" >> $new_env_file
|
|
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"
|
|
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
|
|
|
|
# Check for existing install
|
|
if [[ -d "$GO_INSTALL_ROOT" ]]; then
|
|
[[ -f "$GO_INSTALL_ROOT/manifest" ]] &&
|
|
display_error "Already installed!"
|
|
display_warning "Removing corrupt install..."
|
|
gvm uninstall $version
|
|
fi
|
|
|
|
display_message "Installing $version..."
|
|
|
|
# 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"
|
|
|
|
copy_source
|
|
compile_go
|
|
create_enviroment
|
|
}
|
|
|
|
install_gpkg() {
|
|
display_message " * Installing gpkg..."
|
|
$GVM_GOINSTALL github.com/moovweb/gpkg > $GVM_ROOT/logs/$version-gpkg.log 2>&1 || return 1
|
|
}
|
|
|
|
install_gb() {
|
|
display_message " * Installing gb..."
|
|
$GVM_GOINSTALL github.com/jbussdieker/go-gb/gb > $GVM_ROOT/logs/$version-gb.log 2>&1 || return 1
|
|
}
|
|
|
|
install_goprotobuf() {
|
|
display_message " * Installing goprotobuf..."
|
|
$GVM_GOINSTALL goprotobuf.googlecode.com/hg/proto > $GVM_ROOT/logs/$version-pb-compiler.log 2>&1
|
|
if [[ $? -ne 0 ]]; then
|
|
display_warning "Failed to install goprotobuf"
|
|
return 1
|
|
fi
|
|
#if [[ $version == "release.r60.3" ]]; then
|
|
cd $GVM_ROOT/gos/$version/src/pkg/goprotobuf.googlecode.com/hg/compiler
|
|
make install >> $GVM_ROOT/logs/$version-pb-compiler.log 2>&1
|
|
if [[ $? -ne 0 ]]; then
|
|
display_warning "Failed to install goprotobuf compiler"
|
|
return 1
|
|
fi
|
|
#fi
|
|
}
|
|
|
|
main() {
|
|
trap 'display_error "Canceled!"' INT
|
|
read_command_line $@
|
|
[[ "$VERSION" == "" ]] && display_error "No version specified"
|
|
download_source
|
|
check_tag || (update_source && check_tag) || display_error "Unrecognized Go version"
|
|
install_go
|
|
|
|
GVM_GOINSTALL="goinstall"
|
|
which goinstall &> /dev/null ||
|
|
GVM_GOINSTALL="go get"
|
|
x="`hg tags -R ~/.gvm/archive/go`"; echo ${x#*b0819469a6df} | $GREP_PATH "$version " &> /dev/null
|
|
if [[ "$?" == "1" ]]; then
|
|
install_gb || display_warning "Failed to install gb"
|
|
install_gpkg || display_warning "Failed to install gpkg"
|
|
if [[ "$INSTALL_PB" == "true" ]]; then
|
|
install_goprotobuf
|
|
fi
|
|
fi
|
|
cd $GO_INSTALL_ROOT && find . > manifest
|
|
}
|
|
|
|
main $@
|
|
|