installer/adapters/flatpak-import.sh

45 lines
2 KiB
Bash

#!/bin/bash
# Prototype: called from live installation, after OSTree deployment.
# The seed is ISO content; no seed repository is retained in immutable /usr.
set -euo pipefail
seed=$1
destination=$2
test "$EUID" = 0
test -d "$seed/.ostree/repo"
test -f "$seed/SHA256SUMS"
(cd "$seed"; sha256sum --quiet --check SHA256SUMS)
test ! -e "$destination" || { echo 'Flatpak destination must be fresh' >&2; exit 1; }
mkdir -p /etc/flatpak/installations.d
name=archipelago-installer-$$
config=/etc/flatpak/installations.d/$name.conf
trap 'rm -f "$config"' EXIT
printf '[Installation "%s"]\nPath=%s\nDisplayName=Archipelago installation target\n' "$name" "$destination" > "$config"
chmod 0600 "$config"
# Namespace isolation makes this a local-media import, not a network fallback.
unshare --net /bin/bash -euo pipefail -s -- "$name" "$seed" "$destination" <<'IMPORT'
name=$1
seed=$2
destination=$3
flatpak --installation="$name" remote-add flathub "$seed/flathub.flatpakrepo"
flatpak --installation="$name" remote-modify --collection-id=org.flathub.Stable flathub
flatpak --installation="$name" config --set languages '*'
mapfile -t apps < <(python3 - "$seed/policy.json" <<'PY'
import json,sys
p=json.load(open(sys.argv[1]))
assert p['delivery']=='installation-media'
for ref in p['applications']:
assert ref.startswith(('app/org.gnome.', 'app/org.kde.')) and ref.endswith('/x86_64/stable')
print(ref)
PY
)
test "${#apps[@]}" -gt 0
flatpak --installation="$name" install --noninteractive --assumeyes --sideload-repo="$seed/.ostree/repo" flathub "${apps[@]}"
for ref in "${apps[@]}"; do flatpak --installation="$name" info "$ref"; done
# Do not accept an import that retained commit bytes but lost detached signatures.
# This also covers auto-installed runtime extensions rather than apps alone.
mapfile -t imported < <(ostree --repo="$destination/repo" refs | grep -E '^flathub:(app|runtime)/')
test "${#imported[@]}" -gt 0
for ref in "${imported[@]}"; do
ostree --repo="$destination/repo" show --gpg-verify-remote=flathub "$ref" >/dev/null
done
IMPORT