forked from TypedDevs/bashunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·63 lines (49 loc) · 1.53 KB
/
install.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
#!/bin/bash
# shellcheck disable=SC2164
# shellcheck disable=SC2103
declare -r BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit"
function get_latest_tag() {
git ls-remote --tags "$BASHUNIT_GIT_REPO" |
awk '{print $2}' |
sed 's|^refs/tags/||' |
sort -Vr |
head -n 1
}
declare -r LATEST_BASHUNIT_VERSION="$(get_latest_tag)"
DIR=${1-lib}
VERSION=${2-latest}
TAG="$LATEST_BASHUNIT_VERSION"
function build_and_install_beta() {
echo "> Downloading non-stable version: 'beta'"
git clone --depth 1 --no-tags https://github.com/TypedDevs/bashunit temp_bashunit 2>/dev/null
cd temp_bashunit
./build.sh >/dev/null
cd ..
local latest_commit
latest_commit=$(git rev-parse --short=8 HEAD);
local beta_version
beta_version='(non-stable) beta after '"$LATEST_BASHUNIT_VERSION"' ['"$(date +'%Y-%m-%d')"'] 🐍 #'"$latest_commit"
sed -i -e 's/BASHUNIT_VERSION=".*"/BASHUNIT_VERSION="'"$beta_version"'"/g' temp_bashunit/bin/bashunit
cp temp_bashunit/bin/bashunit ./
rm -rf temp_bashunit
}
function install() {
if [[ $VERSION != 'latest' ]]; then
TAG="$VERSION"
echo "> Downloading a concrete version: '$TAG'"
else
echo "> Downloading the latest version: '$TAG'"
fi
curl -L -O -J "https://github.com/TypedDevs/bashunit/releases/download/$TAG/bashunit" 2>/dev/null
chmod u+x "bashunit"
}
cd "$(dirname "$0")"
rm -f "$DIR"/bashunit
[ -d "$DIR" ] || mkdir "$DIR"
cd "$DIR"
if [[ $VERSION == 'beta' ]]; then
build_and_install_beta
else
install
fi
echo "> bashunit has been installed in the '$DIR' folder"