#!/bin/sh set -e . "$1" if [ -z "$UPSTREAM_ARCHIVE" ]; then exit; fi # TODO: Inaccurate. escape_regex() { echo "$1" | sed -E 's,[\\+*?.{}<>],\\\0,g' } TAR_REGEX="(\.tar(\.(gz|bz2|xz)))" if [ -z "$RELEASE_SEARCH_PAGE" ]; then case "$UPSTREAM_SITE" in https://github.com/*/releases/*) RELEASE_SEARCH_PAGE=$(echo "$UPSTREAM_SITE" | grep -Eo '.*/releases/');; *) RELEASE_SEARCH_PAGE="$UPSTREAM_SITE/";; esac fi if [ -z "$VERSION_REGEX" ]; then VERSION_REGEX="([0-9]+\.[0-9]+(\.[0-9]+)*)" fi if [ -z "$RELEASE_REGEX" ]; then RELEASE_REGEX=$(echo "$UPSTREAM_ARCHIVE" | sed -E 's,\+,\\+,g' | sed -E "s,$VERSION_REGEX(\.tar.*),$(escape_regex "$VERSION_REGEX"),") 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" | sed -E 's,([0-9]+\.[0-9]+(\.[0-9]+)*)(\.tar.*),%v%e,') fi if [ -z "$RELEASE_SEARCH_REGEX" ]; then RELEASE_SEARCH_REGEX="\<$RELEASE_REGEX$TAR_REGEX\>" 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 LATEST=$(curl -Ls "$RELEASE_SEARCH_PAGE" | grep -Eo "$RELEASE_SEARCH_REGEX" | sort -Vu | tail -1) case "$LATEST" in *.tar) EXTENSION=.tar;; *.tar.gz) EXTENSION=.tar.gz;; *.tar.bz2) EXTENSION=.tar.bz2;; *.tar.xz) EXTENSION=.tar.xz;; esac NEW_VERSION="$(echo "$LATEST" | sed -E "s,$RELEASE_SEARCH_REGEX,\1,")" if [ -z "$NEW_VERSION" ]; then echo "\e[91m$UPSTREAM_ARCHIVE failed to find available versions: $RELEASE_SEARCH_PAGE | grep -E '$RELEASE_SEARCH_REGEX'\e[m" 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