#!/bin/sh set -e . "$1" if [ -z "$UPSTREAM_ARCHIVE" ]; then exit; fi NAME_REGEXP="$(echo "$NAME" | sed -E 's,\+,\\+,g')" case "$NAME" in ag) UPSTREAM_VERSION_PAGE="https://geoff.greer.fm/ag/" ;; bochs) UPSTREAM_VERSION_PAGE="https://sourceforge.net/projects/bochs/files/bochs/" SEARCH_REGEX="([0-9]+\.[0-9]+(\.[0-9]+)*)/" UPSTREAM_SITE_TEMPLATE="https://sourceforge.net/projects/bochs/files/bochs/%v" ;; e2fsprogs) UPSTREAM_VERSION_PAGE="https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/" SEARCH_REGEX="v([0-9]+\.[0-9]+(\.[0-9]+)*)/" UPSTREAM_SITE_TEMPLATE="https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v%v" ;; binutils|gcc|grub|libstdc++) VERSION_REGEX="sortix-$NAME_REGEXP-([0-9]+\.[0-9]+(\.[0-9]+)*(-rc[0-9]+)?)" ;; libcurses) UPSTREAM_SITE="https://ftp.barfooze.de/pub/sabotage/tarballs" ;; libevent) VERSION_REGEX="libevent-([0-9]+\\.[0-9]+(\\.[0-9]+)*-stable)" UPSTREAM_SITE_TEMPLATE="https://github.com/libevent/libevent/releases/download/release-%v" UPSTREAM_ARCHIVE_TEMPLATE="libevent-%v%e" ;; libexpat) UPSTREAM_SITE_TEMPLATE="https://github.com/libexpat/libexpat/releases/download/R_%M_%m_%p" ;; libjpeg) UPSTREAM_SITE="https://www.ijg.org/files" # TODO: The last letter is optional but sort -V before the first release. VERSION_REGEX="jpegsrc.v([0-9]+[a-z])" UPSTREAM_ARCHIVE_TEMPLATE="jpegsrc.v%v%e" ;; libgmp) VERSION_REGEX=$(echo "$UPSTREAM_ARCHIVE" | sed -E 's,([0-9]+\.[0-9]+(\.[0-9]+)*a?)(\.tar.*),([0-9]+\\.[0-9]+(\\.[0-9]+)*a?),') ;; libpcre) UPSTREAM_VERSION_PAGE="https://sourceforge.net/projects/pcre/files/pcre/" SEARCH_REGEX="([0-9]+\.[0-9]+(\.[0-9]+)*)/" UPSTREAM_SITE_TEMPLATE="https://sourceforge.net/projects/pcre/files/pcre/%v" ;; libpng) UPSTREAM_VERSION_PAGE="http://libpng.org/pub/png/libpng.html" # TODO: Switch to this upstream site since it also works for older versions. UPSTREAM_SITE="https://download.sourceforge.net/libpng" ;; nasm) UPSTREAM_VERSION_PAGE="https://www.nasm.us/pub/nasm/releasebuilds/" SEARCH_REGEX="([0-9]+\.[0-9]+(\.[0-9]+)*)/" UPSTREAM_SITE_TEMPLATE="https://www.nasm.us/pub/nasm/releasebuilds/%v" ;; nyancat) UPSTREAM_VERSION_PAGE="https://github.com/klange/nyancat/tags" ;; python) UPSTREAM_VERSION_PAGE="https://www.python.org/downloads/source/" SEARCH_REGEX="Python-([0-9]+\.[0-9]+(\.[0-9]+)*)(\.tar(\.(gz|bz2|xz)))" UPSTREAM_SITE_TEMPLATE="https://www.python.org/ftp/python/%v" ;; esac TAR_REGEX="(\.tar(\.(gz|bz2|xz)))" if [ -z "$UPSTREAM_VERSION_PAGE" ]; then case "$UPSTREAM_SITE" in https://github.com/*/releases/*) UPSTREAM_VERSION_PAGE=$(echo "$UPSTREAM_SITE" | grep -Eo '.*/releases/');; *) UPSTREAM_VERSION_PAGE="$UPSTREAM_SITE/";; esac fi if [ -z "$VERSION_REGEX" ]; then VERSION_REGEX=$(echo "$UPSTREAM_ARCHIVE" | sed -E 's,([0-9]+\.[0-9]+(\.[0-9]+)*)(\.tar.*),([0-9]+\\.[0-9]+(\\.[0-9]+)*),') fi if [ -z "$VERSION" ]; then VERSION=$(echo "$UPSTREAM_ARCHIVE" | sed -E "s,$VERSION_REGEX,\1") 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 "$SEARCH_REGEX" ]; then SEARCH_REGEX="\<$VERSION_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 "$UPSTREAM_VERSION_PAGE" | grep -Eo "$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,$SEARCH_REGEX,\1,")" if [ -z "$NEW_VERSION" ]; then echo "\e[91m$UPSTREAM_ARCHIVE failed to find available versions: $NEW_VERSION_REGEX on $UPSTREAM_VERSION_PAGE\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