#!/bin/bash . `dirname "$(readlink -f "$0")"`/run-library.sh read -rd "\000" helpmessage <&2 "$helpmessage" echo >&2 exit 1 ;; --target) TARGET="$2"; shift ;; --debug) DEBUG=1 ;; --build-bundle-packages) BUILD_BUNDLE_PACKAGES=1 ;; --) if [ $# -gt 1 ]; then echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help" exit 1 fi ;; esac shift done STDOUT_IF_DEBUG=/dev/null STDERR_IF_DEBUG=/dev/null DASHQ_UNLESS_DEBUG=-q if [[ "$DEBUG" != 0 ]]; then STDOUT_IF_DEBUG=/dev/stdout STDERR_IF_DEBUG=/dev/stderr DASHQ_UNLESS_DEBUG= fi case "$TARGET" in debian7) FORMAT=deb ;; debian8) FORMAT=deb ;; ubuntu1204) FORMAT=deb ;; ubuntu1404) FORMAT=deb ;; centos6) FORMAT=rpm ;; *) echo -e "$0: Unknown target '$TARGET'.\n" >&2 exit 1 ;; esac if ! [[ -n "$WORKSPACE" ]]; then echo >&2 "$helpmessage" echo >&2 echo >&2 "Error: WORKSPACE environment variable not set" echo >&2 exit 1 fi if ! [[ -d "$WORKSPACE" ]]; then echo >&2 "$helpmessage" echo >&2 echo >&2 "Error: $WORKSPACE is not a directory" echo >&2 exit 1 fi # Find the SSO server package cd "$WORKSPACE" SSO_VERSION=$(version_from_git) PACKAGE_NAME=arvados-sso if [[ "$FORMAT" == "deb" ]]; then PACKAGE_PATH=$WORKSPACE/packages/$TARGET/arvados-sso_${SSO_VERSION}_amd64.deb elif [[ "$FORMAT" == "rpm" ]]; then PACKAGE_PATH=$WORKSPACE/packages/$TARGET/arvados-sso-${SSO_VERSION}-1.x86_64.rpm fi # Test 1a: the package to test must exist if [[ ! -f $PACKAGE_PATH ]]; then echo "Latest package not found at $PACKAGE_PATH. Please build the package first." exit 1 fi if [[ "$FORMAT" == "deb" ]]; then # Test 1b: the system/container where we're running the tests must be clean set +e dpkg -l |grep arvados-sso -q if [[ "$?" != "1" ]]; then echo "Please make sure the arvados-sso package is not installed before running this script" exit 1 fi set -e fi if [[ -e "/var/www/arvados-sso" ]]; then echo "Please make sure /var/www/arvados-sso does not exist before running this script" exit 1 fi # Prepare the machine if [[ "$FORMAT" == "deb" ]]; then $SUDO apt-get update elif [[ "$FORMAT" == "rpm" ]]; then $SUDO yum check-update fi $SUDO mkdir -p /etc/arvados/sso if [[ ! -e "/etc/arvados/sso/application.yml" ]]; then RANDOM_PASSWORD=`date | md5sum |cut -f1 -d' '` cp config/application.yml.example /etc/arvados/sso/application.yml sed -i -e 's/uuid_prefix: ~/uuid_prefix: zzzzz/' /etc/arvados/sso/application.yml sed -i -e "s/secret_token: ~/secret_token: $RANDOM_PASSWORD/" /etc/arvados/sso/application.yml fi if [[ ! -e "/etc/arvados/sso/database.yml" ]]; then # We haven't installed our dependencies yet, but we need to set up our # database configuration now. Install postgresql if need be. if [[ "$FORMAT" == "deb" ]]; then install_package postgresql elif [[ "$FORMAT" == "rpm" ]]; then install_package postgresql-server # postgres packaging on CentOS6 is kind of primitive, needs an initdb $SUDO service postgresql initdb if [ "$TARGET" = "centos6" ]; then sed -i -e "s/127.0.0.1\/32 ident/127.0.0.1\/32 md5/" /var/lib/pgsql/data/pg_hba.conf sed -i -e "s/::1\/128 ident/::1\/128 md5/" /var/lib/pgsql/data/pg_hba.conf fi fi $SUDO service postgresql start RANDOM_PASSWORD=`date | md5sum |cut -f1 -d' '` cat >/etc/arvados/sso/database.yml < /dev/null 2>&1 $SUDO apt-get -f install --yes set -e $SUDO dpkg -i $PACKAGE_PATH # Test 3: the package should remove cleanly $SUDO apt-get remove arvados-sso --yes # Test 4: the package configuration should remove cleanly $SUDO dpkg --purge arvados-sso if [[ -e "/var/www/arvados-sso" ]]; then echo "Error: leftover items under /var/www/arvados-sso." exit 4 fi # Test 5: the package should remove cleanly with --purge $SUDO dpkg -i $PACKAGE_PATH $SUDO apt-get remove arvados-sso --purge --yes if [[ -e "/var/www/arvados-sso" ]]; then echo "Error: leftover items under /var/www/arvados-sso." exit 5 fi elif [[ "$FORMAT" == "rpm" ]]; then # Test 2: the package should install cleanly $SUDO yum -q -y --nogpgcheck localinstall $PACKAGE_PATH # Test 3: the package should remove cleanly $SUDO yum -q -y remove arvados-sso if [[ -e "/var/www/arvados-sso" ]]; then echo "Error: leftover items under /var/www/arvados-sso." exit 3 fi fi echo "Testing complete, no errors!" exit $EXITCODE