Repository navigation
Expand file tree
/
Copy pathbuild_flatpak.sh
More file actions
executable file
·107 lines (94 loc) · 4.13 KB
/
Copy pathbuild_flatpak.sh
File metadata and controls
executable file
·107 lines (94 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
#
# build_flatpak.sh - build a Flatpak of gen1recomp (alongside the RPM).
#
# Reuses the SAME version-stamped game.love that build_rpm.sh produces, so the
# Flatpak and the RPM are always built from an identical archive. It wraps
# the game on top of Flathub's official LÖVE base app (org.love2d.love2d) and
# installs a thin launcher that runs:
# love /app/share/gen1recomp/game.love
#
# Usage:
# ./build_rpm.sh # first: produces build/game-<ver>.love + the RPM
# ./build_flatpak.sh # then: builds the Flatpak for the same version
#
# Prerequisites: flatpak, flatpak-builder, flatpak-runtime-config
# Fedora/Nobara: sudo dnf install -y flatpak flatpak-builder
#
# Output: dist/Gen1Linux-<VERSION>.flatpak
#
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
APP_ID="io.github.hellboundglory.Gen1Linux"
BUILD="$ROOT/build"
DIST="$ROOT/dist"
FLATPAK="$ROOT/flatpak"
STAGE="$FLATPAK/build" # generated sources (gitignored)
MANIFEST="$FLATPAK/$APP_ID.yml"
REPO="$FLATPAK/repo" # local ostree repo (gitignored)
BUILD_DIR="$FLATPAK/build-dir" # flatpak-builder output (gitignored)
FLATHUB="https://dl.flathub.org/repo/flathub.flatpakrepo"
say() { printf '\033[1;32m==>\033[0m %s\n' "$*"; }
fail() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
for bin in flatpak flatpak-builder; do
command -v "$bin" >/dev/null 2>&1 \
|| fail "missing '$bin'. Install: sudo dnf install -y flatpak flatpak-builder"
done
# ------------------------------------------------------------ resolve version
# The Flatpak must match the RPM, so it builds the same game.love build_rpm.sh
# already produced. Default: the newest upstream release tag (as build_rpm.sh).
VERSION="${1:-}"
if [ -z "$VERSION" ]; then
VERSION="$(git -C "$ROOT/gen1recomp" tag -l 'v[0-9]*' 2>/dev/null | sed 's/^v//' | sort -V | tail -1)"
fi
[ -n "$VERSION" ] \
|| fail "could not determine version (is gen1recomp/ cloned?). Build the RPM first, or pass a version."
LOVE="$BUILD/game-$VERSION.love"
[ -f "$LOVE" ] \
|| fail "no game.love at $LOVE. Build it first: ./build_rpm.sh $VERSION"
APP_ICON="$ROOT/gen1recomp/assets/logo/gen1recomp_cover.png"
[ -f "$APP_ICON" ] || fail "could not find the upstream app icon at $APP_ICON"
LICENSE_SRC="$ROOT/gen1recomp/LICENSE.MD"
[ -f "$LICENSE_SRC" ] || LICENSE_SRC="$ROOT/gen1recomp/LICENSE"
[ -f "$LICENSE_SRC" ] || fail "no upstream LICENSE file found"
# ------------------------------------------------------------ stage sources
say "App ID: $APP_ID version: $VERSION"
mkdir -p "$STAGE" "$DIST" "$REPO"
cp -f "$LOVE" "$STAGE/game.love"
cp -f "$LICENSE_SRC" "$STAGE/LICENSE"
# The Flatpak icon must not exceed the hicolor directory size (512x512), so
# resize the upstream 1024x1024 cover with ImageMagick. (Install: dnf/apt
# install imagemagick)
if command -v convert >/dev/null 2>&1; then
say "resizing app icon to 512x512"
convert "$APP_ICON" -resize 512x512 "$STAGE/$APP_ID.png"
else
say "notice: ImageMagick not found, shipping icon at original size"
cp -f "$APP_ICON" "$STAGE/$APP_ID.png"
fi
cat > "$STAGE/$APP_ID.desktop" <<EOF
[Desktop Entry]
Type=Application
Name=gen1recomp
GenericName=Pokémon Gen 1 recompilation
Comment=Native LÖVE2D recreation of Pokémon Red / Blue / Yellow
Exec=gen1recomp
Icon=$APP_ID
Terminal=false
Categories=Game;AdventureGame;RolePlaying;
Keywords=Pokemon;Pokémon;LÖVE;RPG;GBC;
StartupWMClass=love
EOF
# ------------------------------------------------------------ build + bundle
# Make Flathub available so flatpak-builder can pull the runtime, SDK and the
# org.love2d.love2d base (already added in CI/root; --if-not-exists is idempotent).
flatpak remote-add --if-not-exists --user flathub "$FLATHUB"
say "building flatpak (fetches the Freedesktop runtime on first run)"
rm -rf "$BUILD_DIR"
flatpak-builder --user --force-clean --ccache --disable-rofiles-fuse \
--repo="$REPO" --install-deps-from=flathub "$BUILD_DIR" "$MANIFEST"
BUNDLE="$DIST/Gen1Linux-$VERSION.flatpak"
say "bundling $BUNDLE"
flatpak build-bundle --runtime-repo="$FLATHUB" "$REPO" "$BUNDLE" "$APP_ID"
say "done: $BUNDLE"
say "install: flatpak install ./$BUNDLE"