Open boredsquirrel opened 1 year ago
more complex version running the script on reboot, shutdown or logout:
mkdir -p ~/.config/systemd/user
mkdir ~/.config/autostop
# create unit
printf """[Unit]
Description=Execute scripts located at ~/.config/autostop on logout, shutdown or reboot
[Service]
Type=oneshot
ExecStart=/bin/true
#ExecStop=/usr/bin/find ~/.config/autostop/ -type f -name '*.sh' -exec /bin/bash {} \;
ExecStop=/bin/bash -c 'for file in ~/.config/autostop/*; do [[ -x "$file" ]] && "$file"; done'
[Install]
WantedBy=default.target""" > ~/.config/systemd/user/autostop.service
# enable
systemctl --user daemon-reload
systemctl --user enable autostop.service
The first version executes all found "*.sh" scripts.
The second version checks if files are executeable and executes them in that case. Both versions are pretty neat.
It seems systemd has a feature to check if it stops and execute a command in that case.
To use the cache-cleaner, just put it in that directory.
So here is the version using the autostop feature
touch ~/.cache-cleaner.log
printf """#!/bin/bash
rm ~/.cache-cleaner.log
find ~/.var/app/*/cache/ -type f -mtime +7 -print | tee >> ~/.cache-cleaner.log
find ~/.var/app/*/cache/ -type f -mtime +7 -delete
find ~/.cache/ -type f -mtime +7 -print | tee >> ~/.cache-cleaner.log
find ~/.cache/ -type f -mtime +7 -delete""" > ~/.config/autostop/cache-cleaner.sh
chmod +x ~/.config/autostop/cache-cleaner.sh
disable logging:
sed '/cache-cleaner/d' ~/.config/autostart/cache-cleaner.sh
sed '/cache-cleaner/d' ~/.config/autostop/cache-cleaner.sh
rm ~/.cache-cleaner.log
this is a good idea. from what i heard, apple has this sort of stuff. it would be better if we can just integrate this as background process after boot, rather than on shut down, since long shut down time can be irritating
This is very personal. For me I dont care if boot takes long, but I want the laptop to be there when I turn it on. So I would say end is way better.
I mean using the nice autostop service (I think I tried it, I dont know) you can just ask the user where to put it, and then put it there.
Also such a cache cleaner is not official. There is /tmp which is cleaned, there is ~/.cache with is cleaned, and the Flatpak apps themselves should manage their cache well. But I guess they dont, so no way will I not integrate that.
Some user meant this was a problem. It can not harm to delete old cache from various flatpaks. The command for that is: