Skip to content

Instantly share code, notes, and snippets.

@john-fk-doe
Created April 6, 2024 22:30
Show Gist options
  • Select an option

  • Save john-fk-doe/be546e543d7aeac8bd771bf9a24284a2 to your computer and use it in GitHub Desktop.

Select an option

Save john-fk-doe/be546e543d7aeac8bd771bf9a24284a2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
repo="bcicen/ctop"
current=$(reprepro -b /var/www/repos/apt/debian list stable docker-ctop | 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 DOCKER-CTOP version $current -> $new"
END="ctop-"
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('$END')))" | grep linux)
for bin_url in $bin_urls; do
STARTDIR="/tmp/ctop"
DESTDIR="$STARTDIR/pkg"
OUTDIR="$STARTDIR/deb"
rm -rf "$STARTDIR"
mkdir "$STARTDIR"
wget -q $bin_url -O "$STARTDIR/ctop"
install -Dm 755 "$STARTDIR/ctop" "$DESTDIR/usr/bin/ctop"
mkdir -p "$DESTDIR/DEBIAN"
archi=$(echo $bin_url | cut -d '-' -f4)
if [[ "$bin_url" != *linux* ]]; then
continue
fi
[ "$archi" == "arm" ] && archi="armhf"
echo "ARCHI - $archi"
cat >"$DESTDIR/DEBIAN/control"<<EOL
Package: docker-ctop
Version: $new
Section: net
Priority: optional
Architecture: $archi
Maintainer: Azlux <github@azlux.fr>
Description: Top-like interface for container metrics
Homepage: https://github.com/bcicen/ctop
Bugs: https://github.com/bcicen/ctop/issues
EOL
cat >"$STARTDIR/changelog"<<EOL
package ($new) stable; urgency=medium
Please check the source repo for the full changelog
You can found the link at https://packages.azlux.fr/
-- Azlux <github@azlux.fr> $(date -R)
EOL
install -Dm 644 "$STARTDIR/changelog" "$DESTDIR/usr/share/doc/docker-ctop/changelog.Debian"
gzip "$DESTDIR/usr/share/doc/docker-ctop/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment