Fix partial upgrade, temp dir handling, and idempotency bugs

- Use pacman -Syu instead of -Sy to prevent partial upgrades (Arch footgun)
- Run manual AUR build in subshell to avoid leaving cwd in temp dir
- Use append_if_missing for flatpak.conf instead of overwriting
- Show warning on test Flatpak install failure instead of silent suppression

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
28allday 2026-03-28 11:57:14 +00:00
parent 3df9b6b64b
commit 6b29690b99

View file

@ -51,7 +51,12 @@ if ! have pacman; then echo "This script is for Arch/Arch-based systems."; exit
# xdg-desktop-portal-gtk: GTK fallback portal for dialogs # xdg-desktop-portal-gtk: GTK fallback portal for dialogs
# xdg-desktop-portal-hyprland: Hyprland-specific portal (screen sharing, window picking) # xdg-desktop-portal-hyprland: Hyprland-specific portal (screen sharing, window picking)
# desktop-file-utils: Provides update-desktop-database for app menu integration # desktop-file-utils: Provides update-desktop-database for app menu integration
sudo pacman -Sy --noconfirm #
# We use -Syu (full system upgrade) rather than just -Sy because syncing
# the package database without upgrading can cause partial upgrades on Arch,
# where newly installed packages link against library versions that aren't
# installed yet. This is a well-known Arch footgun.
sudo pacman -Syu --noconfirm
need base-devel need base-devel
need git need git
need flatpak need flatpak
@ -79,9 +84,8 @@ elif have paru; then
paru -S --noconfirm cosmic-store-git paru -S --noconfirm cosmic-store-git
else else
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
git -C "$tmp" clone https://aur.archlinux.org/cosmic-store-git.git git clone https://aur.archlinux.org/cosmic-store-git.git "$tmp/cosmic-store-git"
cd "$tmp/cosmic-store-git" (cd "$tmp/cosmic-store-git" && makepkg -si --noconfirm)
makepkg -si --noconfirm
fi fi
# Create a wrapper script that sets XDG_CURRENT_DESKTOP=Hyprland before # Create a wrapper script that sets XDG_CURRENT_DESKTOP=Hyprland before
@ -124,10 +128,10 @@ EOF
# 1. ~/.config/environment.d/flatpak.conf — picked up by systemd user session # 1. ~/.config/environment.d/flatpak.conf — picked up by systemd user session
# 2. ~/.config/hypr/hyprland.conf — picked up by Hyprland directly # 2. ~/.config/hypr/hyprland.conf — picked up by Hyprland directly
mkdir -p "$HOME/.config/environment.d" mkdir -p "$HOME/.config/environment.d"
cat > "$HOME/.config/environment.d/flatpak.conf" <<'EOF' FLATPAK_ENV="$HOME/.config/environment.d/flatpak.conf"
XDG_DATA_DIRS=%h/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share touch "$FLATPAK_ENV"
XDG_CURRENT_DESKTOP=Hyprland append_if_missing "XDG_DATA_DIRS=%h/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share" "$FLATPAK_ENV"
EOF append_if_missing "XDG_CURRENT_DESKTOP=Hyprland" "$FLATPAK_ENV"
HYPR_CFG="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/hyprland.conf" HYPR_CFG="${XDG_CONFIG_HOME:-$HOME/.config}/hypr/hyprland.conf"
append_if_missing "env = XDG_CURRENT_DESKTOP,Hyprland" "$HYPR_CFG" append_if_missing "env = XDG_CURRENT_DESKTOP,Hyprland" "$HYPR_CFG"
@ -159,7 +163,7 @@ systemctl --user restart xdg-desktop-portal-hyprland xdg-desktop-portal || true
# Install GNOME Calculator as a quick test to verify Flatpak is working. # Install GNOME Calculator as a quick test to verify Flatpak is working.
# If this succeeds, the full Flatpak pipeline is functional and you can # If this succeeds, the full Flatpak pipeline is functional and you can
# install any app from COSMIC Store or the command line. # install any app from COSMIC Store or the command line.
flatpak install -y flathub org.gnome.Calculator || true flatpak install -y flathub org.gnome.Calculator || warn "Test Flatpak install failed (non-fatal — you can install apps manually)"
cat <<'EONOTE' cat <<'EONOTE'