on pr610 help sign in
servant/scripts/lib/common.sh
56 lines 1.5 kB history raw
1#!/bin/bash -
2#===============================================================================
3#
4# FILE: lib/common.sh
5#
6# DESCRIPTION: Common functions for servant's shell scripts
7# Meant to be sourced rather than run.
8#
9# REQUIREMENTS: bash >= 4
10#===============================================================================
13DIR=$( dirname $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))
14ROOT=$( dirname $DIR )
15DRY_RUN=false
16POSITION="none"
17SOURCES_TXT="$( dirname $DIR)/sources.txt"
18CABAL=${CABAL:-cabal}
19TRAVIS=${TRAVIS:-false}
21declare -a SOURCES
22SOURCES=$(awk -F= '{print $1}' "$SOURCES_TXT")
24join () { local IFS="$1"; shift; echo "$*"; }
26versions_equal () {
27 local NUM=$(cd "$ROOT" && find . -name 'servant*.cabal' | xargs grep "^version:" | awk '{ print $2 }' | uniq -c | wc -l)
28 if [ 1 -eq $NUM ] ; then
29 return 0
30 else
31 echo "versions of packages are not all the same!" && exit 1
32 fi
35travis_retry() {
36 # From
37 # https://github.com/travis-ci/travis-build/blob/18bd04e965b9bfaa49cd6bdcd8dcb1513b8d2fcd/lib/travis/build/templates/header.sh
38 local result=0
39 local count=1
40 while [ $count -le 3 ]; do
41 [ $result -ne 0 ] && {
42 echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
43 }
44 "$@"
45 result=$?
46 [ $result -eq 0 ] && break
47 count=$(($count + 1))
48 sleep 1
49 done
51 [ $count -gt 3 ] && {
52 echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
53 }
55 return $result