# Generate the `Packages` and `Packages.gz` files
dpkg-scanpackages -m . > Packages
gzip --keep --force -9 Packages


# Generate the Release file
cat conf/distributions > Release
echo -e "Date: `LANG=C date -Ru`" >> Release
# Release must contain MD5 sums of all repository files (in a simple repo just the Packages and Packages.gz files)
echo -e 'MD5Sum:' >> Release
printf ' '$(md5sum Packages.gz | cut --delimiter=' ' --fields=1)' %16d Packages.gz' $(wc --bytes Packages.gz | cut --delimiter=' ' --fields=1) >> Release
printf '\n '$(md5sum Packages | cut --delimiter=' ' --fields=1)' %16d Packages' $(wc --bytes Packages | cut --delimiter=' ' --fields=1) >> Release
# Release must contain SHA256 sums of all repository files (in a simple repo just the Packages and Packages.gz files)
echo -e '\nSHA256:' >> Release
printf ' '$(sha256sum Packages.gz | cut --delimiter=' ' --fields=1)' %16d Packages.gz' $(wc --bytes Packages.gz | cut --delimiter=' ' --fields=1) >> Release
printf '\n '$(sha256sum Packages | cut --delimiter=' ' --fields=1)' %16d Packages' $(wc --bytes Packages | cut --delimiter=' ' --fields=1) >> Release


# Sign the Release file
# The user whomst GPG key needs to be able to write to the `-o` output path.  If you need sudo for 
# this, put `-o` as a temporary path, then use `sudo mv` to put it in the right spot.  Otherwise
# `gpg` will try to use the sudo user's GPG key.
rm InRelease || true
gpg --batch --no-tty --yes  --clearsign -o InRelease Release

# Create the separate Release.gpg file [not sure why this is necessary]
rm Release.gpg || true
gpg -abs -o Release.gpg Release  # Make sure you own the tty.  use `chown [user] $(tty)` if needed; otherwise might say "permission denied" with no other explanation

