Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(default-flatpaks): Improve reliability of Fedora flatpaks removal & logging/debugging #345

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 81 additions & 18 deletions modules/default-flatpaks/v1/system-flatpak-setup
Original file line number Diff line number Diff line change
@@ -1,22 +1,81 @@
#!/usr/bin/env bash

# Opt out of and remove Fedora's flatpak repo
if grep -qz 'fedora' <<< "$(flatpak remotes)"; then
/usr/bin/gnome-software --quit
/usr/lib/fedora-third-party/fedora-third-party-opt-out
/usr/bin/fedora-third-party disable
flatpak remote-delete fedora --force
flatpak remote-delete fedora-testing --force

# Remove flatpak apps from origin fedora
FEDORA_FLATPAKS=$(flatpak list --app --columns=application,origin | grep -w 'fedora' | awk '{print $1}')
flatpak remove --system --noninteractive ${FEDORA_FLATPAKS[@]}

# Remove flatpak runtimes from origin fedora
FEDORA_FLATPAKS=$(flatpak list --runtime --columns=application,arch,branch,origin | grep -w 'fedora' | awk '{print $1"/"$2"/"$3}')
flatpak remove --system --noninteractive ${FEDORA_FLATPAKS[@]}
# Opt out of and remove Fedora's system flatpak repos
FLATPAK_SYSTEM_REMOTES=($(flatpak --system remotes))

fedora_system=false
fedora_testing_system=false

for system_remote in "${FLATPAK_SYSTEM_REMOTES[@]}"; do
if [[ "${system_remote}" == "fedora" ]]; then
fedora_system=true
elif [[ "${system_remote}" == "fedora-testing" ]]; then
fedora_testing_system=true
fi
done

if rpm -q fedora-third-party &>/dev/null; then
if [[ ! "$(fedora-third-party query)" == *"disabled." ]]; then
echo "Disabling Fedora third-party repos..."
/usr/bin/gnome-software --quit
/usr/lib/fedora-third-party/fedora-third-party-opt-out
/usr/bin/fedora-third-party disable
else
echo "Fedora third-party repos are already disabled"
fi
else
echo "ERROR: Cannot opt-out from Fedora third-party repos, because fedora-third-party package is not installed"
fi

if "${fedora_system}"; then
echo "Removing system flatpak remote 'fedora'"
flatpak remote-delete --system fedora --force
else
echo "System flatpak remote 'fedora' is already removed"
fi
if "${fedora_system_testing}"; then
echo "Removing system flatpak remote 'fedora-testing'"
flatpak remote-delete --system fedora-testing --force
else
echo "System flatpak remote 'fedora-testing' is already removed"
fi

