Skip to content

Commit

Permalink
fix(default-flatpaks): Fix loginctl json parsing in F40 & less (sys…
Browse files Browse the repository at this point in the history
…temd v255 & less)
  • Loading branch information
fiftydinar authored Oct 25, 2024
1 parent ccde6df commit ca84ec8
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions modules/default-flatpaks/v1/system-flatpak-setup
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,54 @@ MAINTAINER_REMOVE_LIST=$(comm -23 <(sort "$REMOVE_LIST_FILE") <(sort "$USER_INST
COMBINED_INSTALL_LIST=$(cat <(echo "$MAINTAINER_INSTALL_LIST") "$USER_INSTALL_LIST_FILE" | grep -v -E '^#|^$' | awk '!seen[$0]++')
COMBINED_REMOVE_LIST=$(cat <(echo "$MAINTAINER_REMOVE_LIST") "$USER_REMOVE_LIST_FILE" | grep -v -E '^#|^$' | awk '!seen[$0]++')

# Loginctl has different command for parsing json since v256 (F41), so handle that scenario here
LOGINCTL_VERSION=$(loginctl --version | awk 'NR==1 {print $2}')
function notify-send-pre-install {
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
if [[ ${LOGINCTL_VERSION} -ge 256 ]]; then
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
else
user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid')
fi
xdg_runtime_path="/run/user/$uid"
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus notify-send "Flatpak Installer" "Started install of system flatpaks" --app-name="Flatpak Installer" -u NORMAL
}

function notify-send-install {
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
if [[ ${LOGINCTL_VERSION} -ge 256 ]]; then
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
else
user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid')
fi
xdg_runtime_path="/run/user/$uid"
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus notify-send "Flatpak Installer" "Finished install of system flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
}

function notify-send-pre-uninstall {
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
if [[ ${LOGINCTL_VERSION} -ge 256 ]]; then
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
else
user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid')
fi
xdg_runtime_path="/run/user/$uid"
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus notify-send "Flatpak Installer" "Started uninstall of some system flatpaks" --app-name="Flatpak Installer" -u NORMAL
}

function notify-send-uninstall {
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
xdg_runtime_path="/run/user/$uid"
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus notify-send "Flatpak Installer" "Finished uninstall of system flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
if [[ ${LOGINCTL_VERSION} -ge 256 ]]; then
user_name=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users -j | jq -r '.[] | select(.state == "active") | .uid')
else
user_name=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .user')
uid=$(loginctl list-users --output=json | jq -r '.[] | select(.state == "active") | .uid')
fi
xdg_runtime_path="/run/user/$uid"
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus notify-send "Flatpak Installer" "Finished uninstall of system flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
}

# Remove flatpaks in list
Expand Down

0 comments on commit ca84ec8

Please sign in to comment.