2024-09-16 02:23:53 +01:00
|
|
|
#!/bin/sh -e
|
2024-07-14 06:33:35 +01:00
|
|
|
|
2024-09-19 02:49:24 +01:00
|
|
|
# Prevent execution if this script was only partially downloaded
|
|
|
|
{
|
2024-07-14 06:33:35 +01:00
|
|
|
RC='\033[0m'
|
|
|
|
RED='\033[0;31m'
|
|
|
|
|
|
|
|
# Function to fetch the latest release tag from the GitHub API
|
|
|
|
get_latest_release() {
|
2024-08-29 20:58:09 +01:00
|
|
|
latest_release=$(curl -s https://api.github.com/repos/ChrisTitusTech/linutil/releases |
|
|
|
|
grep -oP '"tag_name": "\K[^"]*' |
|
|
|
|
head -n 1)
|
2024-07-14 06:33:35 +01:00
|
|
|
if [ -z "$latest_release" ]; then
|
2024-09-19 22:48:01 +01:00
|
|
|
printf "%b\n" "Error fetching release data" >&2
|
2024-07-14 06:33:35 +01:00
|
|
|
return 1
|
|
|
|
fi
|
2024-09-19 22:48:01 +01:00
|
|
|
printf "%b\n" "$latest_release"
|
2024-07-14 06:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Function to redirect to the latest pre-release version
|
|
|
|
redirect_to_latest_pre_release() {
|
|
|
|
latest_release=$(get_latest_release)
|
|
|
|
if [ -n "$latest_release" ]; then
|
2024-07-18 23:48:54 +01:00
|
|
|
url="https://github.com/ChrisTitusTech/linutil/releases/download/$latest_release/linutil"
|
2024-07-14 06:33:35 +01:00
|
|
|
else
|
2024-09-19 22:48:01 +01:00
|
|
|
printf "%b\n" 'Unable to determine latest pre-release version.' >&2
|
|
|
|
printf "%b\n" "Using latest Full Release"
|
2024-07-14 06:33:35 +01:00
|
|
|
url="https://github.com/ChrisTitusTech/linutil/releases/latest/download/linutil"
|
|
|
|
fi
|
2024-07-30 22:04:46 +01:00
|
|
|
addArch
|
2024-09-19 22:48:01 +01:00
|
|
|
printf "%b\n" "Using URL: $url"
|
2024-07-14 06:33:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
check() {
|
2024-09-19 22:48:01 +01:00
|
|
|
exit_code=$1
|
|
|
|
message=$2
|
2024-07-14 06:33:35 +01:00
|
|
|
|
2024-09-19 22:48:01 +01:00
|
|
|
if [ "$exit_code" -ne 0 ]; then
|
2024-09-16 01:32:37 +01:00
|
|
|
printf "%b\n" "${RED}ERROR: $message${RC}"
|
2024-07-14 06:33:35 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-07-30 22:04:46 +01:00
|
|
|
addArch() {
|
|
|
|
case "${arch}" in
|
|
|
|
x86_64);;
|
|
|
|
*) url="${url}-${arch}";;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
findArch() {
|
|
|
|
case "$(uname -m)" in
|
|
|
|
x86_64|amd64) arch="x86_64" ;;
|
|
|
|
aarch64|arm64) arch="aarch64" ;;
|
|
|
|
*) check 1 "Unsupported architecture"
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
findArch
|
2024-07-14 06:33:35 +01:00
|
|
|
redirect_to_latest_pre_release
|
|
|
|
|
|
|
|
TMPFILE=$(mktemp)
|
|
|
|
check $? "Creating the temporary file"
|
|
|
|
|
2024-09-19 22:48:01 +01:00
|
|
|
printf "%b\n" "Downloading linutil from $url"
|
|
|
|
curl -fsL "$url" -o "$TMPFILE"
|
2024-07-14 06:33:35 +01:00
|
|
|
check $? "Downloading linutil"
|
|
|
|
|
2024-09-19 22:48:01 +01:00
|
|
|
chmod +x "$TMPFILE"
|
2024-07-14 06:33:35 +01:00
|
|
|
check $? "Making linutil executable"
|
|
|
|
|
|
|
|
"$TMPFILE"
|
|
|
|
check $? "Executing linutil"
|
|
|
|
|
2024-09-19 22:48:01 +01:00
|
|
|
rm -f "$TMPFILE"
|
2024-07-18 23:48:54 +01:00
|
|
|
check $? "Deleting the temporary file"
|
2024-09-19 02:49:24 +01:00
|
|
|
} # End of wrapping
|