Commit Graph

24 Commits

Author SHA1 Message Date
Peter John Hartman
de28df34f8 networkmonitor: move logs to debugs
Logging each state change spams up the logfile quite a bit, so move it
to debug.
2023-02-17 05:37:47 -06:00
ArenM
80bdd6ba97 networkmonitor: handle unavailable state and log unknown states
Signed-off-by: Stacy Harper <contact@stacyharper.net>
2022-12-18 09:08:22 +01:00
ArenM
15526adc19 network_monitor: replace stderr with sxmo_log
stderr is just an alias to sxmo_log, so by replacing it with sxmo_log we
save a little code.

Signed-off-by: Peter John Hartman <peterjohnhartman@gmail.com>
2022-05-01 08:46:03 -05:00
ArenM
c983708aa7 Pass interface type to network hooks, and status
This fetches the network interface type from NetworkManager and passes
it to the network status hooks, as well as the statsubar. Doing this
should make the defaults independent of interface names.

Signed-off-by: Peter John Hartman <peterjohnhartman@gmail.com>
2022-05-01 08:46:03 -05:00
ArenM
474f9bd18e network_monitor: replace dbus-monitor with nmcli device monitor
If a interface is removed when it goes offline (this seems to happen
when using wireguard with wg-quick), we can't get the interface name,
and the network hooks don't work correctly.

Signed-off-by: Peter John Hartman <peterjohnhartman@gmail.com>
2022-05-01 08:46:03 -05:00
Anjandev Momi
1123c0f072 Change license to AGPL-3.0-only 2022-03-15 08:00:00 -04:00
Peter John Hartman
8a784c0b95 fix shellcheck errors
I removed the sxmo_debug but didn't remove the empty vars.
Thanks to Aren.
2022-02-22 16:25:37 -06:00
Peter John Hartman
492c9760b9 remove sxmo_debug
these aren't really useful and generate a lot of spam.
2022-02-20 19:39:24 -06:00
Stacy Harper
92c258f990 Make sxmo hooks scripts in PATH
We then add /usr/share/sxmo/default_hooks/ to the PATH (see
sxmo_init.sh)
2022-02-11 17:04:11 +01:00
Peter John Hartman
76b423ee30 Mute some pgreps
Signed-off-by: Stacy Harper <contact@stacyharper.net>
2022-01-26 21:40:20 +01:00
Peter John Hartman
18f0fa9149 Add sxmo_log and sxmo_debug functions
Signed-off-by: Stacy Harper <contact@stacyharper.net>
2022-01-24 21:03:30 +01:00
Stacy Harper
fb9e94ca4d Quote variables ! 2022-01-17 14:16:55 +01:00
Stacy Harper
a37b60b792 Networkmonitor: Trigger cleaning exit on default exit too 2022-01-17 14:15:43 +01:00
Peter John Hartman
04d7714ee7 networkmonitor: statusbar fix
Signed-off-by: Stacy Harper <contact@stacyharper.net>
2022-01-17 14:07:38 +01:00
Stacy Harper
337bd9c13e network: fix launch to use daemon right 2022-01-17 13:39:22 +01:00
Peter John Hartman
53d3af9134 sxmo_networkmonitor.sh: detect device type
Is there an easier way to retrieve the device name ?

Signed-off-by: Stacy Harper <contact@stacyharper.net>
2022-01-17 13:24:25 +01:00
Stacy Harper
d32bc7e02e Refact: Daemons management
Add a sxmo_daemons to manage all sxmo daemons

$ sxmo_daemons.sh start mmsd mmsdtng
$ sxmo_daemons.sh start network_monitor sxmo_networkmonitor.sh
$ sxmo_daemons.sh start sleepy sleep 2

$ sxmo_daemons.sh start network_monitor sxmo_networkmonitor.sh
-> This will stop the old daemon and start a new one

$ sxmo_daemons.sh running network_monitor
network_monitor is still running
$ echo $?
0

$ sxmo_daemons.sh running unknown
unknown is not running
$ echo $?
1

$ sxmo_daemons.sh running sleepy
sleepy is not running anymore
$ echo $?
2

$ sxmo_daemons.sh running network_monitor -q && echo "tada !"
tada !

$ sxmo_daemons.sh stop network_monitor
$ sxmo_daemons.sh stop all # to stop every managed daemons

