From 1a1819cf058ae06a25ff9e96747dc0c0c212b09e Mon Sep 17 00:00:00 2001 From: rokosun Date: Mon, 19 Sep 2022 20:35:32 +0200 Subject: [PATCH 1/4] New code for fix-tweaked-desktop-files --- bin/periodic/fix-tweaked-desktop-files | 93 +++++++++++--------------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/bin/periodic/fix-tweaked-desktop-files b/bin/periodic/fix-tweaked-desktop-files index f9bc687..a15a6d4 100755 --- a/bin/periodic/fix-tweaked-desktop-files +++ b/bin/periodic/fix-tweaked-desktop-files @@ -1,31 +1,29 @@ #!/bin/bash pidof -sq -o %PPID -x "$(basename "$0")" && exit -data="$HOME"/.local/share/applications/tweaked-desktop-files -data2="$HOME"/.local/share/applications/bakkedup-desktop-files +datastore="$HOME"/.local/share/desktop-file-data +bakdir="$datastore"/backup +data="$datastore"/tweaked-desktop-files + +mkdir -p "$bakdir" || { echo "failed to make directory $bakdir"; exit 1; } # Directories where desktop files are stored user="$HOME"/.local/share/applications -flatpak_local="$HOME"/.local/share/flatpak/exports/share/applications -flatpak_global=/var/lib/flatpak/exports/share/applications -pacman_local=/usr/local/share/applications pacman_global=/usr/share/applications +pacman_local=/usr/local/share/applications +flatpak_global=/var/lib/flatpak/exports/share/applications +flatpak_local="$HOME"/.local/share/flatpak/exports/share/applications snap=/var/lib/snapd/desktop/applications detectfiles() { for file in "$user"/*.desktop; do name=$(basename "$file") || continue - [ -d "$file" ] || grep -xq "\(flatpak-local\|flatpak-global\|pacman-local\|pacman-global\|snap\)/$name" "$data" && continue - if [ -f "$flatpak_local/$name" ]; then - echo "flatpak-local/$name" >> "$data" - elif [ -f "$flatpak_global/$name" ]; then - echo "flatpak-global/$name" >> "$data" - elif [ -f "$pacman_local/$name" ]; then - echo "pacman-local/$name" >> "$data" - elif [ -f "$pacman_global/$name" ]; then - echo "pacman-global/$name" >> "$data" - elif [ -f "$snap/$name" ]; then - echo "snap/$name" >> "$data" - fi + [ -d "$file" ] || grep -xq "$name" "$data" && continue + [ -f "$pacman_global/$name" ] || + [ -f "$pacman_local/$name" ] || + [ -f "$flatpak_global/$name" ] || + [ -f "$flatpak_local/$name" ] || + [ -f "$snap/$name" ] && + echo "$name" >> "$data" done } @@ -35,55 +33,42 @@ fixfiles() { trap 'rm $tmp' EXIT [ -f "$data" ] && cp "$data" "$tmp" && copied='true' lineno=0 - [ "$copied" = 'true' ] && while IFS= read -r line; do + [ "$copied" = 'true' ] && while IFS= read -r name; do ((lineno++)) - name=${line#*/} file="$user/$name" - # shellcheck disable=2015 # To disable shellcheck error here, line below is intended to work this way - echo "$line" | grep -xq '\(flatpak-local\|flatpak-global\|pacman-local\|pacman-global\|snap\)/.\+' && [ -f "$file" ] || { sed -i "${lineno}d" "$tmp" && ((lineno--)) ; continue; } - [ -f "$flatpak_local/$name" ] || - [ -f "$flatpak_global/$name" ] || + [ -f "$file" ] || { sed -i "${lineno}d" "$tmp" && ((lineno--)) ; continue; } + [ -f "$pacman_global/$name" ] || [ -f "$pacman_local/$name" ] || - [ -f "$pacman_global/$name" ] || + [ -f "$flatpak_global/$name" ] || + [ -f "$flatpak_local/$name" ] || [ -f "$snap/$name" ] || - { mv "$file" "$file.bak" && echo "$line" >> "$data2"; } + mv "$file" "$bakdir/$file.bak" done < "$data" [ "$copied" = 'true' ] && [ "$(stat -c '%Y' "$data")" = "$lastmod" ] && sort "$tmp" | uniq > "$data" - [ -n "$(sort "$data2" | uniq -d)" ] && cp "$data2" "$tmp" && sort "$tmp" | uniq > "$data2" - - for bakfile in "$user"/*.desktop.bak; do - origfile="${bakfile%.bak}" + for bakfile in "$bakdir"/*.desktop.bak; do + name=$(basename "${bakfile%.bak}") || continue + origfile="$user/$name" [ -f "$origfile" ] && continue - name=$(basename "$origfile") || continue - [ -f "$flatpak_local/$name" ] || - [ -f "$flatpak_global/$name" ] || + [ -f "$pacman_global/$name" ] || [ -f "$pacman_local/$name" ] || - [ -f "$pacman_global/$name" ] || + [ -f "$flatpak_global/$name" ] || + [ -f "$flatpak_local/$name" ] || [ -f "$snap/$name" ] && mv "$bakfile" "$origfile" done } -while :; do - user_new=$(ls -ad "$user"/*.desktop 2>/dev/null) - flatpak_local_new=$(ls -ad "$flatpak_local"/*.desktop 2>/dev/null) - flatpak_global_new=$(ls -ad "$flatpak_global"/*.desktop 2>/dev/null) - pacman_local_new=$(ls -ad "$pacman_local"/*.desktop 2>/dev/null) - pacman_global_new=$(ls -ad "$pacman_global"/*.desktop 2>/dev/null) - snap_new=$(ls -ad "$snap"/*.desktop 2>/dev/null) - [ "$user_new" != "$user_old" ] && detectfiles - [ "$flatpak_local_new" != "$flatpak_local_old" ] || - [ "$flatpak_global_new" != "$flatpak_global_old" ] || - [ "$pacman_local_new" != "$pacman_local_old" ] || - [ "$pacman_global_new" != "$pacman_global_old" ] || - [ "$snap_new" != "$snap_old" ] && fixfiles - user_old=$user_new - flatpak_local_old=$flatpak_local_new - flatpak_global_old=$flatpak_global_new - pacman_local_old=$pacman_local_new - pacman_global_old=$pacman_global_new - snap_old=$snap_new - sleep 5 -done \ No newline at end of file +existing_dirs=() +for dir in "$user" "$pacman_global" "$pacman_local" "$flatpak_global" "$flatpak_local" "$snap"; do + [ -d "$dir" ] && existing_dirs=("${existing_dirs[@]}" "$dir") +done + +while read -r line; do + if [ "$line" = "$user/" ]; then + detectfiles + else + fixfiles + fi +done < <(inotifywait -qm --format '%w' --include '\.desktop$' -e 'move,move_self,create,delete,delete_self,unmount' "${existing_dirs[@]}") \ No newline at end of file -- 2.30.2 From dfb1f44cbe20dbcc27c7929bdc87765be4d78b04 Mon Sep 17 00:00:00 2001 From: rokosun Date: Tue, 20 Sep 2022 01:09:11 +0200 Subject: [PATCH 2/4] small bug fixes --- bin/periodic/fix-tweaked-desktop-files | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/periodic/fix-tweaked-desktop-files b/bin/periodic/fix-tweaked-desktop-files index a15a6d4..b19f1e7 100755 --- a/bin/periodic/fix-tweaked-desktop-files +++ b/bin/periodic/fix-tweaked-desktop-files @@ -42,7 +42,7 @@ fixfiles() { [ -f "$flatpak_global/$name" ] || [ -f "$flatpak_local/$name" ] || [ -f "$snap/$name" ] || - mv "$file" "$bakdir/$file.bak" + mv "$file" "$bakdir/$name.bak" done < "$data" [ "$copied" = 'true' ] && [ "$(stat -c '%Y' "$data")" = "$lastmod" ] && sort "$tmp" | uniq > "$data" @@ -65,6 +65,9 @@ for dir in "$user" "$pacman_global" "$pacman_local" "$flatpak_global" "$flatpak_ [ -d "$dir" ] && existing_dirs=("${existing_dirs[@]}" "$dir") done +detectfiles +fixfiles + while read -r line; do if [ "$line" = "$user/" ]; then detectfiles -- 2.30.2 From ca46fdc0d2f0930c3109ae384270144b20a4ba6f Mon Sep 17 00:00:00 2001 From: rokosun Date: Tue, 20 Sep 2022 01:44:56 +0200 Subject: [PATCH 3/4] Make directores where possible --- bin/periodic/fix-tweaked-desktop-files | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/periodic/fix-tweaked-desktop-files b/bin/periodic/fix-tweaked-desktop-files index b19f1e7..5a0608d 100755 --- a/bin/periodic/fix-tweaked-desktop-files +++ b/bin/periodic/fix-tweaked-desktop-files @@ -14,6 +14,8 @@ flatpak_global=/var/lib/flatpak/exports/share/applications flatpak_local="$HOME"/.local/share/flatpak/exports/share/applications snap=/var/lib/snapd/desktop/applications +mkdir -p "$user" "$flatpak_local" || { echo "failed to make directoris $user & $flatpak_local"; exit 1; } + detectfiles() { for file in "$user"/*.desktop; do name=$(basename "$file") || continue -- 2.30.2 From fbfc7b5d08219a04c7a9df2702b674cac36fde87 Mon Sep 17 00:00:00 2001 From: rokosun Date: Tue, 20 Sep 2022 02:06:23 +0200 Subject: [PATCH 4/4] Change name to "fix-zombie-appicons" --- bin/periodic/{fix-tweaked-desktop-files => fix-zombie-appicons} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename bin/periodic/{fix-tweaked-desktop-files => fix-zombie-appicons} (97%) diff --git a/bin/periodic/fix-tweaked-desktop-files b/bin/periodic/fix-zombie-appicons similarity index 97% rename from bin/periodic/fix-tweaked-desktop-files rename to bin/periodic/fix-zombie-appicons index 5a0608d..6b680eb 100755 --- a/bin/periodic/fix-tweaked-desktop-files +++ b/bin/periodic/fix-zombie-appicons @@ -1,6 +1,6 @@ #!/bin/bash pidof -sq -o %PPID -x "$(basename "$0")" && exit -datastore="$HOME"/.local/share/desktop-file-data +datastore="$HOME"/.local/share/fix-zombie-appicons bakdir="$datastore"/backup data="$datastore"/tweaked-desktop-files -- 2.30.2