-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·104 lines (87 loc) · 2.38 KB
/
install.sh
File metadata and controls
executable file
·104 lines (87 loc) · 2.38 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# shellcheck disable=SC2155
# shellcheck disable=SC2164
# Helper function for regex matching (Bash 3.0+ compatible)
function regex_match() {
[[ $1 =~ $2 ]]
}
function is_git_installed() {
command -v git >/dev/null 2>&1
}
function build_and_install_beta() {
echo "> Downloading non-stable version: 'beta'"
if ! is_git_installed; then
echo "Error: git is not installed." >&2
exit 1
fi
git clone --depth 1 --no-tags "$BASHUNIT_GIT_REPO" temp_bashunit 2>/dev/null
cd temp_bashunit
./build.sh bin >/dev/null
local latest_commit=$(git rev-parse --short=7 HEAD)
# shellcheck disable=SC2103
cd ..
local beta_version=$(printf "(non-stable) beta after %s [%s] 🐍 #%s" \
"$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
if command -v curl >/dev/null 2>&1; then
curl -L -O -J "$BASHUNIT_GIT_REPO/releases/download/$TAG/bashunit" 2>/dev/null
elif command -v wget >/dev/null 2>&1; then
wget "$BASHUNIT_GIT_REPO/releases/download/$TAG/bashunit" 2>/dev/null
else
echo "Cannot download bashunit: curl or wget not found."
fi
chmod u+x "bashunit"
}
#########################
######### MAIN ##########
#########################
# Defaults
DIR="lib"
VERSION="latest"
function is_version() {
regex_match "$1" '^[0-9]+\.[0-9]+\.[0-9]+$' || [[ "$1" == "latest" || "$1" == "beta" ]]
}
# Parse arguments flexibly
if [[ $# -eq 1 ]]; then
if is_version "$1"; then
VERSION="$1"
else
DIR="$1"
fi
elif [[ $# -eq 2 ]]; then
if is_version "$1"; then
VERSION="$1"
DIR="$2"
elif is_version "$2"; then
DIR="$1"
VERSION="$2"
else
echo "Invalid arguments. Expected version or directory." >&2
exit 1
fi
fi
BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit"
LATEST_BASHUNIT_VERSION="0.34.0"
TAG="$LATEST_BASHUNIT_VERSION"
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"