# Remove flatpak apps from system origin fedora
FEDORA_FLATPAKS_APP=($(flatpak list --system --app --columns=application,origin | awk '$2 == "fedora" {print $1}'))
if [[ ${#FEDORA_FLATPAKS_APP[@]} -gt 0 ]]; then
echo "Removing system flatpak apps from 'fedora' remote"
flatpak remove --system --noninteractive "${FEDORA_FLATPAKS_APP[@]}"
else
echo "System flatpak apps from 'fedora' remote are already removed"
fi

# Remove flatpak runtimes from system origin fedora
FEDORA_FLATPAKS_RUNTIME=($(flatpak list --system --runtime --columns=application,arch,branch,origin | awk '$4 == "fedora" {print $1"/"$2"/"$3}'))
if [[ ${#FEDORA_FLATPAKS_RUNTIME[@]} -gt 0 ]]; then
echo "Removing system flatpak runtimes from 'fedora' remote"
flatpak remove --system --noninteractive "${FEDORA_FLATPAKS_RUNTIME[@]}"
else
echo "System flatpak runtimes from 'fedora' remote are already removed"
fi

# Remove flatpak apps from system origin fedora-testing
FEDORA_TESTING_FLATPAKS_APP=($(flatpak list --system --app --columns=application,origin | awk '$2 == "fedora-testing" {print $1}'))
if [[ ${#FEDORA_TESTING_FLATPAKS_APP[@]} -gt 0 ]]; then
echo "Removing system flatpak apps from 'fedora-testing' remote"
flatpak remove --system --noninteractive "${FEDORA_TESTING_FLATPAKS_APP[@]}"
else
echo "System flatpak apps from 'fedora-testing' remote are already removed"
fi

# Remove flatpak runtimes from system origin fedora-testing
FEDORA_TESTING_FLATPAKS_RUNTIME=($(flatpak list --system --runtime --columns=application,arch,branch,origin | awk '$4 == "fedora-testing" {print $1"/"$2"/"$3}'))
if [[ ${#FEDORA_TESTING_FLATPAKS_RUNTIME[@]} -gt 0 ]]; then
echo "Removing system flatpak runtimes from 'fedora-testing' remote"
flatpak remove --system --noninteractive "${FEDORA_TESTING_FLATPAKS_RUNTIME[@]}"
else
echo "System flatpak runtimes from 'fedora-testing' remote are already removed"
fi

REPO_INFO="/usr/share/bluebuild/default-flatpaks/system/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
Expand All @@ -43,20 +102,24 @@ done
# Set up system-wide Flatpak repository
if [[ $REPO_URL != "null" && $REPO_NAME != "null" ]]; then
echo "Adding system-wide remote $REPO_NAME from $REPO_URL"
echo "Note that --if-not-exists flag doesn't prevent the repo from modifying repo URL"
flatpak remote-add --if-not-exists --system "$REPO_NAME" "$REPO_URL"
fi

# If configured remote is flathub, enable it here.
# Flathub is already installed on Fedora, but not enabled by default,
# Flathub is already installed in Fedora, but not enabled by default,
# so the above command won't add it again
if [[ $REPO_NAME == "flathub" ]]; then
echo "Enabling specified 'flathub' remote, that is already installed, but disabled in Fedora"
flatpak remote-modify --system "$REPO_NAME" --enable
fi

# Change repository title to configured title, if not null
# Change repository title to configured title, if not null & if not already changed
if [[ $REPO_TITLE != "null" ]] && ! ${no_title_modify}; then
echo "Setting title $REPO_TITLE for remote $REPO_NAME"
flatpak remote-modify --system "$REPO_NAME" --title="$REPO_TITLE"
echo "Setting title $REPO_TITLE for remote $REPO_NAME"
elif [[ $REPO_TITLE != "null" ]] && ${no_title_modify}; then
echo "Custom flatpak remote title is already set"
fi

# Notifications config
Expand Down
70 changes: 65 additions & 5 deletions modules/default-flatpaks/v1/user-flatpak-setup
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
#!/usr/bin/env bash

# Remove Fedora's flatpak repo, if it exists
if grep -qz 'fedora' <<< "$(flatpak remotes)"; then
# Remove Fedora's flatpak user repos, if they exist
FLATPAK_USER_REMOTES=($(flatpak --user remotes))

fedora_user=false
fedora_testing_user=false

for user_remote in "${FLATPAK_USER_REMOTES[@]}"; do
if [[ "${user_remote}" == "fedora" ]]; then
fedora_user=true
elif [[ "${user_remote}" == "fedora-testing" ]]; then
fedora_testing_user=true
fi
done

if "${fedora_user}"; then
echo "Removing user flatpak remote 'fedora'"
flatpak remote-delete --user fedora --force
else
echo "User flatpak remote 'fedora' is already removed"
fi
if "${fedora_system_testing}"; then
echo "Removing flatpak remote 'fedora-testing'"
flatpak remote-delete --user fedora-testing --force
else
echo "User flatpak remote 'fedora-testing' is already removed"
fi

# Remove flatpak apps from user origin fedora
FEDORA_FLATPAKS_APP=($(flatpak list --user --app --columns=application,origin | awk '$2 == "fedora" {print $1}'))
if [[ ${#FEDORA_FLATPAKS_APP[@]} -gt 0 ]]; then
echo "Removing user flatpak apps from 'fedora' remote"
flatpak remove --user --noninteractive "${FEDORA_FLATPAKS_APP[@]}"
else
echo "User flatpak apps from 'fedora' remote are already removed"
fi

# Remove flatpak runtimes from user origin fedora
FEDORA_FLATPAKS_RUNTIME=($(flatpak list --user --runtime --columns=application,arch,branch,origin | awk '$4 == "fedora" {print $1"/"$2"/"$3}'))
if [[ ${#FEDORA_FLATPAKS_RUNTIME[@]} -gt 0 ]]; then
echo "Removing user flatpak runtimes from 'fedora' remote"
flatpak remove --user --noninteractive "${FEDORA_FLATPAKS_RUNTIME[@]}"
else
echo "User flatpak runtimes from 'fedora' remote are already removed"
fi

# Remove flatpak apps from origin user origin fedora-testing
FEDORA_TESTING_FLATPAKS_APP=($(flatpak list --user --app --columns=application,origin | awk '$2 == "fedora-testing" {print $1}'))
if [[ ${#FEDORA_TESTING_FLATPAKS_APP[@]} -gt 0 ]]; then
echo "Removing user flatpak apps from 'fedora-testing' remote"
flatpak remove --user --noninteractive "${FEDORA_TESTING_FLATPAKS_APP[@]}"
else
echo "User flatpak apps from 'fedora-testing' remote are already removed"
fi

# Remove flatpak runtimes from user origin fedora-testing
FEDORA_TESTING_FLATPAKS_RUNTIME=($(flatpak list --user --runtime --columns=application,arch,branch,origin | awk '$4 == "fedora-testing" {print $1"/"$2"/"$3}'))
if [[ ${#FEDORA_TESTING_FLATPAKS_RUNTIME[@]} -gt 0 ]]; then
echo "Removing user flatpak runtimes from 'fedora-testing' remote"
flatpak remove --user --noninteractive "${FEDORA_TESTING_FLATPAKS_RUNTIME[@]}"
else
echo "User flatpak runtimes from 'fedora-testing' remote are already removed"
fi

REPO_INFO="/usr/share/bluebuild/default-flatpaks/user/repo-info.yml"
REPO_URL=$(yq '.repo-url' $REPO_INFO)
REPO_NAME=$(yq '.repo-name' $REPO_INFO)
Expand All @@ -31,14 +88,17 @@ done

# Set up per-user Flatpak repository
if [[ $REPO_URL != "null" && $REPO_NAME != "null" ]]; then
echo "Adding remote $REPO_NAME from $REPO_URL"
echo "Adding remote $REPO_NAME from $REPO_URL"
echo "Note that --if-not-exists flag doesn't prevent the repo from modifying repo URL"
flatpak remote-add --if-not-exists --user "$REPO_NAME" "$REPO_URL"
fi

# Change repository title to configured title, if not null
# Change repository title to configured title, if not null & if not already changed
if [[ $REPO_TITLE != "null" ]] && ! ${no_title_modify}; then
flatpak remote-modify --user "$REPO_NAME" --title="$REPO_TITLE"
echo "Setting title $REPO_TITLE for remote $REPO_NAME"
flatpak remote-modify --user "$REPO_NAME" --title="$REPO_TITLE"
elif [[ $REPO_TITLE != "null" ]] && ${no_title_modify}; then
echo "Custom flatpak remote title is already set"
fi

# Notifications config
Expand Down