#!/usr/bin/env bash # Check for available internet connection before proceeding (network-online.target doesn't work for some network connections) # Check it 3 times in 2 second interval, to avoid until loop # Used when adding remotes & when installing flatpaks check_internet_connection() { local max_attempts=3 local sleep_time=2 local attempt=1 while (( attempt <= max_attempts )); do if curl --silent --head --fail "https://fedoraproject.org/static/hotspot.txt" > /dev/null; then return 0 else echo "Internet connection is not available. Waiting..." sleep ${sleep_time} (( attempt++ )) fi done return 1 } # 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_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[@]}" 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) 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 # We cannot compare repo URLs properly # Flatpak outputs repo URL, while we have flatpakref URL, which is not the same no_title_modify=false readarray -t CURRENT_REPO_INFO < <(flatpak remotes --system --columns=name,url,title) for index in "${CURRENT_REPO_INFO[@]}"; do CURRENT_REPO_NAMES+=("$(echo "${index}" | awk '{print $1}')") CURRENT_REPO_TITLES+=("$(echo "${index}" | awk '{ for(i=3;i