diff --git a/.goreleaser-stable.yaml b/.goreleaser-stable.yaml index 5bcd864e0..3a13929d2 100644 --- a/.goreleaser-stable.yaml +++ b/.goreleaser-stable.yaml @@ -99,6 +99,13 @@ nfpms: dst: /usr/bin/kraftld - src: docs/man/ dst: /usr/share/man/man1/ + - src: scripts/cleanup-artifacts.sh + dst: /usr/libexec/kraftkit/cleanup-artifacts + file_info: + mode: 0755 + scripts: + preremove: packaging/deb/prerm + postremove: packaging/deb/postrm aurs: - homepage: https://kraftkit.sh @@ -246,6 +253,11 @@ builds: #@ if bin == "kraft" and os == "linux" and arch == "amd64": - xen #@ end + ignore: + - goos: linux + goarch: 386 + - goos: windows + goarch: 386 #@ end #@ end #@ end diff --git a/.goreleaser-staging.yaml b/.goreleaser-staging.yaml index 4dcfebd8e..69be40588 100644 --- a/.goreleaser-staging.yaml +++ b/.goreleaser-staging.yaml @@ -83,6 +83,13 @@ nfpms: dst: /usr/bin/kraftld - src: docs/man/ dst: /usr/share/man/man1/ + - src: scripts/cleanup-artifacts.sh + dst: /usr/libexec/kraftkit/cleanup-artifacts + file_info: + mode: 0755 + scripts: + preremove: packaging/deb/prerm + postremove: packaging/deb/postrm brews: - name: kraftkit-staging @@ -184,6 +191,11 @@ builds: #@ if bin == "kraft" and os == "linux" and arch == "amd64": - xen #@ end + ignore: + - goos: linux + goarch: 386 + - goos: windows + goarch: 386 #@ end #@ end #@ end diff --git a/packaging/deb/postrm b/packaging/deb/postrm new file mode 100755 index 000000000..ff543fc1c --- /dev/null +++ b/packaging/deb/postrm @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -e + + +# postrm — executed by dpkg AFTER package removal +# +# Debian policy: +# remove --> keep user data +# purge --> remove user data +# +# Therefore we only delete configuration on "purge". +# This allows reinstalling kraftkit without losing settings. +# +# Script MUST NOT fail, dpkg would leave the package in a broken state. +# Always ignore deletion errors. + +case "$1" in + purge) + # User-scoped config directory + rm -rf "$HOME/.config/kraftkit" || true + ;; +esac + +exit 0 diff --git a/packaging/deb/prerm b/packaging/deb/prerm new file mode 100644 index 000000000..9d8273e47 --- /dev/null +++ b/packaging/deb/prerm @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -e + + +# prerm executed BEFORE package removal +# +# Some kraftkit runtimes keep sockets/mounts/artifacts alive. +# If not cleaned, dpkg removal may fail or leave broken state. +# +# We attempt best-effort cleanup but NEVER block uninstall. + +CLEANUP="/usr/libexec/kraftkit/cleanup-artifacts" + +case "$1" in + remove|purge) + if [ -x "$CLEANUP" ]; then + "$CLEANUP" || true + fi + ;; +esac + +exit 0 diff --git a/scripts/cleanup-artifacts.sh b/scripts/cleanup-artifacts.sh new file mode 100755 index 000000000..292434f95 --- /dev/null +++ b/scripts/cleanup-artifacts.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +# cleanup-artifacts +# +# Removes runtime/cache data generated by kraftkit. +# +# Design goals: +# - Idempotent (safe to run multiple times) +# - Works without optional dependencies (yq) +# - Never deletes unintended paths +# - Never fails package uninstall + +CONFIG="${HOME}/.config/kraftkit/config.yaml" + +# Default runtime directories created by KraftKit. +CACHE_DIR="${HOME}/.cache/kraftkit" +DATA_DIR="${HOME}/.local/share/kraftkit" + + +# If a config exists and yq is available, read custom paths. +# Fallback to defaults to ensure cleanup always succeeds. +if [ -f "$CONFIG" ] && command -v yq >/dev/null 2>&1; then + CACHE_DIR="$(yq '.paths.cache // "'"$CACHE_DIR"'"' "$CONFIG")" + DATA_DIR="$(yq '.paths.data // "'"$DATA_DIR"'"' "$CONFIG")" +fi + + +# Safety guards: +# - non empty +# - not root directory +# - ignore missing paths +[ -n "$CACHE_DIR" ] && [ "$CACHE_DIR" != "/" ] && rm -rf -- "$CACHE_DIR" || true +[ -n "$DATA_DIR" ] && [ "$DATA_DIR" != "/" ] && rm -rf -- "$DATA_DIR" || true