Re: [systemd-devel] nsapwned container terminal background color

2017-03-20 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Mar 20, 2017 at 08:34:02AM +, arnaud gaboury wrote:
> > > Are you starting the container manually using systemd-nspawn in a
> > terminal
> > > emulator window?
> 
> Not really. The container is started at machine boot with
> systemd-nspawn@container.service. Then, in one urxvt terminal, I log into
> the container with :
> # machinectl login container
> 
> I have not yet tested your solution, but will do it today and come back
> wtih the result.
Oh, right. So this will have no effect and you need to try the other
solution I mentioned in the first reply.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] nsapwned container terminal background color

2017-03-20 Thread arnaud gaboury
On Mon, Mar 20, 2017 at 5:12 AM Zbigniew Jędrzejewski-Szmek <
zbys...@in.waw.pl> wrote:

> On Sun, Mar 19, 2017 at 09:30:05PM +, Zbigniew Jędrzejewski-Szmek
> wrote:
> > On Sun, Mar 19, 2017 at 04:37:53PM +, arnaud gaboury wrote:
> > > I am trying with no success to have one background terminal color for
> the
> > > host and another one for the container.
> > >
> > > Some settings:
> > > - on host:
> > > window manager : i3
> > > terminal : urxvt-256
> > >
> > > -on container:
> > > no X, it is a server.
> > >
> > > Until now, I have tried to write a wrapper script to urxvt on host.
> This
> > > script is to test value of $HOST or $TERM, then fire urxvt with
> background
> > > color as option. This does not work.
> > >
> > > I have to figure out  that when i log my container, I am first on an
> urxvt
> > > terminal which become, once I am logged as user on container, a xterm.
> > > I am totally lost where to write instruction as the terminal color
> > > background: on host or container? and what app shall be tested to set
> the
> > > environment and decide the bg color (agetty?) ?
> >
> > Are you starting the container manually using systemd-nspawn in a
> terminal
> > emulator window?


Not really. The container is started at machine boot with
systemd-nspawn@container.service. Then, in one urxvt terminal, I log into
the container with :
# machinectl login container

I have not yet tested your solution, but will do it today and come back
wtih the result.

Thank you


> If yes, then the following works (tested with gnome-terminal,
> > but I think urxvt supports the same sequences):
> >
> > [Unit]
> > DefaultDependencies=no
> > Conflicts=shutdown.target
> >
> > [Service]
> > StandardOutput=tty
> > ExecStart=/usr/bin/printf '\033]11;darkgreen\007'
> > ExecStop=/usr/bin/printf '\033]11;black\007'
> > Type=oneshot
> > RemainAfterExit=true
> >
> > [Install]
> > WantedBy=basic.target
> >
> > (It would be nicer to undo the setting and return to whatever the old
> > background was, but I don't know how to do this.)
> I figured it out, although it's a bit ugly ;)
>
> ==> /etc/systemd/system/bgcolor.service <==
> [Unit]
> DefaultDependencies=no
> Conflicts=shutdown.target
> Description=Set terminal background
>
> [Service]
> StandardInput=tty
> StandardOutput=tty
> ExecStart=/usr/local/bin/bgcolor.sh start /run/bgcolor.txt teal
> ExecStop=/usr/local/bin/bgcolor.sh stop /run/bgcolor.txt
> Type=oneshot
> RemainAfterExit=true
>
> [Install]
> WantedBy=sysinit.target
>
> ==> /usr/local/bin/bgcolor.sh <==
> #!/bin/sh -e
>
> file="$2"
> field=11  # background
>
> if [ "$1" == "start" ]; then
> color="$3"
>
> oldstty=$(stty -g)
> stty raw -echo min 0
> #  OSC   Ps  ;Pt ST
> printf "\033]${field};?\033\\"
> IFS=';' read -t1 -r -d '\' answer
> echo "$answer" | sed 's/^.*\;//;s/[^rgb:0-9a-f/]//g' >"$file"
> stty "$oldstty"
>
> printf "\033]${field};${color}\007"
> elif [ "$1" == "stop" ]; then
> color=$(cat "$file")
> printf "\033]${field};${color}\007"
> fi
>
> This will set the background to teal during early boot, storing the
> original color in the specified file, and reset it back during
> shutdown. It seems to interfere with the systemd console output
> (newlines get messed up), and sometimes the restoration does not
> work. I suspect that both issues are caused by interference of
> systemd printing to the console concurrently with the script. Most
> likely putting a verify loop around the query for original
> color would fix the second issue.
>
> Zbyszek
>
>
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] nsapwned container terminal background color

