2022-01-29 21:47:20 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
|
|
|
. "$1"
|
|
|
|
|
|
|
|
if [ -z "$UPSTREAM_ARCHIVE" ]; then exit; fi
|
|
|
|
|
2022-01-30 22:40:03 +00:00
|
|
|
# TODO: Inaccurate.
|
|
|
|
escape_regex() {
|
|
|
|
echo "$1" | sed -E 's,[\\+*?.{}<>],\\\0,g'
|
|
|
|
}
|
|
|
|
|
2022-01-29 21:47:20 +00:00
|
|
|
TAR_REGEX="(\.tar(\.(gz|bz2|xz)))"
|
|
|
|
|
2022-01-30 22:40:03 +00:00
|
|
|
if [ -z "$RELEASE_SEARCH_PAGE" ]; then
|
2022-01-29 21:47:20 +00:00
|
|
|
case "$UPSTREAM_SITE" in
|
|
|
|
https://github.com/*/releases/*)
|
2022-01-30 22:40:03 +00:00
|
|
|
RELEASE_SEARCH_PAGE=$(echo "$UPSTREAM_SITE" | grep -Eo '.*/releases/');;
|
|
|
|
*) RELEASE_SEARCH_PAGE="$UPSTREAM_SITE/";;
|
2022-01-29 21:47:20 +00:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$VERSION_REGEX" ]; then
|
2022-01-30 22:40:03 +00:00
|
|
|
VERSION_REGEX="([0-9]+\.[0-9]+(\.[0-9]+)*)"
|
2022-01-29 21:47:20 +00:00
|
|
|
fi
|
|
|
|
|
2022-01-30 22:40:03 +00:00
|
|
|
if [ -z "$RELEASE_REGEX" ]; then
|
|
|
|
RELEASE_REGEX=$(echo "$UPSTREAM_ARCHIVE" |
|
|
|
|
sed -E 's,\+,\\+,g' |
|
|
|
|
sed -E "s,$VERSION_REGEX(\.tar.*),$(escape_regex "$VERSION_REGEX"),")
|
2022-01-29 21:47:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$UPSTREAM_SITE_TEMPLATE" ]; then
|
|
|
|
UPSTREAM_SITE_TEMPLATE="$UPSTREAM_SITE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$UPSTREAM_ARCHIVE_TEMPLATE" ]; then
|
|
|
|
UPSTREAM_ARCHIVE_TEMPLATE=$(echo "$UPSTREAM_ARCHIVE" |
|
2022-02-01 20:04:18 +00:00
|
|
|
sed -E "s,$VERSION_REGEX(\.tar.*),%v%e,")
|
2022-01-29 21:47:20 +00:00
|
|
|
fi
|
|
|
|
|
2022-01-30 22:40:03 +00:00
|
|
|
if [ -z "$RELEASE_SEARCH_REGEX" ]; then
|
|
|
|
RELEASE_SEARCH_REGEX="\<$RELEASE_REGEX$TAR_REGEX\>"
|
2022-01-29 21:47:20 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$UPSTREAM_ARCHIVE" in
|
|
|
|
*.tar) EXTENSION=.tar;;
|
|
|
|
*.tar.gz) EXTENSION=.tar.gz;;
|
|
|
|
*.tar.bz2) EXTENSION=.tar.bz2;;
|
|
|
|
*.tar.xz) EXTENSION=.tar.xz;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
instantiate() {
|
|
|
|
echo "$1" |
|
|
|
|
sed -E \
|
|
|
|
-e "s,%v,$2,g" \
|
|
|
|
-e "s,%M,$(echo "$2" | sed -E 's,([0-9]+)\.([0-9]+)(\.([0-9]+))?.*,\1,'),g" \
|
|
|
|
-e "s,%m,$(echo "$2" | sed -E 's,([0-9]+)\.([0-9]+)(\.([0-9]+))?.*,\2,'),g" \
|
|
|
|
-e "s,%p,$(echo "$2" | sed -E 's,([0-9]+)\.([0-9]+)(\.([0-9]+))?.*,\4,'),g" \
|
|
|
|
-e "s,%e,$EXTENSION,g"
|
|
|
|
}
|
|
|
|
|
|
|
|
# git tag search
|
|
|
|
|
2022-01-30 22:40:03 +00:00
|
|
|
LATEST=$(curl -Ls "$RELEASE_SEARCH_PAGE" | grep -Eo "$RELEASE_SEARCH_REGEX" | sort -Vu | tail -1)
|
2022-01-29 21:47:20 +00:00
|
|
|
case "$LATEST" in
|
|
|
|
*.tar) EXTENSION=.tar;;
|
|
|
|
*.tar.gz) EXTENSION=.tar.gz;;
|
|
|
|
*.tar.bz2) EXTENSION=.tar.bz2;;
|
|
|
|
*.tar.xz) EXTENSION=.tar.xz;;
|
|
|
|
esac
|
2022-01-30 22:40:03 +00:00
|
|
|
NEW_VERSION="$(echo "$LATEST" | sed -E "s,$RELEASE_SEARCH_REGEX,\1,")"
|
2022-01-29 21:47:20 +00:00
|
|
|
|
|
|
|
if [ -z "$NEW_VERSION" ]; then
|
2022-01-30 22:40:03 +00:00
|
|
|
echo "\e[91m$UPSTREAM_ARCHIVE failed to find available versions: $RELEASE_SEARCH_PAGE | grep -E '$RELEASE_SEARCH_REGEX'\e[m"
|
2022-01-29 21:47:20 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
NEW_UPSTREAM_SITE=$(instantiate "$UPSTREAM_SITE_TEMPLATE" "$NEW_VERSION")
|
|
|
|
NEW_UPSTREAM_ARCHIVE=$(instantiate "$UPSTREAM_ARCHIVE_TEMPLATE" "$NEW_VERSION")
|
|
|
|
|
|
|
|
if ! wget -q "$NEW_UPSTREAM_SITE/$NEW_UPSTREAM_ARCHIVE" -O /dev/null; then
|
|
|
|
echo "\e[91m$NAME failed to download: $NEW_UPSTREAM_SITE/$NEW_UPSTREAM_ARCHIVE\e[m"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$VERSION" != "$NEW_VERSION" ]; then
|
|
|
|
echo "\e[1;92m$NAME $VERSION -> $NEW_VERSION $NEW_UPSTREAM_SITE/$NEW_UPSTREAM_ARCHIVE\e[m"
|
|
|
|
else
|
|
|
|
# Confirmed to actually be up to date.
|
|
|
|
case "$NAME" in
|
|
|
|
flex|gcc|grub|texinfo|libiconv|libtheora|libSDL|libz|nyancat|pkg-config)
|
|
|
|
echo "\e[92m$NAME $VERSION is up to date\e[m"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$NAME $VERSION is up to date"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|