Files
gvm/scripts/pkg-install
T

131 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
if [ "$1" == "" ]; then
echo "Please specify package name"
exit 1
fi
display_error() {
tput sgr0
tput setaf 1
echo "ERROR: $1"
tput sgr0
exit 1
}
[[ $gvm_go_name != "" ]] ||
display_error "No Go version selected"
[[ $gvm_pkgset_name != "" ]] ||
display_error "No package set selected"
gvm_go_path=$GVM_ROOT/pkgsets/$gvm_go_name/$gvm_pkgset_name
cur_dir=`pwd`
cur_dirname=`pwd | awk '{ n=split($1,path,"/"); print path[n] }'`
cache_dir=$GVM_ROOT/archive/package/$1
source_dir=$GVM_ROOT/tmp/$1/src
build_dir=$GVM_ROOT/tmp/$1/build
package_name=$1
version=$2
function download_package() {
if [ ! -d "$cache_dir" ]; then
echo "Downloading $package_name..."
mkdir -p $cache_dir
git clone git@github.com:moovweb/$package_name $cache_dir > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "ERROR: Could not find $package_name in any sources"
exit 1
fi
fi
}
function select_version() {
if [ "$version" != "" ]; then
cd $source_dir && git pull &&
git checkout $version > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Invalid version $version"
exit 1
fi
fi
}
function setup_build_env() {
rm -rf $build_dir && mkdir -p $build_dir
rm -rf $source_dir
cp -r $cache_dir/ $source_dir/
select_version
}
function check_deps() {
export GOPATH=$build_dir
if [ -f "$source_dir/Package.gvm" ]; then
for line in `cat $source_dir/Package.gvm | grep ^pkg | awk '{ print $2 }'`; do
CUR_PKG=$gvm_go_path/pkg.gvm/$line/current
if [ -e "$CUR_PKG/BUILD_VERSION" ]; then
echo "$line: `cat $CUR_PKG/BUILD_VERSION`" >> $build_dir/manifest
else
gvm pkg install $line
if [ $? -ne 0 ]; then
echo "Failed to install dependency $line"
exit 1
fi
#echo "ERROR: Couldnt find package: $line"
#exit 1
fi
export GOPATH=$GOPATH:$CUR_PKG
done
fi
echo ":complete" >> $build_dir/manifest
}
function build_package() {
echo "Installing $package_name..."
if [[ -n $BUILD_NUMBER ]]; then
export BUILD_NUMBER="`cat VERSION`.$BUILD_NUMBER"
else
export BUILD_NUMBER="`cat $source_dir/VERSION`.dev"
fi
echo "$BUILD_NUMBER" > $build_dir/BUILD_VERSION
cd $source_dir && gvmake > $build_dir/build.log 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Failed to build"
cat "$build_dir/build.log"
exit 1
fi
}
function install_package() {
mkdir -p $gvm_go_path/pkg.gvm/$package_name/$BUILD_NUMBER &&
cp -r $build_dir/* $gvm_go_path/pkg.gvm/$package_name/$BUILD_NUMBER &&
rm -f $gvm_go_path/pkg.gvm/$package_name/current &&
ln -s $gvm_go_path/pkg.gvm/$package_name/$BUILD_NUMBER $gvm_go_path/pkg.gvm/$package_name/current &&
if [ $? -ne 0 ]; then
echo "ERROR: Failed to install"
exit 1
fi
if [ -d $build_dir/bin ]; then
mkdir -p $gvm_go_path/bin &&
cp -f $build_dir/bin/* $gvm_go_path/bin/
fi
}
function cleanup() {
rm -rf $build_dir
rm -rf $source_dir
}
#if [ "$cur_dirname" == "$package_name" ]; then
# cache_dir=$cur_dir
# BUILD_NUMBER=src
# echo "Using local source"
#else
download_package
#fi
setup_build_env
check_deps
build_package
install_package
cleanup