Page 1 of 1

sed script to remove xload items from tray

Posted: Sat Mar 13, 2021 8:52 pm
by s243a

Currently, this is just a one liner but I'll edit this post shortly to put it in script format. The one liner is for testing.

Code: Select all

cat ./.jwmrc-tray | sed -rn '/^.*<\/Swallow>.*$/ {H;x;s#(.*)(<Swallow[^<]*.*xload.*$)#\1#p;x;d};{H;};$ {x;p}'

My motivation here, is that in the highly restricted containers used by @rufwoof and also possibly EasyOS users by default, I noticed that the xload tag is problematic and any errors in an init script cause the container to fail to start. Also in general I would like to minimize the amount of try based applications running when starting a desktop in a chroot or container to save system resources.

However, it should be easy enough for the end user to do this so in any chroot/container based system I distributed I would just like to remove the most problematic tray items and leave it up to the user if they want to remove more. Also I want some consistency between more highly restricted environment and lower restricted environments (e.g. just using unshare to get a unique process namespace).

I was able to do this with a simpler script in previous container based systems I've released but in the next example, I'm trying, "4.31 Phoenix - An update of 4.31 with glibc 2.19", the relevant xml tags span multipole lines. Here is an example:

Code: Select all

		<Swallow name="xload" width="32">
			xload -nolabel -bg "#888888" -fg red -hl white
		</Swallow>

also note, that I'm planning to implement an option to have specific .jwmrc and .jwmrc-tray files for the container. If these files exist they will be renamed from .jwmrc_container and .jwmrc-tray_container to .jwmrc and .jwmrc-tray respectively and otherwise, I will strip problematic components from these using sed, ssed, perl, python or awk.


Re: sed script to remove xload items from tray

Posted: Sat Mar 13, 2021 10:49 pm
by s243a

So after some futher testing here is the script:

Code: Select all

#!/bin/ssed -nrf
/^.*<\/Swallow>.*$/ {H;x;s#(.*)(<Swallow[^<]*.*xload.*$)#\1#g;p;s/.*//;x;d}
{H;}
$ {x;p}

The only difference functionally from the orginal one liner above is that rather than have "p" (, which is for print,) as an option to the substitution command the p is a following command. The difference is that when "p" is used as an option to the substitution command then printing will only happen if the command succeeds. However, p is a separate command then the pattern space will print regardless of weather or not the substitution succeeds.

Upon reflection I realize that you could have a closing "Swallow" tag (i.e. </Swallow>) without an xload in the inner xml. A work around might be to use branching but this isn't supported in all versions of said. That "said", I may try the branching approach.

So the script works as follows:
1. If we have a closing "Swallow tag (i.e. </Swallow>) then remove the last set of such tags if xload is part of the inner XML.
1b. Print the pattern space regardless of whether or not the above subsitution is made.
1c. Delete the pattern space "s/.*//"
1e. Swap the pattern space and the hold space "x"
1f. delete the pattern space and start the next cycle "d"
2. If alternatively we don't have a Closing "Swallow" tag then append the pattern space to the hold space "H"
3. If we are on the last line then print the hold space by first swapping the pattern space with the hold space "x" and then printing "p"

Some notes the -n option supresses automatic printing and the -r option means to use extended regular expressions.

Note that I'm only achoring the end of line (via the "$") because I don't know if "^" will match the beginning of the line or the beginning of the pattern space and also this way the expression should be valid whether or not I'm using multi-line mode. I tried multi-line mode without success. In multiline mode I see the folloiwng documented:

There are special character sequences ('`' and '\'') which always match the beginning or the end of the buffer. In addition, the period character does not match a new-line character in multi-line mode.

https://stackoverflow.com/questions/444 ... expression
https://unix.stackexchange.com/question ... ess-suffix
https://www.linuxforce.com.br/comandos- ... mando-sed/

However, I can't get these special character sequences to match the beginning and end of the pattern space to work so I'm not using multi-line mode.


Re: sed script to remove xload items from tray

Posted: Sun Mar 14, 2021 3:28 pm
by user1111

In Fatdog there is a program called 'sit' that adds a system tray icon. With Xephyr running a separate X server display you can drop a tray icon in from the main session into the Xephyr session, so from the main session (DISPLAY=:0) running something like

DISPLAY=:1 sit .....

Provided whatever tray icon is being run doesn't permit any interactions, just for instance displays a chart or whatever, then that should be fine. If the tray icon program enables interactions i.e. perhaps via a right click menu ... then that would be being run as DISPLAY :0 main session (i.e. a potential security weakness).

Off topic to this thread, but thought I'd just mention it as its somewhat related.