2017-03-19 Thread Zbigniew Jędrzejewski-Szmek
On Sun, Mar 19, 2017 at 09:30:05PM +, Zbigniew Jędrzejewski-Szmek wrote:
> On Sun, Mar 19, 2017 at 04:37:53PM +, arnaud gaboury wrote:
> > I am trying with no success to have one background terminal color for the
> > host and another one for the container.
> > 
> > Some settings:
> > - on host:
> > window manager : i3
> > terminal : urxvt-256
> > 
> > -on container:
> > no X, it is a server.
> > 
> > Until now, I have tried to write a wrapper script to urxvt on host. This
> > script is to test value of $HOST or $TERM, then fire urxvt with background
> > color as option. This does not work.
> > 
> > I have to figure out  that when i log my container, I am first on an urxvt
> > terminal which become, once I am logged as user on container, a xterm.
> > I am totally lost where to write instruction as the terminal color
> > background: on host or container? and what app shall be tested to set the
> > environment and decide the bg color (agetty?) ?
> 
> Are you starting the container manually using systemd-nspawn in a terminal
> emulator window? If yes, then the following works (tested with gnome-terminal,
> but I think urxvt supports the same sequences):
> 
> [Unit]
> DefaultDependencies=no
> Conflicts=shutdown.target
> 
> [Service]
> StandardOutput=tty
> ExecStart=/usr/bin/printf '\033]11;darkgreen\007'
> ExecStop=/usr/bin/printf '\033]11;black\007'
> Type=oneshot
> RemainAfterExit=true
> 
> [Install]
> WantedBy=basic.target
> 
> (It would be nicer to undo the setting and return to whatever the old
> background was, but I don't know how to do this.)
I figured it out, although it's a bit ugly ;)

==> /etc/systemd/system/bgcolor.service <==
[Unit]
DefaultDependencies=no
Conflicts=shutdown.target
Description=Set terminal background

[Service]
StandardInput=tty
StandardOutput=tty
ExecStart=/usr/local/bin/bgcolor.sh start /run/bgcolor.txt teal
ExecStop=/usr/local/bin/bgcolor.sh stop /run/bgcolor.txt
Type=oneshot
RemainAfterExit=true

[Install]
WantedBy=sysinit.target

==> /usr/local/bin/bgcolor.sh <==
#!/bin/sh -e

file="$2"
field=11  # background

if [ "$1" == "start" ]; then
color="$3"

oldstty=$(stty -g)
stty raw -echo min 0
#  OSC   Ps  ;Pt ST
printf "\033]${field};?\033\\"
IFS=';' read -t1 -r -d '\' answer
echo "$answer" | sed 's/^.*\;//;s/[^rgb:0-9a-f/]//g' >"$file"
stty "$oldstty"

printf "\033]${field};${color}\007"
elif [ "$1" == "stop" ]; then
color=$(cat "$file")
printf "\033]${field};${color}\007"
fi

This will set the background to teal during early boot, storing the
original color in the specified file, and reset it back during
shutdown. It seems to interfere with the systemd console output
(newlines get messed up), and sometimes the restoration does not
work. I suspect that both issues are caused by interference of
systemd printing to the console concurrently with the script. Most
likely putting a verify loop around the query for original
color would fix the second issue.

Zbyszek


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] nsapwned container terminal background color

2017-03-19 Thread Zbigniew Jędrzejewski-Szmek
On Sun, Mar 19, 2017 at 04:37:53PM +, arnaud gaboury wrote:
> I am trying with no success to have one background terminal color for the
> host and another one for the container.
> 
> Some settings:
> - on host:
> window manager : i3
> terminal : urxvt-256
> 
> -on container:
> no X, it is a server.
> 
> Until now, I have tried to write a wrapper script to urxvt on host. This
> script is to test value of $HOST or $TERM, then fire urxvt with background
> color as option. This does not work.
> 
> I have to figure out  that when i log my container, I am first on an urxvt
> terminal which become, once I am logged as user on container, a xterm.
> I am totally lost where to write instruction as the terminal color
> background: on host or container? and what app shall be tested to set the
> environment and decide the bg color (agetty?) ?

Are you starting the container manually using systemd-nspawn in a terminal
emulator window? If yes, then the following works (tested with gnome-terminal,
but I think urxvt supports the same sequences):

[Unit]
DefaultDependencies=no
Conflicts=shutdown.target

[Service]
StandardOutput=tty
ExecStart=/usr/bin/printf '\033]11;darkgreen\007'
ExecStop=/usr/bin/printf '\033]11;black\007'
Type=oneshot
RemainAfterExit=true

[Install]
WantedBy=basic.target

(It would be nicer to undo the setting and return to whatever the old
background was, but I don't know how to do this.)

If you are logging into an existing container using machinectl shell
or ssh, you can just the equivalent printfs to your ~/.profile.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel