Last active
August 29, 2020 11:54
-
-
Save pastleo/d3d0fd02880dbd9b30647c91d1fdb8f9 to your computer and use it in GitHub Desktop.
update script for https://aur.archlinux.org/packages/docker-rootless-bin/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
require 'net/http' | |
DOC_TEXT = <<-DOC | |
# Get started: | |
git clone ssh://[email protected]/docker-rootless-bin.git | |
cd docker-rootless-bin | |
curl https://gist.githubusercontent.com/pastleo/d3d0fd02880dbd9b30647c91d1fdb8f9/raw/mk_pkgbuild.rb > mk_pkgbuild.rb | |
# Update: | |
ruby mk_pkgbuild.rb PKGBUILD | |
makepkg | |
makepkg --printsrcinfo > .SRCINFO | |
git add --all | |
git commit -m 'update pkgvar with upstream' | |
git push | |
DOC | |
if ARGV.length < 1 | |
puts "Please provide PKGBUILD path" | |
exit 127 | |
end | |
if ['-h', '--help'].include?(ARGV[0]) | |
puts DOC_TEXT | |
exit | |
end | |
pkgbuild_path = ARGV[0] | |
PKGBUILD_TEMPLATE = ERB.new <<-EOF | |
# Maintainer: PastLeo <[email protected]> | |
pkgname=docker-rootless-bin | |
pkgver=<%= pkgver %> | |
pkgrel=1 | |
pkgdesc="Run the Docker daemon as a non-root user (Rootless mode)" | |
arch=('x86_64') | |
url="https://docs.docker.com/engine/security/rootless/" | |
license=('Apache') | |
depends=('docker') | |
provides=('docker-rootless') | |
conflicts=('docker-rootless') | |
install=docker-rootless.install | |
source=( | |
"https://download.docker.com/linux/static/stable/x86_64/docker-rootless-extras-$pkgver.tgz" | |
"docker.service" | |
) | |
md5sums=( | |
"<%= bin_tgz_md5sum %>" | |
"04425cca4e95bf534c41697aeabfcad4" | |
) | |
sha256sums=( | |
"<%= bin_tgz_sha256sum %>" | |
"edf633c42d27e039d5acbb1ead685d6acd66b06786a8552e1bbe5f789dc2c315" | |
) | |
package() { | |
mkdir -p "$pkgdir/usr/bin/" | |
install -Dm755 "$srcdir/docker-rootless-extras/"* "$pkgdir/usr/bin/" | |
install -Dm644 "$srcdir/docker.service" "$pkgdir/usr/lib/systemd/user/docker.service" | |
} | |
EOF | |
BIN_FILENAME_REGEX = /docker-rootless-extras-(\d+)\.(\d+)\.(\d+)\.tgz/ | |
docker_bin_index_html = Net::HTTP.get(URI('https://download.docker.com/linux/static/stable/x86_64/')) | |
latest_versions = | |
docker_bin_index_html.scan(BIN_FILENAME_REGEX).sort do |a, b| | |
a.zip(b).map {|a, b| a.to_i <=> b.to_i }.find {|c| c != 0 } || 0 | |
end.last.join('.') | |
pkgver = latest_versions | |
bin_tgz = "docker-rootless-extras-#{pkgver}.tgz" | |
bin_tgz_url = "https://download.docker.com/linux/static/stable/x86_64/#{bin_tgz}" | |
bin_tgz_tmp = "/tmp/#{bin_tgz}" | |
`curl #{bin_tgz_url} >> #{bin_tgz_tmp}` | |
bin_tgz_md5sum = `md5sum -z #{bin_tgz_tmp}`.strip.split(' ')[0] | |
bin_tgz_sha256sum = `sha256sum -z #{bin_tgz_tmp}`.strip.split(' ')[0] | |
`rm #{bin_tgz_tmp}` | |
File.write( | |
pkgbuild_path, | |
PKGBUILD_TEMPLATE.result(binding) | |
) | |
puts "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment