-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
86 lines (64 loc) · 2.51 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
: ==========================================
: Introduction
: ==========================================
# This script is greatly inspired by the Firebase CLI install script
# which you can find at: https://firebase.tools/
: ==========================================
: Source Code
: ==========================================
# Convenience function
panic() {
echo "❌ Error: $1"
exit 1
}
# For info about why we place the binary at this location, see
# https://unix.stackexchange.com/a/8658
INSTALL_DIR="/usr/local/bin"
# In order for the user to be able to actually run the "ci-tools" command
# without specifying the absolute location, the INSTALL_DIR path must
# be present inside of the PATH environment variable.
echo "🛠 Checking the PATH variable..."
if [[ ! ":$PATH:" == *":$INSTALL_DIR:"* ]]; then
panic "
It looks like $INSTALL_DIR isn't on your PATH.
Please add the following line to either your ~/.profile or ~/.bash_profile, then restart your terminal.
PATH=\$PATH:$INSTALL_DIR
For more information about modifying PATHs, see https://unix.stackexchange.com/a/26059
"
fi
# We need to ensure that the INSTALL_DIR exists.
sudo mkdir -p "$INSTALL_DIR"
echo "💻 Checking the machine type..."
# We use "tr" to translate the uppercase "uname" output into lowercase
UNAME=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ "$UNAME" != "linux" ]; then
panic "this operating system is not supported"
fi
# If version was not given, default to latest version
if [ -z "$CI_TOOLS_VERSION" ]; then
RELEASE_URL="https://github.com/inkldev/ci-tools/releases/latest/download/ci-tools"
else
RELEASE_URL="https://github.com/inkldev/ci-tools/releases/download/v$CI_TOOLS_VERSION/ci-tools"
fi
BIN_FILE="$INSTALL_DIR/ci-tools"
echo "📥 Downloading binary from '$RELEASE_URL' to '$BIN_FILE'"
sudo curl "$RELEASE_URL" \
--output "$BIN_FILE" \
--location \
--progress-bar
# Once the download is complete, we mark the binary file as readable
# and executable (+rx).
echo "🔑 Setting permissions on binary..."
sudo chmod +rx "$BIN_FILE"
# Get the version to test if the command has been successfully installed
VERSION=$(ci-tools --version)
# If no version is detected then clearly the binary failed to install for some reason
if [ -z "$VERSION" ]; then
panic "failed to get binary version"
fi
# Since we've gotten this far we know everything succeeded. We'll just
# let the developer know everything is ready and take our leave.
echo "✅ ci-tools v$VERSION is now installed"
echo "🎉 All Done!"
exit 0