Skip to content

Commit

Permalink
fix(default-flatpaks): Allow usage of Fedora flatpak remote (#359)
Browse files Browse the repository at this point in the history
* fix(default-flatpaks): Allow usage of Fedora flatpak remote

* docs(default-flatpaks): Some further clarifications for retaining Fedora flatpak remote
  • Loading branch information
fiftydinar authored Nov 12, 2024
1 parent d58fa1e commit 1d72437
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
4 changes: 3 additions & 1 deletion modules/default-flatpaks/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `default-flatpaks`

The `default-flatpaks` module can be used to install or uninstall Flatpaks from a configurable remote on every boot. It skips that operation if no changes are detected. This module first removes the Fedora Flatpaks remote and Flatpaks that come pre-installed in Fedora. A Flatpak remote is configured the first time the module is used, but it can be re-configured in subsequent usages of the module. If no Flatpak remote is specified, the module will default to using Flathub.
The `default-flatpaks` module can be used to install or uninstall Flatpaks from a configurable remote on every boot. It skips that operation if no changes are detected. This module, first removes the Fedora Flatpaks remote and Flatpaks that come pre-installed in Fedora (unless Fedora remote is strictly specified in recipe). A Flatpak remote is configured the first time the module is used, but it can be re-configured in subsequent usages of the module. If no Flatpak remote is specified, the module will default to using Flathub.

Flatpaks can either be installed system-wide or per-user. Per-user Flatpaks will be installed separately for every user on a system. Previously-installed flatpaks can also be removed.

Expand All @@ -20,6 +20,8 @@ This module stores the Flatpak remote configuration and Flatpak install/remove l

This module also supports disabling & enabling notifications. If not specified in the recipe, notifications are disabled by default.

If you wish to continue the use of Fedora flatpak remote & it's installed apps on booted system, you just need to specify the remote in the recipe (`repo-name` + `repo-url`) & remote + all apps won't be removed (note that only `fedora` remote is supported, while `fedora-testing` isn't). When you do that, you can further customize flatpaks you want to install or remove from Fedora flatpak remote.

## Local modification

If a local user is not satisfied with default Flatpak installations and removals in the image, it is possible for them to make modifications to the default configuration through the configuration files located within this directory:
Expand Down
60 changes: 37 additions & 23 deletions modules/default-flatpaks/v1/system-flatpak-setup
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ check_internet_connection() {
return 1
}

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)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)

# Opt out of and remove Fedora's system flatpak repos
FLATPAK_SYSTEM_REMOTES=($(flatpak --system remotes))

Expand Down Expand Up @@ -48,36 +53,50 @@ 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
# Remove fedora system remote, unless fedora remote is strictly specified
if [[ ! "${REPO_URL}" == "oci+https://registry.fedoraproject.org" ]]; then
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
else
echo "System flatpak remote 'fedora' is already removed"
echo "Not removing the system flatpak remote 'fedora', as it's specified for use in config"
fi

if "${fedora_testing_system}"; 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[@]}"
# Remove flatpak apps from system origin fedora, unless fedora remote is strictly specified
if [[ ! "${REPO_URL}" == "oci+https://registry.fedoraproject.org" ]]; then
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
else
echo "System flatpak apps from 'fedora' remote are already removed"
fi
echo "Not automatically removing all flatpak apps from system remote 'fedora', as it's specified for use in config"
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[@]}"
# Remove flatpak runtimes from system origin fedora, unless fedora remote is strictly specified
if [[ ! "${REPO_URL}" == "oci+https://registry.fedoraproject.org" ]]; then
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
else
echo "System flatpak runtimes from 'fedora' remote are already removed"
fi
echo "Not automatically removing all flatpak runtimes from system remote 'fedora', as it's specified for use in config"
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}'))
Expand All @@ -97,11 +116,6 @@ 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)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)

# General conditions for not running the unnecessary flatpak setup
# Currently, we don't modify remote title if it's already modified
# Flatpak add remote is ran for some reason, even with --if-not-exists flag, apparently, it modifies the URL
Expand Down
58 changes: 36 additions & 22 deletions modules/default-flatpaks/v1/user-flatpak-setup
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ check_internet_connection() {
return 1
}

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)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)

# Remove Fedora's flatpak user repos, if they exist
FLATPAK_USER_REMOTES=($(flatpak --user remotes))

Expand All @@ -35,12 +40,18 @@ for user_remote in "${FLATPAK_USER_REMOTES[@]}"; do
fi
done

if "${fedora_user}"; then
echo "Removing user flatpak remote 'fedora'"
flatpak remote-delete --user fedora --force
# Remove fedora user remote, unless fedora remote is strictly specified
if [[ ! "${REPO_URL}" == "oci+https://registry.fedoraproject.org" ]]; then
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
else
echo "User flatpak remote 'fedora' is already removed"
echo "Not removing the user flatpak remote 'fedora', as it's specified for use in config"
fi

if "${fedora_testing_user}"; then
echo "Removing user flatpak remote 'fedora-testing'"
flatpak remote-delete --user fedora-testing --force
Expand All @@ -49,22 +60,30 @@ else
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[@]}"
if [[ ! "${REPO_URL}" == "oci+https://registry.fedoraproject.org" ]]; then
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
else
echo "User flatpak apps from 'fedora' remote are already removed"
fi
echo "Not automatically removing all flatpak apps from user remote 'fedora', as it's specified for use in config"
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[@]}"
# Remove flatpak runtimes from user origin fedora, unless fedora remote is strictly specified
if [[ ! "${REPO_URL}" == "oci+https://registry.fedoraproject.org" ]]; then
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
else
echo "User flatpak runtimes from 'fedora' remote are already removed"
fi
echo "Not automatically removing all flatpak runtimes from user remote 'fedora', as it's specified for use in config"
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}'))
Expand All @@ -84,11 +103,6 @@ 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)
REPO_TITLE=$(yq '.repo-title' $REPO_INFO)

# General conditions for not running the unnecessary flatpak setup
# Currently, we don't modify remote title if it's already modified
# Flatpak add remote is ran for some reason, even with --if-not-exists flag, apparently, it modifies the URL
Expand Down

0 comments on commit 1d72437

Please sign in to comment.