diff --git a/sideload-repos-systemd/flatpak-create-sideload-symlinks.sh b/sideload-repos-systemd/flatpak-create-sideload-symlinks.sh index 0e4c57f0..4b3aabd6 100755 --- a/sideload-repos-systemd/flatpak-create-sideload-symlinks.sh +++ b/sideload-repos-systemd/flatpak-create-sideload-symlinks.sh @@ -2,6 +2,8 @@ # This script is intended to be run by flatpak-sideload-usb-repo.service +shopt -s nullglob + if ! test $# -eq 1 || ! test -d "$1"; then echo "Error: first argument must be a directory" exit 1 @@ -15,7 +17,7 @@ for f in "$1"/*; do if ! test -d "$f"; then continue fi - unique_name=automount-$(echo "$f" | sha256sum | cut -f 1 -d ' ') + unique_name=automount$(systemd-escape "$f") if test -e "/run/flatpak/sideload-repos/$unique_name"; then continue fi @@ -23,7 +25,11 @@ for f in "$1"/*; do done # Remove any broken symlinks e.g. from drives that were removed -for f in /run/flatpak/sideload-repos/automount-*; do +for f in /run/flatpak/sideload-repos/automount*; do + OWNER=$(stat -c '%u' "$f") + if [ "$UID" != "$OWNER" ]; then + continue + fi if ! test -e "$f"; then rm "$f" fi diff --git a/sideload-repos-systemd/flatpak-sideload-usb-repo.path.in b/sideload-repos-systemd/flatpak-sideload-usb-repo.path.in index 095b7102..3e7d26ad 100644 --- a/sideload-repos-systemd/flatpak-sideload-usb-repo.path.in +++ b/sideload-repos-systemd/flatpak-sideload-usb-repo.path.in @@ -1,11 +1,10 @@ # This unit is intended to be installed in the systemd user instance, and -# depends on flatpak-sideload-repos-dir.service being in the system instance -# and running first. The idea here is that we add any USB drive mounts to the +# depends on /run/flatpak/sideload-repos having been created via +# systemd-tmpfiles. The idea here is that we add any USB drive mounts to the # appropriate directory so Flatpak can find and pull from them in case they # have flatpaks on them, both when a new drive is inserted and at the start of # the user session. [Path] -PathExists=@media_dir@/%u PathChanged=@media_dir@/%u [Install] diff --git a/sideload-repos-systemd/flatpak-sideload-usb-repo.service.in b/sideload-repos-systemd/flatpak-sideload-usb-repo.service.in index 8f8895da..a3f4c93a 100644 --- a/sideload-repos-systemd/flatpak-sideload-usb-repo.service.in +++ b/sideload-repos-systemd/flatpak-sideload-usb-repo.service.in @@ -3,3 +3,6 @@ [Service] Type=oneshot ExecStart=@libexecdir@/flatpak-create-sideload-symlinks.sh @media_dir@/%u + +[Install] +WantedBy=default.target