#!/usr/bin/env bash repo="moncho/dry" current=$(reprepro -b /var/www/repos/apt/debian list stable dry | head -n1 | awk '{print $3}') api=$(curl --silent "https://api.github.com/repos/$repo/releases/latest") new=$(echo $api | grep -Po '"tag_name": "v\K.*?(?=")') if [ "$current" == "$new" ]; then exit fi echo "New DRY version $current -> $new" END="linux" 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 \"$END\" in s['name']))") for bin_url in $bin_urls; do STARTDIR="/tmp/dry" DESTDIR="$STARTDIR/pkg" OUTDIR="$STARTDIR/deb" rm -rf "$STARTDIR" mkdir "$STARTDIR" wget -q $bin_url -O "$STARTDIR/dry" install -Dm 755 "$STARTDIR/dry" "$DESTDIR/usr/bin/dry" mkdir -p "$DESTDIR/DEBIAN" archi=$(echo ${bin_url##*/} | cut -d '-' -f3) [ "$archi" == "386" ] && archi="i386" echo "ARCHI - $archi" cat >"$DESTDIR/DEBIAN/control"< Description: dry - A Docker manager for the terminal Homepage: https://github.com/moncho/dry Bugs: https://github.com/moncho/dry/issues EOL cat >"$STARTDIR/changelog"< $(date -R) EOL install -Dm 644 "$STARTDIR/changelog" "$DESTDIR/usr/share/doc/dry/changelog.Debian" gzip "$DESTDIR/usr/share/doc/dry/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"