From f367bbe2989dd361b49bc86035f8fd361b714e23 Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Sun, 13 Sep 2026 21:47:32 -0400 Subject: [PATCH] Clean /usr/bin install: contents dir 'lib' + install.sh --- .gitea/workflows/build.yml | 6 ++- packaging/install.sh | 81 ++++++++++++++++++++++++++++++++++++++ psp-preserve.spec | 3 +- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100755 packaging/install.sh diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 2005908..5d2f773 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -25,7 +25,11 @@ jobs: run: pyinstaller --clean --noconfirm psp-preserve.spec - name: Package tarball - run: tar -czf psp-preserve-linux-x86_64.tar.gz -C dist psp-preserve + run: | + cp packaging/install.sh dist/psp-preserve/ + cp packaging/psp-preserve.desktop dist/psp-preserve/ + cp img/app-icon.png dist/psp-preserve/ + tar -czf psp-preserve-linux-x86_64.tar.gz -C dist psp-preserve - uses: actions/upload-artifact@v3 with: diff --git a/packaging/install.sh b/packaging/install.sh new file mode 100755 index 0000000..a118df6 --- /dev/null +++ b/packaging/install.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# Install the PSP Preservation Tool to a system prefix. +# +# FHS-friendly layout: +# $PREFIX/bin/psp-preserve symlink -> payload binary +# $PREFIX/lib/psp-preserve/ app payload (binary + lib/) +# $PREFIX/share/applications/ desktop entry +# $PREFIX/share/icons/hicolor/256x256/apps/ app icon +# +# The PyInstaller onedir build keeps the executable and its `lib/` contents +# directory side by side, so both live under $PREFIX/lib/psp-preserve/ and a +# symlink exposes the binary at $PREFIX/bin/psp-preserve. +# +# Usage (run from inside the extracted tarball): +# sudo ./install.sh # install to /usr/local (default) +# sudo ./install.sh --prefix=/usr # install to /usr +# sudo ./install.sh --uninstall # remove from the default prefix +set -eu + +PREFIX=/usr/local +MODE=install + +for arg in "$@"; do + case "$arg" in + --prefix=*) PREFIX=${arg#--prefix=} ;; + --uninstall) MODE=uninstall ;; + *) echo "unknown argument: $arg" >&2; exit 2 ;; + esac +done + +SRC_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) +LIBDIR="$PREFIX/lib/psp-preserve" +BINDIR="$PREFIX/bin" +APPDIR="$PREFIX/share/applications" +ICONDIR="$PREFIX/share/icons/hicolor/256x256/apps" +APP_BIN="$LIBDIR/psp-preserve" + +require_root() { + if [ "$(id -u)" -ne 0 ]; then + echo "run as root (e.g. sudo)" >&2 + exit 1 + fi +} + +uninstall() { + rm -f "$BINDIR/psp-preserve" + rm -f "$APPDIR/psp-preserve.desktop" + rm -f "$ICONDIR/psp-preserve.png" + rm -rf "$LIBDIR" + echo "Uninstalled from $PREFIX" +} + +if [ "$MODE" = uninstall ]; then + require_root + uninstall + exit 0 +fi + +require_root + +# The tarball ships these next to this script. +for f in psp-preserve lib psp-preserve.desktop app-icon.png; do + if [ ! -e "$SRC_DIR/$f" ]; then + echo "missing $f (run install.sh from inside the extracted tarball)" >&2 + exit 1 + fi +done + +mkdir -p "$LIBDIR" "$BINDIR" "$APPDIR" "$ICONDIR" +rm -rf "$LIBDIR" +mkdir -p "$LIBDIR" +cp -a "$SRC_DIR/psp-preserve" "$LIBDIR/psp-preserve" +cp -a "$SRC_DIR/lib" "$LIBDIR/lib" +install -m 0644 "$SRC_DIR/psp-preserve.desktop" "$APPDIR/psp-preserve.desktop" +install -m 0644 "$SRC_DIR/app-icon.png" "$ICONDIR/psp-preserve.png" +ln -sfn "$APP_BIN" "$BINDIR/psp-preserve" + +echo "Installed to $PREFIX" +echo " binary: $BINDIR/psp-preserve -> $APP_BIN" +echo " payload: $LIBDIR" +echo " desktop: $APPDIR/psp-preserve.desktop" diff --git a/psp-preserve.spec b/psp-preserve.spec index 38726ea..5e86452 100644 --- a/psp-preserve.spec +++ b/psp-preserve.spec @@ -2,7 +2,7 @@ """PyInstaller spec: build the PSP Preservation Tool (onedir). Bundles the read-only resources (DATs, PS1 loader, offline cover bundles, -icons) under ``_internal/`` next to the executable. User-writable data +icons) under ``lib/`` next to the executable. User-writable data (credentials, manual covers, PS1 templates, NPS cache, library DB, cover cache) lives in the OS state dir at runtime — see ``app/config.py``. @@ -63,4 +63,5 @@ coll = COLLECT( strip=False, upx=False, name="psp-preserve", + contents_directory="lib", )