#!/usr/bin/env bash repo="orf/gping" current=$(reprepro -b /var/www/repos/apt/debian list stable gping | head -n1 | awk '{print $3}') api=$(curl --silent "https://api.github.com/repos/$repo/releases/latest") new=$(echo $api | grep -Po '"tag_name": "\S*-?v\K.*?(?=")') if [ "$current" == "$new" ]; then exit fi echo "New GPING version $current -> $new" declare -A dist dist['amd64']='-Linux-x86_64.tar.gz' dist['armhf']='unknown-linux-gnueabihf.tar.gz' dist['arm64']='aarch64-unknown-linux-gnu.tar.gz' for entry in "${!dist[@]}"; do END="${dist[$entry]}" bin_url=$(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'].endswith('$END')))") man_url=$(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']=='gping.1'))") STARTDIR="/tmp/gping" DESTDIR="$STARTDIR/pkg" OUTDIR="$STARTDIR/deb" rm -rf "$STARTDIR" mkdir "$STARTDIR" wget -q $bin_url -O "$STARTDIR/gping.tar.gz" wget -q $man_url -O "$STARTDIR/gping.1" tar xf "$STARTDIR/gping.tar.gz" -C "$STARTDIR" install -Dm 755 "$STARTDIR/gping" "$DESTDIR/usr/bin/gping" install -D -g 0 -o 0 -m 0644 "$STARTDIR/gping.1" "$DESTDIR/usr/local/man/man1/gping.1" mkdir -p "$DESTDIR/DEBIAN" cat >"$DESTDIR/DEBIAN/control"< Description: Ping, but with a graph Homepage: https://github.com/orf/gping Bugs: https://github.com/orf/gping/issues EOL cat >"$STARTDIR/changelog"< $(date -R) EOL install -Dm 644 "$STARTDIR/changelog" "$DESTDIR/usr/share/doc/gping/changelog.Debian" gzip "$DESTDIR/usr/share/doc/gping/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 rm -rf "$STARTDIR" done