#!/bin/bash
-EXITCODE=0
-CALL_FREIGHT=0
-APTUSER=$1
-APTSERVER=$2
+read -rd "\000" helpmessage <<EOF
+$(basename $0): Build Arvados packages and (optionally) upload them.
-if [[ "$APTUSER" == '' ]]; then
- echo "Syntax: $0 <aptuser> <aptserver>"
- exit 1
-fi
+Syntax:
+ $(basename $0) WORKSPACE=/path/to/arvados [options]
+
+Options:
+
+--upload Upload packages (default: false)
+--scp-user USERNAME Scp user for apt server (only required when --upload is specified)
+--apt-server HOSTNAME Apt server hostname (only required when --upload is specified)
+--debug Output debug information (default: false)
+
+WORKSPACE=path Path to the Arvados source tree to build packages from
-if [[ "$APTSERVER" == '' ]]; then
- echo "Syntax: $0 <aptuser> <aptserver>"
+EOF
+
+EXITCODE=0
+CALL_FREIGHT=0
+
+DEBUG=0
+UPLOAD=0
+
+while [[ -n "$1" ]]
+do
+ arg="$1"; shift
+ case "$arg" in
+ --help)
+ echo >&2 "$helpmessage"
+ echo >&2
+ exit 1
+ ;;
+ --scp-user)
+ APTUSER="$1"; shift
+ ;;
+ --apt-server)
+ APTSERVER="$1"; shift
+ ;;
+ --debug)
+ DEBUG=1
+ ;;
+ --upload)
+ UPLOAD=1
+ ;;
+ *)
+ echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
+ exit 1
+ ;;
+ esac
+done
+
+# Sanity checks
+if [[ "$UPLOAD" != '0' && ("$APTUSER" == '' || "$APTSERVER" == '') ]]; then
+ echo >&2 "$helpmessage"
+ echo >&2
+ echo >&2 "Error: please specify --scp-user and --apt-server if --upload is set"
+ echo >&2
exit 1
fi
# Sanity check
if ! [[ -n "$WORKSPACE" ]]; then
- echo "WORKSPACE environment variable not set"
+ echo >&2 "$helpmessage"
+ echo >&2
+ echo >&2 "Error: WORKSPACE environment variable not set"
+ echo >&2
exit 1
fi
source /etc/profile.d/rvm.sh
-echo $WORKSPACE
+
+if [[ "$DEBUG" != 0 ]]; then
+ echo "Workspace is $WORKSPACE"
+fi
# Make all files world-readable -- jenkins runs with umask 027, and has checked
# out our git tree here
# gems and packages
umask 0022
-echo "umask is"
-umask
+if [[ "$DEBUG" != 0 ]]; then
+ echo "umask is" `umask`
+fi
# Build arvados GEM
-echo "Build and publish ruby gem"
+if [[ "$DEBUG" != 0 ]]; then
+ echo "Build and publish ruby gems"
+fi
+
cd "$WORKSPACE"
cd sdk/ruby
# clean up old gems
rm -f arvados-*gem
-gem build arvados.gemspec
-# publish new gem
-gem push arvados-*gem
+
+if [[ "$DEBUG" != 0 ]]; then
+ gem build arvados.gemspec
+else
+ # -q appears to be broken in gem version 2.2.2
+ gem build arvados.gemspec -q >/dev/null
+fi
+
+if [[ "$UPLOAD" != 0 ]]; then
+ # publish new gem
+ gem push arvados-*gem
+fi
# Build arvados-cli GEM
-echo "Build and publish ruby gem"
cd "$WORKSPACE"
cd sdk/cli
# clean up old gems
rm -f arvados-cli*gem
-gem build arvados-cli.gemspec
-# publish new gem
-gem push arvados-cli*gem
+
+if [[ "$DEBUG" != 0 ]]; then
+ gem build arvados-cli.gemspec
+else
+ # -q appears to be broken in gem version 2.2.2
+ gem build arvados-cli.gemspec -q >/dev/null
+fi
+
+if [[ "$UPLOAD" != 0 ]]; then
+ # publish new gem
+ gem push arvados-cli*gem
+fi
# Build arvados-python-client Python package
-echo "Build and publish arvados-python-client package"
+if [[ "$DEBUG" != 0 ]]; then
+ echo "Build and publish arvados-python-client package"
+fi
+
cd "$WORKSPACE"
GIT_HASH=`git log --format=format:%ct.%h -n1 .`
cd sdk/python
# Make sure only to use sdist - that's the only format pip can deal with (sigh)
-python setup.py sdist upload
+
+if [[ "$UPLOAD" != 0 ]]; then
+ # Make sure only to use sdist - that's the only format pip can deal with (sigh)
+ if [[ "$DEBUG" != 0 ]]; then
+ python setup.py sdist upload
+ else
+ python setup.py -q sdist upload
+ fi
+else
+ # Make sure only to use sdist - that's the only format pip can deal with (sigh)
+ if [[ "$DEBUG" != 0 ]]; then
+ python setup.py sdist
+ else
+ python setup.py -q sdist
+ fi
+fi
cd ../../services/fuse
-# Make sure only to use sdist - that's the only format pip can deal with (sigh)
-python setup.py sdist upload
+if [[ "$UPLOAD" != 0 ]]; then
+ # Make sure only to use sdist - that's the only format pip can deal with (sigh)
+ if [[ "$DEBUG" != 0 ]]; then
+ python setup.py sdist upload
+ else
+ python setup.py -q sdist upload
+ fi
+else
+ # Make sure only to use sdist - that's the only format pip can deal with (sigh)
+ if [[ "$DEBUG" != 0 ]]; then
+ python setup.py sdist
+ else
+ python setup.py -q sdist
+ fi
+fi
# Build debs for everything
build_and_scp_deb () {
COMMAND_ARR+=("$PACKAGE")
+ if [[ "$DEBUG" != 0 ]]; then
+ echo
+ echo "Fpm command:"
+ echo "${COMMAND_ARR[@]}"
+ echo
+ fi
+
FPM_RESULTS=$("${COMMAND_ARR[@]}")
FPM_EXIT_CODE=$?
if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
EXITCODE=1
- echo "Error: Unabled figure out package name from fpm results:\n $FPM_RESULTS"
+ echo "Error: Unable to figure out package name from fpm results:\n $FPM_RESULTS"
else
if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
if [[ "$FPM_EXIT_CODE" != "0" ]]; then
echo "Error building debian package for $1:\n $FPM_RESULTS"
else
- scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
- CALL_FREIGHT=1
+ if [[ "$UPLOAD" != 0 ]]; then
+ scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
+ CALL_FREIGHT=1
+ fi
fi
else
echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
mkdir "$WORKSPACE/src-build-dir"
cd "$WORKSPACE"
- git clone https://github.com/curoverse/arvados.git src-build-dir
+ if [[ "$DEBUG" != 0 ]]; then
+ git clone https://github.com/curoverse/arvados.git src-build-dir
+ else
+ git clone -q https://github.com/curoverse/arvados.git src-build-dir
+ fi
fi
cd "$WORKSPACE/src-build-dir"
# just in case, check out master
-git checkout master
-git pull
-
-# go into detached-head state
-git checkout `git log --format=format:%h -n1 .`
+if [[ "$DEBUG" != 0 ]]; then
+ git checkout master
+ git pull
+ # go into detached-head state
+ git checkout `git log --format=format:%h -n1 .`
+else
+ git checkout -q master
+ git pull -q
+ # go into detached-head state
+ git checkout -q `git log --format=format:%h -n1 .`
+fi
# Build arvados src deb package
cd $WORKSPACE/debs
# clean up, check out master and step away from detached-head state
cd "$WORKSPACE/src-build-dir"
-git checkout master
+if [[ "$DEBUG" != 0 ]]; then
+ git checkout master
+else
+ git checkout -q master
+fi
# Keep
export GOPATH=$(mktemp -d)
build_and_scp_deb virtualenv
# Finally, publish the packages, if necessary
-if [[ "$CALL_FREIGHT" != "0" ]]; then
+if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
else
- echo "No new packages generated. No freight run necessary."
+ if [[ "$UPLOAD" != 0 ]]; then
+ echo "No new packages generated. No freight run necessary."
+ fi
fi
# clean up temporary GOPATH