2019-02-14 18:42:45 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# install location
|
|
|
|
LOCATION=/usr/local/bin
|
|
|
|
|
2019-02-14 19:34:50 +01:00
|
|
|
# exit top level program from subshell
|
|
|
|
trap "exit 1" TERM
|
|
|
|
export TOP_PID=$$
|
2024-05-20 11:52:27 +02:00
|
|
|
fail() {
|
2019-02-14 19:34:50 +01:00
|
|
|
kill -s TERM $TOP_PID
|
|
|
|
}
|
|
|
|
|
2019-02-14 18:42:45 +01:00
|
|
|
# platform IDs
|
|
|
|
LIN=linux
|
|
|
|
MAC=macos
|
|
|
|
WIN=windows
|
2024-05-20 08:57:25 +02:00
|
|
|
# Urls
|
|
|
|
LIN_X64_URL=https://git.phoenix.ipv64.de/public/warp/releases/download/1.0.0/linux-x64.warp-packer
|
|
|
|
LIN_AARCH64_URL=https://git.phoenix.ipv64.de/public/warp/releases/download/1.0.0/linux-aarch64.warp-packer
|
|
|
|
MAC_URL=https://git.phoenix.ipv64.de/public/warp/releases/download/1.0.0/macos-x64.warp-packer
|
|
|
|
|
|
|
|
# platform architecture
|
|
|
|
X64=x64
|
|
|
|
AARCH64=aarch64
|
2019-02-14 18:42:45 +01:00
|
|
|
|
|
|
|
# returns this platform ID
|
2024-05-20 11:52:27 +02:00
|
|
|
get_this_platform() {
|
2019-02-14 18:42:45 +01:00
|
|
|
local this_platform="$(uname -s)"
|
|
|
|
case $this_platform in
|
|
|
|
Linux*) echo $LIN ;;
|
|
|
|
Darwin*) echo $MAC ;;
|
|
|
|
*)
|
|
|
|
echo "Error: Unsupported platform $this_platform" >&2
|
|
|
|
fail
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-05-20 08:57:25 +02:00
|
|
|
# returns this platform architecture
|
2024-05-20 11:52:27 +02:00
|
|
|
get_this_architecture() {
|
2024-05-20 08:57:25 +02:00
|
|
|
local this_machine="$(uname -m)"
|
|
|
|
case $this_machine in
|
|
|
|
x86_64) echo $X64 ;;
|
|
|
|
aarch64) echo $AARCH64 ;;
|
|
|
|
*)
|
|
|
|
fail_with "Unsupported machine $this_machine"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2019-02-14 18:42:45 +01:00
|
|
|
# actually sets this platform
|
|
|
|
THIS_PLATFORM=$(get_this_platform)
|
|
|
|
|
2024-05-20 08:57:25 +02:00
|
|
|
# actually sets this architecture
|
|
|
|
THIS_ARCHITECTURE=$(get_this_architecture)
|
|
|
|
|
2019-02-14 18:42:45 +01:00
|
|
|
# fetches latest release download link for the platform
|
2024-05-20 11:52:27 +02:00
|
|
|
get_warp_link() {
|
2019-02-14 18:42:45 +01:00
|
|
|
local this_platform=$1
|
2024-05-20 08:57:25 +02:00
|
|
|
local this_architecture=$2
|
2022-08-12 18:40:09 +02:00
|
|
|
|
|
|
|
if [ "$this_platform" = "$LIN" ]; then
|
2024-05-20 08:57:25 +02:00
|
|
|
echo "$LIN_URL"
|
|
|
|
if [ "$this_architecture" = "$X64" ]; then
|
|
|
|
echo "$LIN_X64_URL"
|
|
|
|
else
|
|
|
|
echo "$LIN_AARCH64_URL"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$MAC_URL"
|
|
|
|
fi
|
2019-02-14 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# downloads and installs single binary
|
2024-05-20 11:52:27 +02:00
|
|
|
install() {
|
2019-02-14 18:42:45 +01:00
|
|
|
local name=$1
|
|
|
|
local link=$2
|
|
|
|
local temp_location="/tmp/$name"
|
|
|
|
echo "Downloading $name..."
|
2024-05-20 09:26:10 +02:00
|
|
|
curl -fsSL -o $temp_location $link
|
2024-05-20 11:52:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2019-02-14 18:42:45 +01:00
|
|
|
echo "Error: Failed to download $name" >&2
|
2019-02-14 19:34:50 +01:00
|
|
|
fail
|
2019-02-14 18:42:45 +01:00
|
|
|
fi
|
2019-02-15 10:32:49 +01:00
|
|
|
echo "Creating $LOCATION/$name..."
|
2024-05-20 15:23:42 +02:00
|
|
|
su -c "install -D \
|
2019-02-15 10:32:49 +01:00
|
|
|
--mode=755 \
|
|
|
|
--owner=root \
|
|
|
|
--group=root \
|
2024-05-20 15:23:42 +02:00
|
|
|
'$temp_location' '$LOCATION'"
|
2024-05-20 11:52:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2019-02-14 18:42:45 +01:00
|
|
|
echo "Error: Failed to install $name" >&2
|
2019-02-14 19:34:50 +01:00
|
|
|
fail
|
2019-02-14 18:42:45 +01:00
|
|
|
fi
|
2024-05-20 09:26:10 +02:00
|
|
|
rm $temp_location
|
2019-02-14 18:42:45 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 10:31:04 +01:00
|
|
|
# returns missing dependencies
|
2024-05-20 11:52:27 +02:00
|
|
|
get_missing_deps() {
|
|
|
|
if ! command -v awk > /dev/null 2<&1; then
|
|
|
|
echo -n "awk "
|
|
|
|
fi
|
|
|
|
if ! command -v curl > /dev/null 2<&1; then
|
|
|
|
echo -n "curl "
|
|
|
|
fi
|
|
|
|
if ! command -v file > /dev/null 2<&1; then
|
|
|
|
echo -n "file "
|
|
|
|
fi
|
|
|
|
if ! command -v grep > /dev/null 2<&1; then
|
|
|
|
echo -n "grep "
|
|
|
|
fi
|
|
|
|
if ! command -v sed > /dev/null 2<&1; then
|
|
|
|
echo -n "sed "
|
|
|
|
fi
|
|
|
|
if ! command -v sort > /dev/null 2<&1; then
|
|
|
|
echo -n "sort "
|
|
|
|
fi
|
|
|
|
if ! command -v tar > /dev/null 2<&1; then
|
|
|
|
echo -n "tar "
|
|
|
|
fi
|
|
|
|
if ! command -v unzip > /dev/null 2<&1; then
|
|
|
|
echo -n "unzip "
|
|
|
|
fi
|
|
|
|
if ! command -v zip > /dev/null 2<&1; then
|
|
|
|
echo -n "zip"
|
|
|
|
fi
|
2019-02-15 10:31:04 +01:00
|
|
|
}
|
|
|
|
|
2024-05-11 09:09:28 +02:00
|
|
|
WARP4J_LINK="https://git.phoenix.ipv64.de/public/warp4j/raw/branch/master/warp4j"
|
2019-02-14 18:42:45 +01:00
|
|
|
|
|
|
|
echo "Getting information about warp-packer releases..."
|
2024-05-20 08:57:25 +02:00
|
|
|
WARP_LINK=$(get_warp_link $THIS_PLATFORM $THIS_ARCHITECTURE)
|
2019-02-14 18:42:45 +01:00
|
|
|
|
2019-02-15 10:31:04 +01:00
|
|
|
MISSING_DEPS=$(get_missing_deps)
|
|
|
|
|
2019-02-14 18:42:45 +01:00
|
|
|
install "warp-packer" "$WARP_LINK" && \
|
2019-02-15 10:31:04 +01:00
|
|
|
install "warp4j" "$WARP4J_LINK"
|
|
|
|
|
2024-05-20 11:52:27 +02:00
|
|
|
if [ -z "$MISSING_DEPS" ]; then
|
2019-02-15 10:31:04 +01:00
|
|
|
echo "Successfully installed"
|
|
|
|
else
|
|
|
|
echo "Main tools successfully installed"
|
|
|
|
echo "Please install following with your package manager:"
|
2024-05-20 11:52:27 +02:00
|
|
|
echo $MISSING_DEPS
|
2019-02-15 10:31:04 +01:00
|
|
|
exit 1
|
|
|
|
fi
|