#!/usr/bin/env bash repo="RasmusLindroth/tut" current=$(reprepro -b /var/www/repos/apt/debian list stable tut | head -n1 | awk '{print $3}') api=$(curl --silent "https://api.github.com/repos/$repo/releases/latest") new=$(echo $api | grep -Po '"tag_name": "\K.*?(?=")') if [ "$current" == "$new" ]; then exit fi echo "New TUT version $current -> $new" START="tut" END="static" bin_urls=$(echo $api | python3 -c "import sys; from json import loads as l; x = l(sys.stdin.read()); print(' '.join(s['browser_download_url'] for s in x['assets'] if (s['name'].startswith('$START') and s['name'].endswith('$END'))))") for bin_url in $bin_urls; do STARTDIR="/tmp/tut" DESTDIR="$STARTDIR/pkg" OUTDIR="$STARTDIR/deb" rm -rf "$STARTDIR" mkdir "$STARTDIR" wget -q $bin_url -O "$STARTDIR/tut" install -Dm 755 "$STARTDIR/tut" "$DESTDIR/usr/bin/tut" mkdir -p "$DESTDIR/DEBIAN" archi=$(echo $bin_url | cut -d '-' -f2) [ "$archi" == "386" ] && archi="i386" [ "$archi" == "arm" ] && archi="armhf" echo "ARCHI - $archi" cat >"$DESTDIR/DEBIAN/control"< Description: a Mastodon TUI Homepage: https://github.com/RasmusLindroth/tut Bugs: https://github.com/RasmusLindroth/tut/issues EOL cat >"$STARTDIR/changelog"< $(date -R) EOL install -Dm 644 "$STARTDIR/changelog" "$DESTDIR/usr/share/doc/tut/changelog.Debian" gzip "$DESTDIR/usr/share/doc/tut/changelog.Debian" rm -rf "$OUTDIR" mkdir "$OUTDIR" dpkg-deb --build "$DESTDIR" "$OUTDIR" reprepro -b /var/www/repos/apt/debian includedeb stable "$OUTDIR"/*.deb reprepro -b /var/www/repos/apt/debian includedeb oldstable "$OUTDIR"/*.deb done rm -rf "$STARTDIR"