Crafter.Review/packaging/flatpak/prune-base.sh

41 lines
1.7 KiB
Shell
Raw Normal View History

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#
# The base app, net.catcrafts.CrafterBuild, brings Crafter.Build's whole
# toolchain into /app so this project can be built inside flatpak-builder.
# The shipped app keeps what crafter-review runs on and nothing else: a list
# of what stays rather than of what goes, so whatever a newer base adds goes
# without anyone having to know about it.
set -eu
cd /app
keep() {
case "$1" in
bin | bin/crafter-review | bin/node | bin/npm | bin/npx | bin/rg) return 0 ;;
lib | lib/node | lib/node/*) return 0 ;;
# What a binary built by the base's crafter-build links through its
# /app/lib rpath.
lib/libc++.so.1* | lib/libc++abi.so.1* | lib/libunwind.so.1*) return 0 ;;
# Split into the .Debug extension at export.
lib/debug | lib/debug/*) return 0 ;;
share | share/crafter-review | share/crafter-review/*) return 0 ;;
# Named, not whole: the base's CrafterBuild metainfo and licences go.
share/metainfo | share/metainfo/net.catcrafts.CrafterReview.metainfo.xml) return 0 ;;
share/licenses | share/licenses/net.catcrafts.CrafterReview | share/licenses/net.catcrafts.CrafterReview/*) return 0 ;;
manifest*.json) return 0 ;;
esac
return 1
}
# Depth first: a directory comes after its contents, and goes only once it
# is empty.
find . -mindepth 1 -depth | sed 's|^\./||' | while IFS= read -r path; do
keep "$path" && continue
if [ -d "$path" ] && [ ! -L "$path" ]; then
rmdir "$path" 2>/dev/null || true
else
rm -f "$path"
fi
done
rm -f share/crafter-review/prune-base.sh