From 79f59b667b22b647253cb047a9c04cd60d1db03a Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Wed, 24 Apr 2019 19:36:36 +0200 Subject: [PATCH] Show a welcome text on interactive shells running on Silverblue hosts The welcome text uses the OSC 8 [1] escape sequence to add a hyperlink to the Silverblue documentation [2]. Silence a SC1003 [3] because the intention is to print the 'ESC \' string terminator (or ST), and not escape a single quote. [1] https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda [2] https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/ [3] https://github.com/koalaman/shellcheck/wiki/SC1003 https://github.com/debarshiray/toolbox/pull/127 --- meson.build | 3 +++ meson_options.txt | 6 ++++++ profile.d/meson.build | 10 ++++++++++ profile.d/toolbox.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 meson_options.txt create mode 100644 profile.d/meson.build create mode 100644 profile.d/toolbox.sh diff --git a/meson.build b/meson.build index 19c03a8..c747e02 100644 --- a/meson.build +++ b/meson.build @@ -8,6 +8,8 @@ project( go_md2man = find_program('go-md2man') shellcheck = find_program('shellcheck', required: false) +profiledir = get_option('profile_dir') + systemd_dep = dependency('systemd') tmpfilesdir = systemd_dep.get_pkgconfig_variable('tmpfilesdir') @@ -24,3 +26,4 @@ install_data( subdir('data') subdir('doc') +subdir('profile.d') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..fe9f410 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,6 @@ +option( + 'profile_dir', + description: 'Directory for profile.d files to be read by the shell on start-up', + type: 'string', + value: '/usr/share/profile.d' +) diff --git a/profile.d/meson.build b/profile.d/meson.build new file mode 100644 index 0000000..03b242c --- /dev/null +++ b/profile.d/meson.build @@ -0,0 +1,10 @@ +toolbox_sh = files('toolbox.sh') + +if shellcheck.found() + test('shellcheck profile.d', shellcheck, args: ['--shell=sh', toolbox_sh]) +endif + +install_data( + toolbox_sh, + install_dir: profiledir, +) diff --git a/profile.d/toolbox.sh b/profile.d/toolbox.sh new file mode 100644 index 0000000..da8cc1a --- /dev/null +++ b/profile.d/toolbox.sh @@ -0,0 +1,26 @@ +[ "$BASH_VERSION" != "" ] || [ "$ZSH_VERSION" != "" ] || return 0 +[ "$PS1" != "" ] || return 0 + +toolbox_config="$HOME/.config/toolbox" +host_welcome_stub="$toolbox_config/host-welcome-shown" + +if [ -f /run/ostree-booted ] \ + && ! [ -f "$host_welcome_stub" ]; then + echo "" + echo "Welcome to Fedora Silverblue. This terminal is running on the" + echo "immutable host system. You may want to try out the Toolbox for a" + echo "more traditional environment that allows package installation" + echo "with DNF." + echo "" + printf "For more information, see the " + # shellcheck disable=SC1003 + printf '\033]8;;https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/\033\\documentation\033]8;;\033\\' + printf ".\n" + echo "" + + mkdir -p "$toolbox_config" + touch "$host_welcome_stub" +fi + +unset toolbox_config +unset host_welcome_stub