warp4j/install

111 lines
2.4 KiB
Plaintext
Raw Normal View History

2019-02-14 18:42:45 +01:00
#!/usr/bin/env bash
# install location
LOCATION=/usr/local/bin
# exit top level program from subshell
trap "exit 1" TERM
export TOP_PID=$$
function fail() {
kill -s TERM $TOP_PID
}
2019-02-14 18:42:45 +01:00
# platform IDs
LIN=linux
LIN_URL=https://git.kirby-link.dd-dns.de/attachments/f701fbff-c58b-4aac-91e3-47efda1fc760
2019-02-14 18:42:45 +01:00
MAC=macos
MAC_URL=https://git.kirby-link.dd-dns.de/attachments/b09c6469-406a-4dd1-b5e8-1294a3aabf0f
2019-02-14 18:42:45 +01:00
WIN=windows
# returns this platform ID
function get_this_platform() {
local this_platform="$(uname -s)"
case $this_platform in
Linux*) echo $LIN ;;
Darwin*) echo $MAC ;;
*)
echo "Error: Unsupported platform $this_platform" >&2
fail
;;
esac
}
# actually sets this platform
THIS_PLATFORM=$(get_this_platform)
# fetches latest release download link for the platform
function get_warp_link() {
2019-02-14 18:42:45 +01:00
local this_platform=$1
if [ "$this_platform" = "$LIN" ]; then
echo "$LIN_URL"
else
echo "$MAC_URL"
fi
2019-02-14 18:42:45 +01:00
}
# downloads and installs single binary
function install() {
local name=$1
local link=$2
local temp_location="/tmp/$name"
echo "Downloading $name..."
curl -fsSL -o "$temp_location" "$link"
if [[ $? != 0 ]]; then
echo "Error: Failed to download $name" >&2
fail
2019-02-14 18:42:45 +01:00
fi
echo "Creating $LOCATION/$name..."
sudo install -D \
--mode=755 \
--owner=root \
--group=root \
"$temp_location" "$LOCATION"
2019-02-14 18:42:45 +01:00
if [[ $? != 0 ]]; then
echo "Error: Failed to install $name" >&2
fail
2019-02-14 18:42:45 +01:00
fi
}
# returns missing dependencies
function get_missing_deps() {
local deps=(
"awk" \
"curl" \
2019-02-16 16:46:39 +01:00
"file" \
"grep" \
"sed" \
"sort" \
"tar" \
"unzip" \
"zip" \
)
for d in ${deps[@]}; do
if ! command -v $d &> /dev/null ; then
echo -n "$d "
fi
done
}
WARP4J_LINK="https://git.kirby-link.dd-dns.de/public/warp4j/raw/branch/master/warp4j"
2019-02-14 18:42:45 +01:00
echo "Getting information about warp-packer releases..."
WARP_LINK=$(get_warp_link $THIS_PLATFORM)
2019-02-14 18:42:45 +01:00
MISSING_DEPS=$(get_missing_deps)
2019-02-14 18:42:45 +01:00
install "warp-packer" "$WARP_LINK" && \
install "warp4j" "$WARP4J_LINK"
if [[ -z $MISSING_DEPS ]]; then
echo "Successfully installed"
else
echo "Main tools successfully installed"
echo "Please install following with your package manager:"
for d in ${MISSING_DEPS[@]}; do
echo -n "$d "
done
echo
exit 1
fi