This is how I remember I did it:
Put the scripts into /home/purism/bin (watch-modem.sh, recover-modem.sh):
purism@pureos:~$ ls -l bin/*modem*
-rwxr-xr-x 1 root root 310 2. Jun 11:00 bin/recover-modem.sh
-rwxr-xr-x 1 purism purism 1404 2. Jun 10:56 bin/watch-modem.sh
recover-modem.sh is called as root (using sudo) - make it belong to root (like shown above) using this command:
sudo chmod 775 /home/purism/bin/recover-modem.sh; sudo chown root:root /home/purism/bin/recover-modem.sh
Edit your sudoers configuration to let purism run recover-modem.sh as root: sudo visudo /etc/sudoers.d/11_recover-modem
Copy the following into the editor and save the file:
Cmnd_Alias RECOVER_MODEM_CMD = /home/purism/bin/recover-modem.sh
User_Alias RECOVER_MODEM_GRP = purism
RECOVER_MODEM_GRP ALL=NOPASSWD: RECOVER_MODEM_CMD
Put the service file into /home/purism/.config/systemd/user/watchmodem.service
purism@pureos:~$ ls -l .config/systemd/user/watchmodem.service
-rw-r--r-- 1 purism purism 158 27. Mai 12:46 .config/systemd/user/watchmodem.service
Reload systemd config: systemctl --user daemon-reload
Enable the service: systemctl --user enable watchmodem
Check the service: systemctl --user status watchmodem
My output looks like this:
purism@pureos:~$ systemctl --user status watchmodem
● watchmodem.service - Watch Modem of Librem5
Loaded: loaded (/home/purism/.config/systemd/user/watchmodem.service; enabled; preset: enabled)
Active: active (running) since Fri 2022-09-23 12:24:38 CEST; 3 days ago
Main PID: 796 (watch-modem.sh)
Tasks: 3 (limit: 3124)
Memory: 40.4M
CPU: 2min 14.411s
CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/watchmodem.service
├─796 /bin/bash /home/purism/bin/watch-modem.sh
├─800 journalctl -f SYSLOG_IDENTIFIER=ModemManager
└─801 /bin/bash /home/purism/bin/watch-modem.sh
Sep 26 08:56:06 pureos /home/purism/bin/watch-modem.sh[15249]: found: 'QMI endpoint hangup: removed'
Sep 26 08:56:06 pureos watch-modem.sh[15252]: Playing WAVE '/home/purism/.local/share/sounds/__custom/glass.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Sep 26 08:56:17 pureos /home/purism/bin/watch-modem.sh[15386]: seems like modem recovered by itself
...
Didn’t re-install and check all the steps like written down here - so follow with care and if anything doesn’t work let me know.
I agreed to build a package of this as a temporary solution until the cause for the disconnects is found and taken care of. Will be part of bm818-tools.
If anybody installs this manually it will have to be removed when the package is ready and might be installed via dependencies. I’ll write about it in this thread so that anybody will be informed (you can watch the thread or watch the repo for the merge request that’ll come sometimes).