refactor: move default-flatpaks files to module directory
This commit is contained in:
parent
4647a5e39c
commit
53e8fb3e2b
5 changed files with 5 additions and 5 deletions
|
|
@ -3,12 +3,12 @@
|
|||
# Tell build process to exit if there are any errors.
|
||||
set -euo pipefail
|
||||
|
||||
BLING_DIRECTORY="${BLING_DIRECTORY:-"/tmp/bling"}"
|
||||
MODULE_DIRECTORY="${MODULE_DIRECTORY:-"/tmp/modules"}"
|
||||
|
||||
cp -r "$BLING_DIRECTORY"/files/usr/bin/system-flatpak-setup /usr/bin/system-flatpak-setup
|
||||
cp -r "$BLING_DIRECTORY"/files/usr/bin/user-flatpak-setup /usr/bin/user-flatpak-setup
|
||||
cp -r "$BLING_DIRECTORY"/files/usr/lib/systemd/system/system-flatpak-setup.service /usr/lib/systemd/system/system-flatpak-setup.service
|
||||
cp -r "$BLING_DIRECTORY"/files/usr/lib/systemd/user/user-flatpak-setup.service /usr/lib/systemd/user/user-flatpak-setup.service
|
||||
cp -r "$MODULE_DIRECTORY"/default-flatpaks/system-flatpak-setup /usr/bin/system-flatpak-setup
|
||||
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
|
||||
|
||||
configure_flatpak_repo () {
|
||||
CONFIG_FILE=$1
|
||||
|
|
|
|||
94
modules/default-flatpaks/system-flatpak-setup
Executable file
94
modules/default-flatpaks/system-flatpak-setup
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Opt out of and remove Fedora's flatpak repo
|
||||
if grep -qz 'fedora' <<< "$(flatpak remotes)"; then
|
||||
/usr/bin/gnome-software --quit
|
||||
/usr/lib/fedora-third-party/fedora-third-party-opt-out
|
||||
/usr/bin/fedora-third-party disable
|
||||
flatpak remote-delete fedora --force
|
||||
flatpak remote-delete fedora-testing --force
|
||||
|
||||
# Remove flatpak apps from origin fedora
|
||||
FEDORA_FLATPAKS=$(flatpak list --app --columns=application,origin | grep -w 'fedora' | awk '{print $1}')
|
||||
flatpak remove --system --noninteractive ${FEDORA_FLATPAKS[@]}
|
||||
|
||||
# Remove flatpak runtimes from origin fedora
|
||||
FEDORA_FLATPAKS=$(flatpak list --runtime --columns=application,arch,branch,origin | grep -w 'fedora' | awk '{print $1"/"$2"/"$3}')
|
||||
flatpak remove --system --noninteractive ${FEDORA_FLATPAKS[@]}
|
||||
fi
|
||||
|
||||
REPO_INFO="/etc/flatpak/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)
|
||||
|
||||
# Set up system-wide Flatpak repository
|
||||
if [[ ! $REPO_URL == "null" && ! $REPO_NAME == "null" ]]; then
|
||||
flatpak remote-add --if-not-exists --system "$REPO_NAME" "$REPO_URL"
|
||||
echo "Adding system-wide remote $REPO_NAME from $REPO_URL"
|
||||
fi
|
||||
|
||||
# If configured remote is flathub, enable it here.
|
||||
# Flathub is already installed on Fedora, but not enabled by default,
|
||||
# so the above command won't add it again
|
||||
if [[ $REPO_NAME == "flathub" ]]; then
|
||||
flatpak remote-modify --system "$REPO_NAME" --enable
|
||||
fi
|
||||
|
||||
# Change repository title to configured title, if not null
|
||||
if [[ ! $REPO_TITLE == "null" ]]; then
|
||||
flatpak remote-modify --system "$REPO_NAME" --title="$REPO_TITLE"
|
||||
echo "Setting title $REPO_TITLE for remote $REPO_NAME"
|
||||
fi
|
||||
|
||||
# Notifications config
|
||||
NOTIFICATIONS=$(cat /etc/flatpak/notifications)
|
||||
|
||||
# Installed flatpaks
|
||||
FLATPAK_LIST=$(flatpak list --system --columns=application)
|
||||
|
||||
# Flatpak list files
|
||||
INSTALL_LIST_FILE="/etc/flatpak/system/install"
|
||||
REMOVE_LIST_FILE="/etc/flatpak/system/remove"
|
||||
|
||||
function notify-send-install {
|
||||
user_name=$(loginctl list-sessions --output=json | jq -r '.[].user')
|
||||
uid=$(loginctl list-sessions --output=json | jq -r '.[].uid')
|
||||
xdg_runtime_path="/run/user/$uid"
|
||||
display_var=$(printenv DISPLAY)
|
||||
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Finished install of system flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
|
||||
}
|
||||
|
||||
function notify-send-uninstall {
|
||||
user_name=$(loginctl list-sessions --output=json | jq -r '.[].user')
|
||||
uid=$(loginctl list-sessions --output=json | jq -r '.[].uid')
|
||||
xdg_runtime_path="/run/user/$uid"
|
||||
display_var=$(printenv DISPLAY)
|
||||
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Finished uninstall of system flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
|
||||
}
|
||||
|
||||
# Install flatpaks in list
|
||||
if [[ -f $INSTALL_LIST_FILE ]]; then
|
||||
if [[ -n $FLATPAK_LIST ]]; then
|
||||
INSTALL_LIST=$(echo "$FLATPAK_LIST" | grep -vf - "$INSTALL_LIST_FILE")
|
||||
else
|
||||
INSTALL_LIST=$(cat $INSTALL_LIST_FILE)
|
||||
fi
|
||||
if [[ -n $INSTALL_LIST ]]; then
|
||||
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
|
||||
if [[ $NOTIFICATIONS == "true" ]]; then
|
||||
notify-send-install
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Remove flatpaks in list
|
||||
if [[ -f $REMOVE_LIST_FILE ]]; then
|
||||
REMOVE_LIST=$(echo "$FLATPAK_LIST" | grep -o -f - "$REMOVE_LIST_FILE")
|
||||
if [[ -n $REMOVE_LIST ]]; then
|
||||
flatpak uninstall --system --noninteractive ${REMOVE_LIST[@]}
|
||||
if [[ $NOTIFICATIONS == "true" ]]; then
|
||||
notify-send-uninstall
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
14
modules/default-flatpaks/system-flatpak-setup.service
Normal file
14
modules/default-flatpaks/system-flatpak-setup.service
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=Manage system flatpaks
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/system-flatpak-setup
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
StartLimitInterval=0
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
60
modules/default-flatpaks/user-flatpak-setup
Executable file
60
modules/default-flatpaks/user-flatpak-setup
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Remove Fedora's flatpak repo, if it exists
|
||||
if grep -qz 'fedora' <<< "$(flatpak remotes)"; then
|
||||
flatpak remote-delete --user fedora --force
|
||||
flatpak remote-delete --user fedora-testing --force
|
||||
fi
|
||||
|
||||
REPO_INFO="/etc/flatpak/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)
|
||||
|
||||
# Set up per-user Flatpak repository
|
||||
if [[ ! $REPO_URL == "null" && ! $REPO_NAME == "null" ]]; then
|
||||
flatpak remote-add --if-not-exists --user "$REPO_NAME" "$REPO_URL"
|
||||
echo "Adding remote $REPO_NAME from $REPO_URL"
|
||||
fi
|
||||
|
||||
# Change repository title to configured title, if not null
|
||||
if [[ ! $REPO_TITLE == "null" ]]; then
|
||||
flatpak remote-modify --user "$REPO_NAME" --title="$REPO_TITLE"
|
||||
echo "Setting title $REPO_TITLE for remote $REPO_NAME"
|
||||
fi
|
||||
|
||||
# Notifications config
|
||||
NOTIFICATIONS=$(cat /etc/flatpak/notifications)
|
||||
|
||||
# Installed flatpaks
|
||||
FLATPAK_LIST=$(flatpak list --user --columns=application)
|
||||
|
||||
# Flatpak list files
|
||||
INSTALL_LIST_FILE="/etc/flatpak/user/install"
|
||||
REMOVE_LIST_FILE="/etc/flatpak/user/remove"
|
||||
|
||||
# Install flatpaks in list
|
||||
if [[ -f $INSTALL_LIST_FILE ]]; then
|
||||
if [[ -n $FLATPAK_LIST ]]; then
|
||||
INSTALL_LIST=$(echo "$FLATPAK_LIST" | grep -vf - "$INSTALL_LIST_FILE")
|
||||
else
|
||||
INSTALL_LIST=$(cat $INSTALL_LIST_FILE)
|
||||
fi
|
||||
if [[ -n $INSTALL_LIST ]]; then
|
||||
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
|
||||
if [[ $NOTIFICATIONS == "true" ]]; then
|
||||
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 ]]; then
|
||||
REMOVE_LIST=$(echo "$FLATPAK_LIST" | grep -o -f - "$REMOVE_LIST_FILE")
|
||||
if [[ -n $REMOVE_LIST ]]; then
|
||||
flatpak uninstall --user --noninteractive ${REMOVE_LIST[@]}
|
||||
if [[ $NOTIFICATIONS == "true" ]]; then
|
||||
notify-send "Flatpak Installer" "Finished uninstall of user flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
14
modules/default-flatpaks/user-flatpak-setup.service
Normal file
14
modules/default-flatpaks/user-flatpak-setup.service
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=Configure Flatpaks for current user
|
||||
Wants=network-online.target
|
||||
After=system-flatpak-setup.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/user-flatpak-setup
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
StartLimitInterval=0
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue