2015-06-05 14:14:26 +02:00
|
|
|
#!/bin/bash -
|
|
|
|
#===============================================================================
|
|
|
|
#
|
|
|
|
# FILE: lib/common.sh
|
|
|
|
#
|
|
|
|
# DESCRIPTION: Common functions for servant's shell scripts
|
|
|
|
# Meant to be sourced rather than run.
|
|
|
|
#
|
|
|
|
# REQUIREMENTS: bash >= 4
|
|
|
|
#===============================================================================
|
|
|
|
|
|
|
|
|
2015-06-05 15:08:52 +02:00
|
|
|
DIR=$( dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))
|
2015-07-06 09:05:45 +02:00
|
|
|
ROOT=$( dirname $DIR )
|
2015-06-05 14:14:26 +02:00
|
|
|
DRY_RUN=false
|
|
|
|
POSITION="none"
|
|
|
|
SOURCES_TXT="$( dirname $DIR)/sources.txt"
|
|
|
|
CABAL=${CABAL:-cabal}
|
2015-06-12 15:45:27 +02:00
|
|
|
TRAVIS=${TRAVIS:-false}
|
2015-06-05 14:14:26 +02:00
|
|
|
|
|
|
|
declare -a SOURCES
|
2015-07-22 23:50:03 +02:00
|
|
|
SOURCES=$(awk -F= '{print $1}' "$SOURCES_TXT")
|
2015-06-05 14:14:26 +02:00
|
|
|
|
|
|
|
join () { local IFS="$1"; shift; echo "$*"; }
|
|
|
|
|
|
|
|
versions_equal () {
|
2015-07-06 09:05:45 +02:00
|
|
|
local NUM=$(cd "$ROOT" && find . -name 'servant*.cabal' | xargs grep "^version:" | awk '{ print $2 }' | uniq -c | wc -l)
|
2015-06-05 14:14:26 +02:00
|
|
|
if [ 1 -eq $NUM ] ; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
echo "versions of packages are not all the same!" && exit 1
|
|
|
|
fi
|
|
|
|
}
|
2015-06-12 14:37:41 +02:00
|
|
|
|
|
|
|
travis_retry() {
|
|
|
|
# From
|
|
|
|
# https://github.com/travis-ci/travis-build/blob/18bd04e965b9bfaa49cd6bdcd8dcb1513b8d2fcd/lib/travis/build/templates/header.sh
|
|
|
|
local result=0
|
|
|
|
local count=1
|
|
|
|
while [ $count -le 3 ]; do
|
|
|
|
[ $result -ne 0 ] && {
|
|
|
|
echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
|
|
|
|
}
|
|
|
|
"$@"
|
|
|
|
result=$?
|
|
|
|
[ $result -eq 0 ] && break
|
|
|
|
count=$(($count + 1))
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
[ $count -gt 3 ] && {
|
|
|
|
echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result
|
|
|
|
}
|