sed script, replace run-as-spot w/ root/"--no-sandbox"

interpretive language scripts


Moderator: Forum moderators

Post Reply
s243a
Posts: 501
Joined: Mon Dec 09, 2019 7:29 pm
Has thanked: 90 times
Been thanked: 37 times

sed script, replace run-as-spot w/ root/"--no-sandbox"

Post by s243a »

Chromium based puppies are meant to be ran as a less privileged users (e.g. spot) and Ideally we should do this. However, this won't always work (e.g. in a highly restricted container (See thread)) in which case one might want the option to run as root using the "--no-sandbox" option.

The intent of this thread is to illustrate some basic concepts of sed. The actual problem could be solved in a simpler way (e.g. just copying a new startup script for the browser) and really this doesn't take up much code since the startups scipts provided by @mikewalsh are only about 13 lines long.

That said, the sed code is only two lines long and if I'm incorporated it into a script to build a chrooted system I would rather minimize the lines of code and rely as much as possible on the code provided by the original startup script (i.e. change as little as possible).

The sed code is as follows:

Code: Select all

cat chromium-pup | sed -rn \
'/run-as-spot "\$HERE\/chrome"/ {s#^(.*)$#"$HERE/chrome" --no-sandbox --user-data-dir=$HERE/PROFILE --disable-infobars "$@"#g;}
/run-as-spot "\$HERE\/chrome"/! {p}' > chromium-pup-nosb 

There are two lines here. The first line checks if the line starts with 'run-as-spot "$HERE/chrome"' and if so then it replaces it with the following line:

Code: Select all

"$HERE/chrome" --no-sandbox --user-data-dir=$HERE/PROFILE --disable-infobars "$@"

The second line code checks to see if the pattern isn't matched and simply prints the line. I could do this with a single line of sed code via substitution. However, I think this pattern action approach is more structured (almost like a script) and it also results in simpler regular expressions.

Some notes on syntax. The -n option means to not automatically print. Printing instead is done via the "p" command or alternatively as the output of a substitution. The -r option means to use regular expressions. Inside the pattern, we escape the forward slash "/" with "\/" and the dollar sign "$" with "\$". The forward slash needs to be escaped because it defines the boundaries of the pattern. The dollar sign needs to be escaped because it represents the end of a line in a regular expression.

In my case I'm using this sed script to patch the start-up script for ungoogled-chromium, running in the Puli/Xenial64 with core libs upgraded via the rootfs of WDLGO_UbuntuFocal64 (see post). The browser is started in a chroot, sandbox or container. Running and idependent xserver via Xephyr.

In the script I built to chroot into an extracted system (for testing) the patching code is as follows:

Code: Select all

if [ ! -f "$CHROOT_FOLDER/opt/Ungoogled_Chromium-portable/chromium/chromium-pup-nosb" ]; then
  (cd "$CHROOT_FOLDER/opt/Ungoogled_Chromium-portable/chromium/"; cp -a  chromium-pup chromium-pup-nosb;
   cat chromium-pup | sed -rn \
'/run-as-spot "\$HERE\/chrome"/ {s#^(.*)$#"$HERE/chrome" --no-sandbox --user-data-dir=$HERE/PROFILE --disable-infobars "$@"#g;}
/run-as-spot "\$HERE\/chrome"/! {p}' > chromium-pup-nosb )
fi

I hope to provide multiple startup options. For example one option will be a highly restricted startup option like the contianer used by @rufwoof in the thread:
Fatdog unshare xephyr capsh container

User avatar
April
Posts: 493
Joined: Tue Dec 29, 2020 9:06 pm
Has thanked: 57 times
Been thanked: 28 times

Re: sed script, replace run-as-spot w/ root/"--no-sandbox"

Post by April »

Just a note to Opera users

Starting with "opera.bin --no-sandbox " similarly runs Opera as root. Put it in a desktop icon with argument to pass to the executable
Put it in your desktop shortcut command sent to opera.bin that is.

The Australian State Governments have all enacted laws to steal your assets on your death. All legal paperwork is binned and all assets seized on one disgruntled child's complaint.Move them well before you die or go into a home.

Post Reply

Return to “Scripts”