We can now start, stop and check daemons status with ease. When
dwm/sway shutdown, we stop all daemons. Restarting or toggleing window
manager cannot leave any dangling daemons anymore.

As you can see, all daemons now start from the start hook. We gave the
full power on the user to disable or add daemons.

This patch is painfull cause I had to make sure every daemons behave
correctly and shutdown gracefully when killed (which was definitely not
the case !).

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2022-01-15 11:30:49 +01:00
Stacy Harper
57c5ee2352 Refact: status bar
The current sxmo status bar cause a high cpu usage periodically. It was
working by triggering a script that build the whole line.

This is a proposition to improve this implementation:

The design is very simple. We got a root dir that contains files. We
will cat those file contents sorted by the file names.

This way we can update a specific part and the rewriting will then be
very light.

Some abstraction to make it simple:

$ sxmo_status.sh show

To display the current content

$ sxmo_status.sh debug

To help fuzzy developpers like me

$ sxmo_status.sh watch

To watch updates of the component files. Will stdout the new line on
change.

$ sxmo_status.sh add 99-time "11:35" # or
$ printf "11:35" | sxmo_status.sh add 99-time

To add or re-write the component 99-time with the content "11:35"

$ sxmo_status.sh del 99-time

To drop a component

Then, to wrap some of the sxmo status bar component we will still use
the statusbar hook. It make it easy for the user to override or drop
some components.

$ sxmo_hooks.sh statusbar time

To set the time based on the current time. Here other existing
components:

$ sxmo_hooks.sh statusbar call_duration
$ sxmo_hooks.sh statusbar modem
$ sxmo_hooks.sh statusbar modem_monitor
$ sxmo_hooks.sh statusbar wifi
$ sxmo_hooks.sh statusbar vpn
$ sxmo_hooks.sh statusbar battery
$ sxmo_hooks.sh statusbar volume

Or to rewrite everything:

$ sxmo_hooks.sh statusbar all

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2022-01-15 11:30:40 +01:00
Zach DeCook
6274f1f222 shebangs: change to /bin/sh
Any sane linux system will have a posix compliant shell at /bin/sh
This change will allow us to better detect running scripts using pgrep.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2021-12-20 14:29:25 +01:00
Peter John Hartman
5181a5125f networkmonitor: fix to detect state changes
1. Our original version of sxmo_networkmonitor.sh was checking
interface 'org.freedesktop.NetworkManager' when it should be
'org.freedesktop.NetworkMananger.Device'.  By chance, the 'up'
detection worked, but the others (down, pre-down) did not.

2. It also did not check for pre-up.

3. Also, the /etc/NetworkMananger/dispatcher.d/10-statusbarupdate.sh
is both not needed and actually wouldn't have been working, since
it would have run as root.

4. Finally, sxmo_networkmonitor.sh was not being stopped when the wm
ended (so it would break if you did Toggle WM).

Hence, this patch fixes all of the above.  We *could* down the road
move all of this into /etc/NetworkMananger/dispatcher.d / pre-up.d,
etc., since what we do here is basically what those scripts do.
However, that would require somewhat complicated doas rules, since
those scripts run as root.

I kind of think this is the simpler approach after all.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2021-12-09 22:37:14 +01:00
Peter John Hartman
d7aa42e63c fixup! Cleanup echoes to include date.
Signed-off-by: Anjandev Momi <anjan@momi.ca>
2021-11-22 13:57:55 -05:00
Peter John Hartman
3b98939463 Cleanup echoes to include date.
Signed-off-by: Stacy Harper <contact@stacyharper.net>
2021-11-18 11:29:34 +01:00
Stacy Harper
e6ea657634 Cleanup hooks
This add a script to use either the user hook or the default one.

Sometime we checked the user hook or a default code. We move this
default code in a defaut hook.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2021-06-29 22:43:16 +02:00
Maarten van Gompel
35e39dbb90 implemented sxmo_networkmonitor to monitor when the network goes up/down and execute hooks
This implement a dbus monitor for networkamanger and is useful to
start/stop/restart certain things in user-defined hooks when
connectivity is gained/lost. By default all
it does is ensure the status bar is updated quickly to reflect the
network status.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2021-06-21 23:03:48 +02:00