2 Commits

Author SHA1 Message Date
eSh
8bc101bdbc use xargs to enable systemd timers 2022-09-16 03:44:04 +02:00
eSh
8770d45219 add systemd timers for periodic fixes 2022-09-16 03:43:28 +02:00
19 changed files with 196 additions and 261 deletions

@ -9,4 +9,4 @@ remove:
pamac-installer --remove tromjaro-fixes
clean:
$(RM) -rf src/ pkg/ *.tar.xz
$(RM) -rf src/ pkg/ *.tar.xz

@ -1,26 +1,17 @@
# Maintainer: TROM <contact@tromsite.com>
pkgname=tromjaro-fixes
pkgver=1.6
pkgrel=0
pkgver=1.0.0
pkgrel=1
pkgdesc="Various fixes for TROMjaro OS"
arch=(any)
url=""
license=(unknown)
depends=('xfce4-appfinder'
'xdotool'
'rsync'
'inotify-tools'
'qt5-styleplugins'
'qt6gtk2'
'qqc2-desktop-style')
depends=()
provides=('tromjaro-fixes')
backup=()
options=(!strip)
source=('scalable.zip::https://www.drive.tromsite.com/s/y8Gm7q6wLrXmtEN/download'
'tromjaro-fixes.sh')
sha256sums=('SKIP'
'SKIP')
install='fixes-package.install'
prepare() {
cp -R ../bin ../flatpak-overrides ../alpm-hooks ../systemd .
}
@ -31,6 +22,11 @@ package() {
install -Dm755 ${srcdir}/bin/standalone/* ${pkgdir}/usr/bin
install -Dm755 ${srcdir}/bin/periodic/* ${pkgdir}/usr/bin
# copy systemd units
install -d ${pkgdir}/usr/lib/systemd/system
install -Dm644 ${srcdir}/systemd/services/* ${pkgdir}/usr/lib/systemd/system
install -Dm644 ${srcdir}/systemd/timers/* ${pkgdir}/usr/lib/systemd/system
# copy alpm hooks
install -d ${pkgdir}/usr/share/libalpm/hooks
install -Dm644 ${srcdir}/alpm-hooks/* ${pkgdir}/usr/share/libalpm/hooks
@ -38,21 +34,4 @@ package() {
# copy flatpak overrides
install -d ${pkgdir}/var/lib/flatpak/overrides
install -Dm644 ${srcdir}/flatpak-overrides/* ${pkgdir}/var/lib/flatpak/overrides
# copy systemd units
install -d ${pkgdir}/usr/lib/systemd/user
install -Dm644 ${srcdir}/systemd/services/* ${pkgdir}/usr/lib/systemd/user
# copy zafiro dark icons
install -d ${pkgdir}/usr/local/share/icons/zafiro-dark/apps/scalable
install -Dm755 ${srcdir}/scalable/* ${pkgdir}/usr/local/share/icons/zafiro-dark/apps/scalable
# copy zafiro icons
install -d ${pkgdir}/usr/local/share/icons/zafiro/apps/scalable
install -Dm755 ${srcdir}/scalable/* ${pkgdir}/usr/local/share/icons/zafiro/apps/scalable
# copy tromjaro-fixes.sh
install -d ${pkgdir}/etc/profile.d/
install -Dm644 ${srcdir}/tromjaro-fixes.sh ${pkgdir}/etc/profile.d/
}

@ -8,4 +8,4 @@ Target = *
[Action]
Description = Refreshing the chaotic-aur keyring...
When = PreTransaction
Exec = /usr/bin/fix-chaotic-keyring
Exec = /usr/bin/chaotic-keyring-refresh

@ -0,0 +1,11 @@
[Trigger]
Operation = Upgrade
Type = Package
Target = qt5-base
Target = qt6-base
[Action]
Description = Reinstalling needed packages for theming QT applications...
When = PostTransaction
Exec = /usr/bin/reinstall-for-qt

@ -1,30 +1,4 @@
#!/bin/bash
# Set the directories
shared\_themes\_dir=/usr/share/themes/
local\_themes\_dir="$HOME/.themes/"
# Function to synchronize themes from shared to local directory
sync\_themes() {
rsync -av --delete --progress "$shared\_themes\_dir" "$local\_themes\_dir"
echo "Directory $local\_themes\_dir is synchronized with $shared\_themes\_dir"
}
# Initial synchronization
sync\_themes
# Function to monitor both shared and local themes directories
monitor\_themes() {
inotifywait -m -r -e modify,attrib,move,move\_self,create,delete,delete\_self,unmount "$shared\_themes\_dir" "$local\_themes\_dir" |
while read -r events; do
sync\_themes
done
}
# Start monitoring in the background
monitor\_themes
#!/bin/sh
rm -r ~/.themes/* 2> /dev/null
rsync -av --progress /usr/share/themes/* ~/.themes/ --exclude Windowck
rsync -av --progress ~/.local/share/themes/* ~/.themes/ --exclude Windowck-dark

@ -1,38 +1,34 @@
#!/bin/bash
#!/bin/sh
sync_theme() {
# Get the current system theme
theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
# Enable syncing the current theme with xfwm4 if not already enabled
[ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] && xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
# Find the best match for the xfwm4 theme that corresponds with the current system theme
xfwm4_theme=$(find /usr/share/themes/ /usr/local/share/themes/ "$HOME"/.themes/ "$HOME"/.local/share/themes/ -mindepth 2 -maxdepth 2 -type d -name xfwm4 -printf '%h\n' 2>/dev/null | grep -o "/${theme}[^/]*$" | sort | head -n1)
# If a match is not found then use the Default theme
[ -z "$xfwm4_theme" ] && xfwm4_theme='Default'
# Apply the xfwm4 theme
xfconf-query -c xfwm4 -p /general/theme -n -t string -s "${xfwm4_theme#/}"
# Apply the current theme with gsettings
gsettings set org.gnome.desktop.interface gtk-theme "$theme"
# Apply the current theme for GTK apps in flatpak
# Define the path to the flatpak override directory
flatpak_override_dir="$HOME/.local/share/flatpak/overrides"
# Create the directory if it doesn't exist
[ -d "$flatpak_override_dir" ] || mkdir -p "$flatpak_override_dir" || { echo 'failed creating directory!'; return 1; }
# Write the theme configuration to the global override file
echo "[Environment]
GTK_THEME=$theme" > "$flatpak_override_dir/global"
}
sync_icon_theme() {
# Get the current icon theme
icon_theme=$(xfconf-query -c xsettings -p /Net/IconThemeName)
# Apply the same theme in qt5ct and qt6ct configuration
sed -i "s/^icon_theme=.*$/icon_theme=$icon_theme/" "$HOME"/.config/qt5ct/qt5ct.conf
sed -i "s/^icon_theme=.*$/icon_theme=$icon_theme/" "$HOME"/.config/qt6ct/qt6ct.conf
}
sync_font() {
# Get the current system font
font=$(xfconf-query -c xsettings -p /Gtk/FontName)
# Apply the same font for the title of xfce windows
xfconf-query -c xfwm4 -p /general/title_font -n -t string -s "$font"
}
# Get the current system theme
theme_new=$(xfconf-query -c xsettings -p /Net/ThemeName)
# Get the current icon theme
icon_theme_new=$(xfconf-query -c xsettings -p /Net/IconThemeName)
sync_theme
sync_font
# Run sync_theme if the new system theme doesn't match the previous one
[ "$theme_new" != "$theme_prev" ] && sync_theme
# Run sync_icon_theme if the new icon theme doesn't match the previous one
[ "$icon_theme_new" != "$icon_theme_prev" ] && sync_icon_theme
# Monitor when the user changes their system theme or font in XFCE and sync them as needed
while read -r line; do
case "$line" in
'set: /Net/ThemeName') sync_theme ;;
'set: /Gtk/FontName') sync_font ;;
esac
done < <(xfconf-query -c xsettings -m)
# The new values become the previous values
theme_prev=$theme_new
icon_theme_prev=$icon_theme_new

@ -0,0 +1,86 @@
#!/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
# 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
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
done
}
fixfiles() {
lastmod=$(stat -c "%Y" "$data")
tmp="$(mktemp)"
trap 'rm $tmp' EXIT
[ -f "$data" ] && cp "$data" "$tmp" && copied='true'
lineno=0
[ "$copied" = 'true' ] && while IFS= read -r line; 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 "$pacman_local/$name" ] ||
[ -f "$pacman_global/$name" ] ||
[ -f "$snap/$name" ] ||
{ mv "$file" "$file.bak" && echo "$line" >> "$data2"; }
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}"
[ -f "$origfile" ] && continue
name=$(basename "$origfile") || continue
[ -f "$flatpak_local/$name" ] ||
[ -f "$flatpak_global/$name" ] ||
[ -f "$pacman_local/$name" ] ||
[ -f "$pacman_global/$name" ] ||
[ -f "$snap/$name" ] &&
mv "$bakfile" "$origfile"
done
}
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

@ -1,120 +0,0 @@
#!/bin/bash
# Exit out if the same script is already running in the background
pidof -sq -o %PPID -x "$(basename "$0")" && exit
# Setting read-only variables
declare -r datadir="$HOME"/.local/share/fix-zombie-appicons
declare -r backup_dir="$datadir"/backup
declare -r datafile="$datadir"/tweaked-desktop-files
# Desktop files stored here will take precedence over the other ones
declare -r home_local_applications_dir="$HOME/.local/share/applications"
# Go through each item in $XDG_DATA_DIRS to find all other directories
# except home_local_applications_dir where desktop files are stored, and
# save these to other_applications_dirs
while read -r dir; do
full_dir_path=${dir%/}/applications
other_applications_dirs+=("$full_dir_path")
# Directories inside user's home directory
[[ "$full_dir_path" = "$HOME"/* ]] && dirs_inside_user_home+=("$full_dir_path")
done < <(echo "$XDG_DATA_DIRS" | tr ':' '\n' | sort -u | grep -vFx "$home_local_applications_dir")
declare -r other_applications_dirs dirs_inside_user_home
# Create tempfile which is used by the fix_desktop_files function
tempfile="$(mktemp)"
trap 'rm $tempfile' EXIT # Delete tempfile when the script exits
declare -r tempfile
# This function will check for new desktop files in home_local_applications_dir and
# record them in datafile if the same file is found in any of the other_applications_dirs.
detect_new_desktop_files() {
for file in "$home_local_applications_dir"/*.desktop; do
# This is added as a failsafe to ensure its a file and not a directory
[ -d "$file" ] && continue
filename=$(basename "$file")
# Continue looping if the filename is already recorded in the datafile
grep -xq "$filename" "$datafile" && continue
# If the same file is present in any of the other_applications_dirs then add its filename to datafile
for dir in "${other_applications_dirs[@]}"; do
[ -f "$dir/$filename" ] && echo "$filename" >> "$datafile" && break
done
done
}
# The following function will:
# 1. Go through all the files recorded in datafile and move them to backup_dir if
# the same file is not found in other_applications_dirs anymore.
# 2. Go through all the bakked up files in backup_dir and move them back to
# its original_file_path if the same file is present in any of
# the other_applications_dirs. This will not overwrite if a new
# file already exists at original_file_path.
fix_desktop_files() {
# This is added as a failsafe to avoid overwriting datafile in case the file got edited during this period
local -r last_modified_time=$(stat -c "%Y" "$datafile")
# Copy datafile to tempfile because its not possible to directly edit the file inside a while-read loop
[ -f "$datafile" ] && cp "$datafile" "$tempfile" && local -r datafile_copied='true'
local -i line_number=0
# Loop through each line in datafile
[ "$datafile_copied" = 'true' ] && while IFS='' read -r filename; do
line_number+=1
file="$home_local_applications_dir/$filename"
# If the file don't exist anymore then remove the line from datafile (as tempfile) and continue looping
[ -f "$file" ] || { sed -i "${line_number}d" "$tempfile" && line_number+=-1 ; continue; }
# If the same file is not present in any of the other_applications_dirs then move the file to backup_dir
unset file_exists
for dir in "${other_applications_dirs[@]}"; do
[ -f "$dir/$filename" ] && file_exists='true' && break
done
[ "$file_exists" != 'true' ] && mv "$file" "$backup_dir/$filename.bak"
done < "$datafile"
# Write the contents from tempfile back to datafile after sorting and removing duplicate lines
[ "$datafile_copied" = 'true' ] && [ "$(stat -c '%Y' "$datafile")" = "$last_modified_time" ] && sort -u "$tempfile" > "$datafile"
for bakfile in "$backup_dir"/*.desktop.bak; do
filename=$(basename "${bakfile%.bak}")
original_file_path="$home_local_applications_dir/$filename"
# Continue looping if a new file is already present at the original_file_path,
# this will prevent the backup from overwriting the new file
[ -f "$original_file_path" ] && continue
# If the same bakked up file is present in any of the other_applications_dirs then move it back to its original_file_path
for dir in "${other_applications_dirs[@]}"; do
[ -f "$dir/$filename" ] && mv "$bakfile" "$original_file_path" && break
done
done
}
# Create some directories in the user's home directory if they don't already exist
mkdir -p "$datadir" "$backup_dir" "$home_local_applications_dir" ||
{ echo "failed to make directories $datadir, $backup_dir & $home_local_applications_dir"; exit 1; }
# Try to create dirs_inside_user_home if they don't already exist
[ ${#dirs_inside_user_home[@]} -gt 0 ] && mkdir -p "${dirs_inside_user_home[@]}"
# Check which directories currently exist on the user's system so that inotifywait can monitor them for changes
for dir in "$home_local_applications_dir" "${other_applications_dirs[@]}"; do
[ -d "$dir" ] && currently_existing_dirs+=("$dir")
done
# Both functions will be run once when the script first starts
detect_new_desktop_files
fix_desktop_files
# Inotifywait monitors currently_existing_dirs and the functions are run each time when there is a change in relevant directories
while IFS='' read -r line; do
if [ "$line" = "$home_local_applications_dir/" ]; then
detect_new_desktop_files
else
fix_desktop_files
fi
done < <(inotifywait -qm --format '%w' --include '\.desktop$' -e 'move,move_self,create,delete,delete_self,unmount' "${currently_existing_dirs[@]}")

@ -1,2 +1,3 @@
#!/bin/bash
pacman-key --populate chaotic
sudo pacman-key --populate chaotic &
rm ~/.local/bin/fix-chaotic-keyring

@ -0,0 +1,3 @@
#!/bin/bash
rm /var/lib/pacman/db.lck
pacman --noconfirm -S qt5-styleplugins qt6gtk2

@ -1,14 +1,3 @@
post_install() {
find /usr/lib/systemd/user/ -name "fix-*.service" -type f -printf "%f\0" | xargs -0 systemctl --global enable
echo "Warning: A restart is required to take effect"
}
post_upgrade() {
find /usr/lib/systemd/user/ -name "fix-*.service" -type f -printf "%f\0" | xargs -0 systemctl --global enable
echo "Warning: A restart is required to take effect"
}
pre_remove() {
find /usr/lib/systemd/user/ -name "fix-*.service" -type f -printf "%f\0" | xargs -0 systemctl --global disable
echo "Warning: A restart is required to take effect"
find /usr/lib/systemd/system/ -name "fix-*.timer" -type f -print0 | xargs -0 systemctl enable
}

@ -1,5 +1,2 @@
[Context]
filesystems=~/.config/gtk-4.0;~/.themes;~/.icons;xdg-config/gtk-4.0;xdg-config/Kvantum:ro;
[Environment]
QT_STYLE_OVERRIDE=kvantum
filesystems=~/.themes;

@ -3,13 +3,11 @@
[Unit]
Description=Fix flatpak theming script
StartLimitIntervalSec=0
Wants=fix-flatpaks-theming.timer
[Service]
Type=simple
Restart=always
RestartSec=1
Type=oneshot
ExecStart=/usr/bin/fix-flatpaks-theming
[Install]
WantedBy=default.target
WantedBy=multi-user.target

@ -3,13 +3,11 @@
[Unit]
Description=Fix theming script
StartLimitIntervalSec=0
Wants=fix-theming.timer
[Service]
Type=simple
Restart=always
RestartSec=1
Type=oneshot
ExecStart=/usr/bin/fix-theming
[Install]
WantedBy=default.target
WantedBy=multi-user.target

@ -3,13 +3,11 @@
[Unit]
Description=Fix tweaked desktop files script
StartLimitIntervalSec=0
Wants=fix-tweaked-desktop-files.timer
[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/usr/bin/fix-zombie-appicons
Type=oneshot
ExecStart=/usr/bin/fix-tweaked-desktop-files
[Install]
WantedBy=default.target
WantedBy=multi-user.target

@ -0,0 +1,14 @@
# This timer unit is for fix-flatpaks-theming service unit
#
[Unit]
Description=Run fix flatpaks theming script every 600 seconds
Requires=fix-flatpaks-theming.service
[Timer]
Unit=fix-flatpaks-theming.service
OnBootSec=1
OnUnitActiveSec=600
[Install]
WantedBy=timers.target

@ -0,0 +1,14 @@
# This timer unit is for fix-theming service unit
#
[Unit]
Description=Run fix theming script every 3 seconds
Requires=fix-theming.service
[Timer]
Unit=fix-theming.service
OnBootSec=1
OnUnitActiveSec=3
[Install]
WantedBy=timers.target

@ -0,0 +1,14 @@
# This timer unit is for fix-tweaked-desktop-files service unit
#
[Unit]
Description=Run fix tweaked desktop files script every 5 seconds
Requires=fix-tweaked-desktop-files.service
[Timer]
Unit=ffix-tweaked-desktop-files.service
OnBootSec=1
OnUnitActiveSec=5
[Install]
WantedBy=timers.target

@ -1,17 +0,0 @@
# Sync the QT with GTK
export QT_QPA_PLATFORMTHEME="gtk2"
export QT_QUICK_CONTROLS_STYLE="gtk2"
export QT_AUTO_SCREEN_SCALE_FACTOR=1
# Show color output in less
export LESS=-R
export LESS_TERMCAP_mb=$'\e[1;31m'
export LESS_TERMCAP_md=$'\e[1;36m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;44;33m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;32m'
export LESS_TERMCAP_ue=$'\e[0m'
# Disable the beep sound
[ -n "$DISPLAY" ] && xset b off