Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packaging/download-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
set -euo pipefail

readonly REPOSITORY='larslaskowski/pimonitor'
# Restrict both the initial request and any redirect to HTTPS, so a
# compromised or misconfigured server can't downgrade the download to plain
# HTTP.
readonly CURL=(curl -fsSL --proto '=https' --proto-redir '=https')

if [[ -z "${ARCH:-}" ]]; then
case "$(uname -m)" in
Expand Down Expand Up @@ -35,14 +39,14 @@ case "${ARCH:-}" in
;;
esac

for command in curl wget tar; do
for command in curl tar; do
if ! command -v "$command" >/dev/null 2>&1; then
printf 'Required command not found: %s\n' "$command" >&2
exit 1
fi
done

version=$(curl -fsSL "https://api.github.com/repos/${REPOSITORY}/releases/latest" \
version=$("${CURL[@]}" "https://api.github.com/repos/${REPOSITORY}/releases/latest" \
| awk -F '"' '/"tag_name"/ { print $4; exit }')

if [[ -z "$version" ]]; then
Expand All @@ -61,7 +65,7 @@ if [[ -e "$directory" ]]; then
fi

printf 'Downloading PiMonitor %s for %s ...\n' "$version" "$ARCH"
wget --no-clobber "$url"
"${CURL[@]}" -o "$archive" "$url"

printf 'Extracting %s ...\n' "$archive"
tar xzf "$archive"
Expand Down