linutil/start.sh

52 lines
1.0 KiB
Bash
Raw Normal View History

#!/bin/sh -e
2024-06-29 03:12:23 +01:00
# Prevent execution if this script was only partially downloaded
{
rc='\033[0m'
red='\033[0;31m'
2024-06-29 03:12:23 +01:00
2024-07-07 23:33:47 +01:00
check() {
exit_code=$1
message=$2
2024-06-29 03:12:23 +01:00
if [ "$exit_code" -ne 0 ]; then
printf '%sERROR: %s%s\n' "$red" "$message" "$rc"
2024-07-07 23:33:47 +01:00
exit 1
fi
2024-10-02 20:59:04 +01:00
unset exit_code
unset message
2024-07-07 23:33:47 +01:00
}
2024-06-29 03:12:23 +01:00
findArch() {
case "$(uname -m)" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) check 1 "Unsupported architecture"
esac
}
getUrl() {
case "${arch}" in
x86_64) echo "https://github.com/ChrisTitusTech/linutil/releases/latest/download/linutil";;
*) echo "https://github.com/ChrisTitusTech/linutil/releases/latest/download/linutil-${arch}";;
esac
}
findArch
temp_file=$(mktemp)
2024-07-07 23:33:47 +01:00
check $? "Creating the temporary file"
curl -fsL "$(getUrl)" -o "$temp_file"
2024-07-07 23:33:47 +01:00
check $? "Downloading linutil"
chmod +x "$temp_file"
2024-07-07 23:33:47 +01:00
check $? "Making linutil executable"
"$temp_file" "$@"
2024-07-07 23:33:47 +01:00
check $? "Executing linutil"
rm -f "$temp_file"
2024-07-07 23:33:47 +01:00
check $? "Deleting the temporary file"
} # End of wrapping