Skip to content

Commit 3c60559

Browse files
authored
Merge pull request #1 from githedgehog/add_fabric_tester_testfab
adding testfab (fabric tester) installer file.
2 parents 16aae75 + a9a28dd commit 3c60559

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

testfab

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The Hedgehog Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# The install script is based off of the Helm v3 install script:
18+
# https://github.com/helm/helm/blob/main/scripts/get-helm-3
19+
20+
: ${BINARY_NAME:="testfab"}
21+
: ${USE_SUDO:="true"}
22+
: ${DEBUG:="false"}
23+
: ${INSTALL_DIR:="/usr/local/bin"}
24+
: ${TAG:="latest"}
25+
26+
HAS_ORAS="$(type "oras" &> /dev/null && echo true || echo false)"
27+
28+
# initArch discovers the architecture for this system.
29+
initArch() {
30+
ARCH=$(uname -m)
31+
case $ARCH in
32+
armv5*) ARCH="armv5";;
33+
armv6*) ARCH="armv6";;
34+
armv7*) ARCH="arm";;
35+
aarch64) ARCH="arm64";;
36+
x86) ARCH="386";;
37+
x86_64) ARCH="amd64";;
38+
i686) ARCH="386";;
39+
i386) ARCH="386";;
40+
esac
41+
}
42+
43+
# initOS discovers the operating system for this system.
44+
initOS() {
45+
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
46+
47+
case "$OS" in
48+
# Minimalist GNU for Windows
49+
mingw*|cygwin*) OS='windows';;
50+
esac
51+
}
52+
53+
# runs the given command as root (detects if we are root already)
54+
runAsRoot() {
55+
HOME=${HOME:-/tmp}
56+
if [ $EUID -ne 0 -a "$USE_SUDO" = "true" ]; then
57+
sudo HOME=$HOME "${@}"
58+
else
59+
HOME=$HOME "${@}"
60+
fi
61+
}
62+
63+
# verifySupported checks that the os/arch combination is supported for
64+
# binary builds, as well whether or not necessary tools are present.
65+
verifySupported() {
66+
local supported="linux-amd64"
67+
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
68+
echo "No prebuilt binary for ${OS}-${ARCH}."
69+
echo "To build from source, go to https://github.com/githedgehog/testfab"
70+
exit 1
71+
fi
72+
73+
if [ "${HAS_ORAS}" != "true" ] ; then
74+
echo "Oras required, you can install it by running: curl -fsSL https://i.hhdev.io/oras | bash"
75+
exit 1
76+
fi
77+
}
78+
79+
installFile() {
80+
runAsRoot oras pull -o /usr/local/bin/ ghcr.io/githedgehog/testfab:"${TAG}"
81+
runAsRoot chmod +x /usr/local/bin/testfab
82+
83+
echo "$BINARY_NAME installed into $INSTALL_DIR/$BINARY_NAME"
84+
}
85+
86+
# Execution
87+
88+
#Stop execution on any error
89+
set -e
90+
set -o pipefail
91+
92+
# Set debug if desired
93+
if [ "${DEBUG}" == "true" ]; then
94+
set -x
95+
fi
96+
97+
initArch
98+
initOS
99+
verifySupported
100+
installFile

0 commit comments

Comments
 (0)