-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-bats-core.sh
executable file
·71 lines (54 loc) · 1.76 KB
/
install-bats-core.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
DEPENDENCIES_PATH="dependencies"
GIT_REPO="https://github.com/bats-core/bats-core.git"
GIT_BRANCH="master"
PREV_PWD=$PWD
TMP_DIR=$PWD/$DEPENDENCIES_PATH/tmp
set -eo pipefail
set -u
FORCE=${1:--keep}
function get_bats_repo_and_branch() {
FORCE=$1
CHECKOUT_DIR="tmp/bats"
INSTALATION_DIR="bats-core"
if [ ! -d "$DEPENDENCIES_PATH" ]; then
mkdir -p "$DEPENDENCIES_PATH"
fi
cd "$DEPENDENCIES_PATH"
if [[ ! -d "$INSTALATION_DIR" ]]; then
echo "Checking out branch $GIT_BRANCH of repo $GIT_REPO ..."
git clone --branch $GIT_BRANCH $GIT_REPO $CHECKOUT_DIR
pull_repository
run_package_installation $INSTALATION_DIR
else
echo "Directory $INSTALATION_DIR already exists."
if [ $FORCE == "-force" ]; then
echo "$FORCE parameter passed, updating dependency anyway."
git clone --branch $GIT_BRANCH $GIT_REPO $CHECKOUT_DIR
pull_repository
run_package_installation $INSTALATION_DIR
else
echo "Call the script with a -force parameter to override current contents."
fi
fi
}
function pull_repository() {
cd $CHECKOUT_DIR
echo "Resetting any local changes before 'git pull'."
git checkout .
git checkout $GIT_BRANCH
echo "Bringing up to date branch $GIT_BRANCH of repo $GIT_REPO ..."
git pull
cd $PREV_PWD
}
function run_package_installation() {
echo "Installing bats-core..."
local absolute_installation_path="$PWD/$DEPENDENCIES_PATH/$CHECKOUT_DIR"
$absolute_installation_path/install.sh $PWD/$DEPENDENCIES_PATH/$INSTALATION_DIR
# Cleanup
echo "Cleaning up installation files..."
rm -rf $TMP_DIR
}
get_bats_repo_and_branch "$FORCE"
STATUS=${?}
exit ${STATUS}