Skip to content

Instantly share code, notes, and snippets.

@monorkin
Last active October 18, 2024 08:54
Show Gist options
  • Save monorkin/a76ad79a85a1033a69be5ae245e487b7 to your computer and use it in GitHub Desktop.
Save monorkin/a76ad79a85a1033a69be5ae245e487b7 to your computer and use it in GitHub Desktop.
Hey email snap to Arch package update script
require "digest"
require "json"
require "net/http"
require "pathname"
require "shellwords"
require "tempfile"
MAX_REDIRECTS = 10
URL = URI("https://api.snapcraft.io/v2/snaps/info/hey-mail")
HEADERS = { "Snap-Device-Series" => "16" }
info = JSON.parse(Net::HTTP.get(URL, HEADERS))
channel = info["channel-map"].find do |channel|
channel.dig("channel", "architecture") == "amd64" &&
channel.dig("channel", "risk") == "stable" &&
channel.dig("channel", "track") == "latest"
end
if channel.nil?
$stderr.puts "Channel not found"
$stderr.puts info
exit 1
end
version = channel["version"]
download_url = channel["download"]["url"]
snapname = Pathname.new(URI(download_url).path).basename.to_s
sha256sum = ""
sha512sum = ""
sha256 = Digest::SHA256.new
sha512 = Digest::SHA512.new
running = true
redirect_count = 0
current_download_url = download_url
while running do
if redirect_count > MAX_REDIRECTS
$stderr.puts "Too many redirects while downloading the file"
exit 2
end
puts "Attempting to download #{current_download_url}"
Net::HTTP.get_response(URI(current_download_url)) do |response|
if response.is_a?(Net::HTTPRedirection)
puts "Redirecting to #{response["location"]}"
redirect_count += 1
current_download_url = response["location"]
elsif response.is_a?(Net::HTTPSuccess)
puts "Downloading #{current_download_url}"
response.read_body do |chunk|
sha256 << chunk
sha512 << chunk
end
running = false
end
end
end
sha256sum = sha256.hexdigest
sha512sum = sha512.hexdigest
pkgbuild = format(
DATA.read,
version: Shellwords.shellescape(version),
snapname: Shellwords.shellescape(snapname),
download_url: Shellwords.shellescape(download_url),
sha256sum: Shellwords.shellescape(sha256sum),
sha512sum: Shellwords.shellescape(sha512sum)
)
File.write("PKGBUILD", pkgbuild)
puts "Done!"
puts "Run `makepkg -si` to build and install the package"
__END__
# This file was auto-generated using update.rb
# Do not make manual modifications to it use update.rb instead
pkgname=hey-mail-bin
pkgver=%{version}
pkgrel=1
pkgdesc="Hey Mail desktop app"
url="https://hey.com/apps/"
arch=('x86_64')
license=('Proprietary')
depends=('c-ares' 'ffmpeg' 'gtk3' 'http-parser' 'libevent' 'libvpx' 'libxslt' 'libxss' 'minizip' 'nss' 're2' 'snappy' 'libnotify' 'libappindicator-gtk2' 'libappindicator-gtk3')
makedepends=('squashfs-tools')
provides=('hey-mail')
conflicts=('hey-mail')
SNAPNAME="%{snapname}"
source=("%{download_url}")
sha256sums=('%{sha256sum}')
sha512sums=('%{sha512sum}')
build() {
unsquashfs -force -dest root $SNAPNAME
}
package() {
install -d "$pkgdir/usr/bin"
install -d "$pkgdir/opt/hey-mail"
install -d "$pkgdir/usr/share/applications"
cp -r root/* "$pkgdir/opt/hey-mail"
rm -rf "$pkgdir/opt/hey-mail/usr"
rm -rf "$pkgdir/opt/hey-mail/gnome-platform"
rm -rf "$pkgdir/opt/hey-mail/lib"
rm -rf "$pkgdir/opt/hey-mail/libvulkan.so"
rm -rf "$pkgdir/opt/hey-mail/libGLESv2.so"
rm -rf "$pkgdir/opt/hey-mail/libEGL.so"
ln -s /opt/hey-mail/hey-mail "$pkgdir/usr/bin/hey-mail"
sed "s/\${SNAP}/\/opt\/hey-mail/" root/meta/gui/hey-mail.desktop > "$pkgdir/usr/share/applications/hey-mail.desktop"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment