Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui: simplify webui-desktop script #4919

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pyanaconda/ui/webui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
import os
import meh

from pyanaconda import ui
Expand Down Expand Up @@ -114,8 +113,6 @@ def run(self):
# This is read by cockpit-desktop and makes it launch Firefox in kiosk mode
# instead of the GTK WebKit based web view it launches by default.

# pylint: disable=environment-modify
os.environ["BROWSER"] = "/usr/bin/firefox --kiosk"
proc = startProgram(["/usr/libexec/webui-desktop",
"/cockpit/@localhost/anaconda-webui/index.html"],
reset_lang=False)
Expand Down
62 changes: 6 additions & 56 deletions ui/webui/webui-desktop
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,6 @@ set -eu
exec_prefix="/usr"
libexecdir="/usr/libexec"

# find suitable browser, unless already set by $BROWSER
# We can't use xdg-open, it does too much magic behind the back to connect to
# existing instances (outside of our namespace) and does not allow us to reduce
# the UI, or pass options like chromium's --no-sandbox.
detect_browser()
{
[ -z "${BROWSER:-}" ] || return 0

# First choice, but it depends on gi.repository WebKit2, so check it
if /usr/libexec/cockpit-client --help >/dev/null 2>/dev/null; then
BROWSER="/usr/libexec/cockpit-client --disable-uniqueness --no-ui --external-ws"
return 0
fi

for browser in chromium-browser chromium google-chrome; do
if type $browser >/dev/null 2>&1; then
# need to disable sandboxing in user namespace, but that already isolates
# TODO: Find a way to disable the URL bar
BROWSER="$browser --no-sandbox --disable-infobars"
return 0
fi
done

if type firefox >/dev/null 2>&1; then
# TODO: Find a way to disable the privacy notice tab, via mozilla.cfg?
# TODO: Find a way to disable the URL bar
BROWSER="firefox --no-remote"
return 0
fi

# TODO: is there a simple way to use webkitgtk?
echo "No suitable browser found (Chromium/Chrome, or Firefox)" >&2
exit 1
}


if [ -z "${1:-}" ]; then
echo "Usage: $0 <Cockpit path> [ssh host]" >&2
exit 1
Expand All @@ -97,35 +61,23 @@ case "$1" in
;;
esac

detect_browser

# start the bridge; this needs to run in the normal user session/namespace
coproc ${2:+ssh "$2"} cockpit-bridge
trap "kill $COPROC_PID; wait $COPROC_PID || true" EXIT INT QUIT PIPE

# start ws and browser in a detached network namespace
SCRIPT='
set -eu
# new namespaces have lo down by default
ip link set lo up >&2
BROWSER="/usr/bin/firefox --kiosk"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm using this variable on my Firefox theme PR: https://github.com/rhinstaller/anaconda/pull/4918/files#diff-4384704581bd02e11beb389b584be16b175b80679194ac91422ed2701d8bd3bdR139

I wonder - now that we started changing it maybe this script is a better place for the theme handling than the UI handling Python code where I put it in my PR ? What do you think ?

We might have to solve live/boot.iso detection somehow, but otherwise it should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it probably makes more sense that the theming gets applied here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I'll adjust #4918 accordingly. :)


# start browser in a temporary home dir, so that it does not interfere with your real one
export BROWSER_HOME=$(mktemp --directory --tmpdir cockpit.desktop.XXXXXX)
BROWSER_HOME=$(mktemp --directory --tmpdir cockpit.desktop.XXXXXX)

# forward parent stdin and stdout (from bridge) to cockpit-ws
# it pretty well does not matter which port we use in our own namespace, so use standard http
# disable /etc/cockpit/
XDG_CONFIG_DIRS="$BROWSER_HOME" COCKPIT_SUPERUSER="pkexec" '${COCKPIT_WS:-/usr/libexec/cockpit-ws}' -p 80 -a 127.0.0.90 --local-session=- <&0 >&1 &
XDG_CONFIG_DIRS="$BROWSER_HOME" COCKPIT_SUPERUSER="pkexec" /usr/libexec/cockpit-ws -p 80 -a 127.0.0.90 --local-session=cockpit-bridge &
WS_PID=$!
# ... and stop using that stdin/out for everything else
exec 0</dev/null
exec 1>&2

trap "set +e; kill $WS_PID; wait $WS_PID; rm -rf $BROWSER_HOME" EXIT INT QUIT PIPE
trap 'set +e; kill $WS_PID; wait $WS_PID; rm -rf $BROWSER_HOME' EXIT INT QUIT PIPE

# if we have netcat, use it for waiting until ws is up
if type nc >/dev/null 2>&1; then
for retry in `seq 10`; do
for _ in `seq 10`; do
nc -z 127.0.0.90 80 && break
sleep 0.5;
done
Expand All @@ -134,6 +86,4 @@ else
sleep 3
fi

HOME="$BROWSER_HOME" '$BROWSER' http://127.0.0.90'"$URL_PATH"'
'
/bin/bash -c "$SCRIPT" <&${COPROC[0]} >&${COPROC[1]}
HOME="$BROWSER_HOME" $BROWSER http://127.0.0.90"$URL_PATH"