BlueGit

golden-age paperdoll-renderer

Files

paperdoll-renderer / scripts / ci / verify-packages.sh

verify-packages.sh

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