fix(default-flatpaks): Make notifications be more reliable by delaying service start for 30s & cleaner internet-related logs

This commit is contained in:
fiftydinar 2024-10-25 19:13:53 +02:00 committed by GitHub
parent ca9a840072
commit 247a99e42a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 68 additions and 55 deletions

View file

@ -9,6 +9,9 @@ cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup /usr/bin/system-
cp -r "$MODULE_DIRECTORY"/default-flatpaks/user-flatpak-setup /usr/bin/user-flatpak-setup
cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup.service /usr/lib/systemd/system/system-flatpak-setup.service
cp -r "$MODULE_DIRECTORY"/default-flatpaks/user-flatpak-setup.service /usr/lib/systemd/user/user-flatpak-setup.service
cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup.timer /usr/lib/systemd/system/system-flatpak-setup.timer
cp -r "$MODULE_DIRECTORY"/default-flatpaks/user-flatpak-setup.timer /usr/lib/systemd/user/user-flatpak-setup.timer
configure_flatpak_repo () {
CONFIG_FILE=$1
@ -146,8 +149,8 @@ check_flatpak_id_validity_from_flathub () {
echo "Enabling flatpaks module"
mkdir -p /usr/share/bluebuild/default-flatpaks/{system,user}
mkdir -p /etc/bluebuild/default-flatpaks/{system,user}
systemctl enable -f system-flatpak-setup.service
systemctl enable -f --global user-flatpak-setup.service
systemctl enable -f system-flatpak-setup.timer
systemctl enable -f --global user-flatpak-setup.timer
# Check that `system` is present before configuring. Also copy template list files before writing Flatpak IDs.
if [[ ! $(echo "$1" | yq -I=0 ".system") == "null" ]]; then

View file

@ -1,26 +1,24 @@
#!/usr/bin/env bash
# Check for available internet connection before proceeding (network-online.target doesn't work for some network connections)
# Check it 5 times in 3 second interval, to avoid until loop
# 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=5
local sleep_time=3
local max_attempts=3
local sleep_time=2
local attempt=1
while [[ ${attempt} -le ${max_attempts} ]]; do
while (( attempt <= max_attempts )); do
if curl --silent --head --fail "https://fedoraproject.org/static/hotspot.txt" > /dev/null; then
internet_connection=true
return 0
return 0
else
internet_connection=false
echo "Internet connection is not available. Waiting..."
sleep ${sleep_time}
attempt=$((attempt + 1))
echo "Internet connection is not available. Waiting..."
sleep ${sleep_time}
(( attempt++ ))
fi
done
echo "ERROR: Internet connection is not available. Skipping the operation above."
return 1
}
# Opt out of and remove Fedora's system flatpak repos
@ -125,11 +123,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 if it doesn't exist (requires internet)"
check_internet_connection
if "${internet_connection}"; then
echo "Internet connection is successful, applying the operation above"
if check_internet_connection; then
echo "Adding system-wide remote $REPO_NAME from $REPO_URL if it doesn't exist (requires internet)"
flatpak remote-add --if-not-exists --system "$REPO_NAME" "$REPO_URL"
else
echo "NOTE: Skipping the addition of system-wide remote, because there is no internet connection"
fi
fi
@ -229,20 +227,22 @@ if [[ -f $INSTALL_LIST_FILE ]] || [[ -f $USER_INSTALL_LIST_FILE ]]; then
INSTALL_LIST="$COMBINED_INSTALL_LIST"
fi
if [[ -n $INSTALL_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
echo "Installing system flatpaks from config list (requires internet)"
check_internet_connection
if "${internet_connection}"; then
echo "Internet connection is successful, applying the operation above"
if check_internet_connection; then
echo "Installing system flatpaks from config list (requires internet)"
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
else
echo "ERROR: Installation of system flatpaks was not performed, because there was no internet connection"
exit 1
fi
elif [[ -n $INSTALL_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
echo "Installing system flatpaks from config list (requires internet)"
check_internet_connection
if "${internet_connection}"; then
echo "Internet connection is successful, applying the operation above"
if check_internet_connection; then
echo "Installing system flatpaks from config list (requires internet)"
notify-send-pre-install
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send-install
else
echo "ERROR: Installation of system flatpaks was not performed, because there was no internet connection"
exit 1
fi
fi
fi

View file

@ -9,6 +9,3 @@ ExecStart=/usr/bin/system-flatpak-setup
Restart=on-failure
RestartSec=30
StartLimitInterval=3
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,8 @@
[Unit]
Description=Timer for system-flatpak-setup
[Timer]
OnBootSec=30
[Install]
WantedBy=timers.target

View file

@ -1,26 +1,24 @@
#!/usr/bin/env bash
# Check for available internet connection before proceeding (network-online.target doesn't work for some network connections)
# Check it 5 times in 3 second interval, to avoid until loop
# 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=5
local sleep_time=3
local max_attempts=3
local sleep_time=2
local attempt=1
while [[ ${attempt} -le ${max_attempts} ]]; do
while (( attempt <= max_attempts )); do
if curl --silent --head --fail "https://fedoraproject.org/static/hotspot.txt" > /dev/null; then
internet_connection=true
return 0
return 0
else
internet_connection=false
echo "Internet connection is not available. Waiting..."
sleep ${sleep_time}
attempt=$((attempt + 1))
echo "Internet connection is not available. Waiting..."
sleep ${sleep_time}
(( attempt++ ))
fi
done
echo "ERROR: Internet connection is not available. Skipping the operation above."
return 1
}
# Remove Fedora's flatpak user repos, if they exist
@ -112,11 +110,11 @@ done
# Set up per-user Flatpak repository
if [[ $REPO_URL != "null" && $REPO_NAME != "null" ]]; then
echo "Adding user-wide remote $REPO_NAME from $REPO_URL if it doesn't exist (requires internet)"
check_internet_connection
if "${internet_connection}"; then
echo "Internet connection is successful, applying the operation above"
if check_internet_connection; then
echo "Adding user-wide remote $REPO_NAME from $REPO_URL if it doesn't exist (requires internet)"
flatpak remote-add --if-not-exists --user "$REPO_NAME" "$REPO_URL"
else
echo "NOTE: Skipping the addition of user-wide remote, because there is no internet connection"
fi
fi
@ -180,20 +178,22 @@ if [[ -f $INSTALL_LIST_FILE ]] || [[ -f $USER_INSTALL_LIST_FILE ]]; then
INSTALL_LIST="$COMBINED_INSTALL_LIST"
fi
if [[ -n $INSTALL_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
echo "Installing user flatpaks from config list (requires internet)"
check_internet_connection
if "${internet_connection}"; then
echo "Internet connection is successful, applying the operation above"
if check_internet_connection; then
echo "Installing user flatpaks from config list (requires internet)"
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
else
echo "ERROR: Installation of user flatpaks was not performed, because there was no internet connection"
exit 1
fi
elif [[ -n $INSTALL_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
echo "Installing user flatpaks from config list (requires internet)"
check_internet_connection
if "${internet_connection}"; then
echo "Internet connection is successful, applying the operation above"
if check_internet_connection; then
echo "Installing user flatpaks from config list (requires internet)"
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
else
echo "ERROR: Installation of user flatpaks was not performed, because there was no internet connection"
exit 1
fi
fi
fi

View file

@ -4,11 +4,8 @@ Wants=network-online.target
After=system-flatpak-setup.service
[Service]
Type=simple
Type=oneshot
ExecStart=/usr/bin/user-flatpak-setup
Restart=on-failure
RestartSec=30
StartLimitInterval=3
[Install]
WantedBy=default.target

View file

@ -0,0 +1,8 @@
[Unit]
Description=Timer for user-flatpak-setup
[Timer]
OnBootSec=30
[Install]
WantedBy=timers.target