I've hacked this together with random code from stack exchange I would love someone who can actually script to look it over and let me know what else I need to do to it.
the goals of this script,
Other goal for the script, to be ran as a cron job on @reboot/or system uptime+x (need to test how the steamdeck handles @reboot chron jobs) so that everytime the steam deck boots it changes to a random collection of boot animations
#!/usr/bin/env bash
shopt -s nullglob
files=(*.webm)
shopt -u nullglob
if [[ ${#files[@]} -eq 0 ]]; then
echo "No matching files!"
exit
fi
file=${files[$((RANDOM % ${#files[@]}))]}
cp "$file" ~/.local/share/Steam/steamui/overrides/movies/deck_startup.webm
end
I would like to have a hard location for the storage of the boot animations (~/.local/bootanimations)
thanks in advance, this is obviously above my skill level (Im sure my script is wrong) but I am learning as I go so breaking it down for me and pointing me to the resources I need to look at are very very welcome
Edit: Updated from feedback to be more clear and remove redundancy in code
Edit2: use systemd user timer instead of cron, solution below
turn on user timer
-------------------------
systemctl --user enable rba.timer
-------------------------
/home/deck/.config/systemd/user/rba.timer
-------------------------
[Unit]
Description=Random Boot Animation Timer
[Timer]
OnBootSec=5min
[Install]
WantedBy=timers.target
-------------------------
/home/deck/.config/systemd/user/rba.service
-------------------------
[Unit]
Description=service for timer
[Service]
Type=simple
ExecStart=/home/user/.config/systemd/user/rba.sh
-------------------------
/home/deck/.config/systemd/user/rba.sh
-------------------------
#!/usr/bin/env bash
shopt -s nullglob
files=(/home/deck/.local/bootanimations/*.webm)
shopt -u nullglob
if [[ ${#files[@]} -eq 0 ]]; then
echo "No matching files!"
exit
fi
file=${files[$((RANDOM % ${#files[@]}))]}
cp "$file" ~/.local/share/Steam/steamui/overrides/movies/deck_startup.webm
Is the goal specifically to use a timer or just activate on boot? It's not clear if you're doing this to learn timers.
If it's just to work on boot, add this to your service file:
[Install]
WantedBy=default.target
If you'd like the service to also run when the Steam Deck switches into desktop mode you can add:
[Install]
WantedBy=default.target
WantedBy=graphical-session.target
Additionally, you don't have to place the .service file into the .config/systemd/[...] location yourself if you include the above in your .service file. When you systemctl --user enable /path/to/rba.service
it will automatically create the correct symlinks into the correct systemd folder for the intended target. systemctl --user disable rba.service
will delete the symlink for you.
I don't have the graphical-session.target added to the main branch in my own code yet but if you'd like to look over my randomizer system, do let me know. It seems like your goal is to learn more than it is to just get it done, don't want to overstep by just blasting the link out.
This is what I used to learn how to structure .service unit files: https://wiki.archlinux.org/title/systemd
Also, couple general suggestions. Instead of a full cp, you could just create a symlink to the uioverrides/movies/deck_startup.webm location. That way you're not actually moving files and your video files can stay exactly where they are!