| 1 | #!/usr/bin/env bash |
| 2 | # Reject a package that is the wrong kind of file. A Linux executable copied |
| 3 | # into the Windows archive must not pass. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 7 | cd "$root" |
| 8 | mkdir -p dist |
| 9 | |
| 10 | appimage="dist/paperdoll-renderer-x86_64.AppImage" |
| 11 | deb="dist/paperdoll-renderer_amd64.deb" |
| 12 | arch="dist/paperdoll-renderer-x86_64.pkg.tar.zst" |
| 13 | windows="dist/paperdoll-renderer-windows-x86_64.zip" |
| 14 | |
| 15 | require_file() { |
| 16 | local path="$1" |
| 17 | if [[ ! -s "$path" ]]; then |
| 18 | echo "missing or empty artifact: $path" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | } |
| 22 | |
| 23 | magic_prefix() { |
| 24 | # Print the first bytes as hex, without spaces. |
| 25 | od -An -tx1 -N "$2" "$1" | tr -d ' \n' |
| 26 | } |
| 27 | |
| 28 | require_file "$appimage" |
| 29 | require_file "$deb" |
| 30 | require_file "$arch" |
| 31 | require_file "$windows" |
| 32 | |
| 33 | # AppImage 1.9 type 2 images are ELF binaries and contain the AppImage marker. |
| 34 | if [[ "$(magic_prefix "$appimage" 4)" != "7f454c46" ]]; then |
| 35 | echo "AppImage is not an ELF" >&2 |
| 36 | exit 1 |
| 37 | fi |
| 38 | if ! grep -a -q "AppImage" "$appimage"; then |
| 39 | echo "AppImage marker missing" >&2 |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | # Debian packages are ar archives. |
| 44 | if [[ "$(magic_prefix "$deb" 8)" != "213c617263683e0a" ]]; then |
| 45 | echo "deb is not an ar archive" >&2 |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | # zstd frame magic. |
| 50 | if [[ "$(magic_prefix "$arch" 4)" != "28b52ffd" ]]; then |
| 51 | echo "Arch package is not zstd" >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | # Zip local-file header, a PE executable name, and no ELF header at the start. |
| 56 | if [[ "$(magic_prefix "$windows" 4)" != "504b0304" ]]; then |
| 57 | echo "Windows artifact is not a zip" >&2 |
| 58 | exit 1 |
| 59 | fi |
| 60 | if ! grep -a -q "paperdoll-renderer.exe" "$windows"; then |
| 61 | echo "Windows zip does not name paperdoll-renderer.exe" >&2 |
| 62 | exit 1 |
| 63 | fi |
| 64 | if [[ "$(magic_prefix "$windows" 4)" == "7f454c46" ]]; then |
| 65 | echo "Windows zip starts with an ELF header" >&2 |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | sha256sum "$appimage" "$deb" "$arch" "$windows" | tee dist/SHA256SUMS |
| 70 | echo "package artifacts verified" |