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

fix(default-flatpaks): Couldn't resolve host name in some network setups #352

Merged
merged 2 commits into from
Oct 23, 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
48 changes: 42 additions & 6 deletions modules/default-flatpaks/v1/system-flatpak-setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#!/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 3 second interval, to avoid until loop
# Used when adding remotes & when installing flatpaks
check_internet_connection() {
local max_attempts=3
local sleep_time=3
local attempt=1

while [[ ${attempt} -le ${max_attempts} ]]; do
if curl --silent --head --fail "https://fedoraproject.org/static/hotspot.txt" > /dev/null; then
internet_connection=true
return 0
else
internet_connection=false
echo "Internet connection is not available. Waiting..."
sleep ${sleep_time}
attempt=$((attempt + 1))
fi
done

echo "ERROR: Internet connection is not available. Skipping the operation above."
}

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

Expand Down Expand Up @@ -103,8 +126,11 @@ 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"
echo "Note that --if-not-exists flag doesn't prevent the repo from modifying repo URL"
check_internet_connection
if "${internet_connection}"; then
flatpak remote-add --if-not-exists --system "$REPO_NAME" "$REPO_URL"
fi
fi

# If configured remote is flathub, enable it here.
Expand Down Expand Up @@ -189,20 +215,30 @@ if [[ -f $INSTALL_LIST_FILE ]] || [[ -f $USER_INSTALL_LIST_FILE ]]; then
INSTALL_LIST="$COMBINED_INSTALL_LIST"
fi
if [[ -n $INSTALL_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
echo "Installing system flatpaks from config list"
check_internet_connection
if "${internet_connection}"; then
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
fi
elif [[ -n $INSTALL_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
notify-send-pre-install
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send-install
echo "Installing system flatpaks from config list"
check_internet_connection
if "${internet_connection}"; then
notify-send-pre-install
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send-install
fi
fi
fi

# Remove flatpaks in list
if [[ -f $REMOVE_LIST_FILE ]] || [[ -f $USER_REMOVE_LIST_FILE ]]; then
REMOVE_LIST=$(comm -12 <(echo "$COMBINED_REMOVE_LIST" | sort) <(echo "$FLATPAK_LIST" | sort))
if [[ -n $REMOVE_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
echo "Removing system flatpaks from config list"
flatpak uninstall --system --noninteractive ${REMOVE_LIST[@]}
elif [[ -n $REMOVE_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
echo "Removing system flatpaks from config list"
notify-send-pre-uninstall
flatpak uninstall --system --noninteractive ${REMOVE_LIST[@]}
notify-send-uninstall
Expand Down
2 changes: 1 addition & 1 deletion modules/default-flatpaks/v1/system-flatpak-setup.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Type=oneshot
ExecStart=/usr/bin/system-flatpak-setup
Restart=on-failure
RestartSec=30
StartLimitInterval=0
StartLimitInterval=3

[Install]
WantedBy=multi-user.target
46 changes: 41 additions & 5 deletions modules/default-flatpaks/v1/user-flatpak-setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
#!/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 3 second interval, to avoid until loop
# Used when adding remotes & when installing flatpaks
check_internet_connection() {
local max_attempts=3
local sleep_time=3
local attempt=1

while [[ ${attempt} -le ${max_attempts} ]]; do
if curl --silent --head --fail "https://fedoraproject.org/static/hotspot.txt" > /dev/null; then
internet_connection=true
return 0
else
internet_connection=false
echo "Internet connection is not available. Waiting..."
sleep ${sleep_time}
attempt=$((attempt + 1))
fi
done

echo "ERROR: Internet connection is not available. Skipping the operation above."
}

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

Expand Down Expand Up @@ -91,7 +114,10 @@ done
if [[ $REPO_URL != "null" && $REPO_NAME != "null" ]]; then
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"
check_internet_connection
if "${internet_connection}"; then
flatpak remote-add --if-not-exists --user "$REPO_NAME" "$REPO_URL"
fi
fi

# Change repository title to configured title, if not null & if not already changed
Expand Down Expand Up @@ -140,20 +166,30 @@ if [[ -f $INSTALL_LIST_FILE ]] || [[ -f $USER_INSTALL_LIST_FILE ]]; then
INSTALL_LIST="$COMBINED_INSTALL_LIST"
fi
if [[ -n $INSTALL_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
echo "Installing user flatpaks from config list"
check_internet_connection
if "${internet_connection}"; then
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
fi
elif [[ -n $INSTALL_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Started install of user flatpaks" --app-name="Flatpak Installer" -u NORMAL
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send "Flatpak Installer" "Finished install of user flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
echo "Installing user flatpaks from config list"
check_internet_connection
if "${internet_connection}"; then
notify-send "Flatpak Installer" "Started install of user flatpaks" --app-name="Flatpak Installer" -u NORMAL
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send "Flatpak Installer" "Finished install of user flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
fi
fi

# Remove flatpaks in list
if [[ -f $REMOVE_LIST_FILE ]] || [[ -f $USER_REMOVE_LIST_FILE ]]; then
REMOVE_LIST=$(comm -12 <(echo "$COMBINED_REMOVE_LIST" | sort) <(echo "$FLATPAK_LIST" | sort))
if [[ -n $REMOVE_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
echo "Removing user flatpaks from config list"
flatpak uninstall --user --noninteractive ${REMOVE_LIST[@]}
elif [[ -n $REMOVE_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
echo "Removing user flatpaks from config list"
notify-send "Flatpak Installer" "Started uninstall of some user flatpaks" --app-name="Flatpak Installer" -u NORMAL
flatpak uninstall --user --noninteractive ${REMOVE_LIST[@]}
notify-send "Flatpak Installer" "Finished uninstall of user flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
Expand Down
2 changes: 1 addition & 1 deletion modules/default-flatpaks/v1/user-flatpak-setup.service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Type=simple
ExecStart=/usr/bin/user-flatpak-setup
Restart=on-failure
RestartSec=30
StartLimitInterval=0
StartLimitInterval=3

[Install]
WantedBy=default.target