dotfiles/agent/get_prymn.sh
2023-07-09 19:58:51 +03:00

63 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
# shellcheck shell=dash
# A simple script that is run on a remote host to download and install the
# agent binary.
set -u
# For Dev: file:///home/nikos/Projects/prymn/agent/target/debug/prymn_agent
GET_PRYMN_ROOT="${GET_PRYMN_ROOT:?You need to set GET_PRYMN_ROOT to the prymn_agent path for now}"
main() {
# Check for dependencies
check_for_command curl
check_for_command mktemp
local dir
if ! dir="$(mktemp -d)"; then
error "mktemp was not executed successfully"
fi
local file="${dir}/prymn_agent"
local url="${GET_PRYMN_ROOT}"
printf "downloading prymn agent...\n" 1>&2
ensure download "${url}" "${file}"
ensure chmod u+x "$file"
# Run the installer
"$file" --install "$@"
local ret=$?
rm "${file}"
rmdir "${dir}"
return $ret
}
download() {
local err
err=$(curl -sSfL "$1" -o "$2" 2>&1)
if [ -n "$err" ]; then
error "$err"
fi
}
error() {
printf "Error: %s\n" "$1" >&2
exit 1
}
check_for_command() {
if ! command -v "$1" > /dev/null 2>&1; then
error "get_prymn.sh requires the program '$1' but it was not found in your system."
fi
}
ensure() {
"$@" || error "failed to execute: $*"
}
main "$@" || exit 1