Bug 54717 - ucr command line completion not working in screen and sudo shells
Summary: ucr command line completion not working in screen and sudo shells
Status: CLOSED FIXED
Alias: None
Product: UCS
Classification: Unclassified
Component: General
Version: UCS 5.0
Hardware: Other Linux
: P5 normal
Target Milestone: UCS 5.2-1-errata
Assignee: Arvid Requate
QA Contact: Juan Pedro Torres
URL: https://git.knut.univention.de/univen...
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-05 17:06 CEST by Arvid Requate
Modified: 2025-05-28 13:40 CEST (History)
6 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 4: Minor Usability: Impairs usability in secondary scenarios
Who will be affected by this bug?: 3: Will affect average number of installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.206
Enterprise Customer affected?: Yes
School Customer affected?:
ISV affected?:
Waiting Support: Yes
Flags outvoted (downgraded) after PO Review:
Ticket number: 2025012921000224, 2025032121000164, 2025032221000055, 2025051521000065, 2025032521000102
Bug group (optional): Usability
Customer ID:
Max CVSS v3 score:


Attachments
Proposed patch (1.20 KB, patch)
2022-07-04 11:21 CEST, Nikola Radovanovic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arvid Requate univentionstaff 2022-05-05 17:06:47 CEST
Noticed during support cases, Phoenix deployments and personal development machines:


In UCS 5.0 the bash command line completion does not work in screen and sudo sessions that are not login sessions.

After running `. /etc/profile` the commands in /etc/profile.d/bash_completion.sh are run and bash completion works.

If `echo $BASH_COMPLETION_VERSINFO` doesn't produce output, then that's not been loaded.

It works when you get a login shell as root directly.
Comment 1 Arvid Requate univentionstaff 2022-06-28 13:55:11 CEST
Workaround:

. /etc/profile.d/bash_completion.sh
Comment 2 Nikola Radovanovic univentionstaff 2022-07-04 11:21:50 CEST
Created attachment 10962 [details]
Proposed patch

Can we try with this one?

I manually edited /etc/bash.bashrc on one of my VMs and rebooted it.
Comment 3 Philipp Hahn univentionstaff 2022-07-06 15:28:37 CEST
A "interactive *non*-login shell" starts sourcing `bashrc` instead of `profile`.
In Debian the later `profile` always sources the former `bashrc` by default.

While /etc/bash.bashrc does *not* source `bash_completion.sh`, this is done explicitly by /etc/skel/.bashrc which normal users get by default.

Completion is neither sourced by /root/.profile nor by /root/.bashrc
For a "root" *login* shell it still is sourced via /etc/profile
These files are all installed by package "base-files" and shipped in /usr/hsare/base-files/{dot.{profile,bashrc},profile}

But `screen` or `sudo` do *not* get completion sourced:
Both do *not* use a "login-shell" by default; you have to explicitly request that using `sudo -i` or `screen -s -bash`.
As such they use `/root/.bashrc` only, which does not source completion.

See <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=275623#54>

<https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html>

# interactive login
`bash --login` | `-bash`
+- `--noprofile`
   +- /etc/profile
   |  . /etc/bash.bashrc
   |  . /etc/profile.d/*.sh
   |      . /etc/profile.d/bash_completion.sh
   +--+- $HOME/.bash_profile
      +- $HOME/.bash_login
      +- $HOME/.profile
         . $HOME/.bashrc
`sh --login` | `-sh`
+- `--noprofile`
   +- /etc/profile
   +- $HOME/.profile

# interactive non-login shell
`bash -i`
+--+- `--norc`
   +- `--rcfile …`
   +- $HOME/.bashrc
   +- /etc/bash.bashrc
`sh -i`
+- $ENV

# non-interactive non-login shell
`bash -c` | `#!/bin/bash`
+- $BASH_ENV
`sh -c` | `#!/bin/sh`
NOTHING


(In reply to Nikola Radovanovic from comment #2)
> Created attachment 10962 [details]
> Proposed patch

No, the "bug" is in /root/.bashrc (AKA /usr/share/base-files/dot.bashrc) not sourcing /etc/profile.d/bash_completion.sh


(In reply to Arvid Requate from comment #0)
> In UCS 5.0 the bash command line completion does not work in screen and sudo
> sessions that are not login sessions.

Use `sudo -i` or `screen -s -bash` for now.
Comment 4 Nikola Radovanovic univentionstaff 2022-07-12 11:39:01 CEST
Thank you!
Comment 5 Mirac Erdemiroglu univentionstaff 2025-05-17 05:36:44 CEST
A good way to fix this issue is to edit the template and remove the 'out' commands (marked with #), so that bash completion can be used.

vim /etc/univention/templates/files/etc/bash.bashrc

 # enable bash completion in interactive shells
-#if ! shopt -oq posix; then
-#  if [ -f /usr/share/bash-completion/bash_completion ]; then
-#    . /usr/share/bash-completion/bash_completion
-#  elif [ -f /etc/bash_completion ]; then
-#    . /etc/bash_completion
-#  fi
-#fi
+if ! shopt -oq posix; then
+ if [ -f /usr/share/bash-completion/bash_completion ]; then
+   . /usr/share/bash-completion/bash_completion
+ elif [ -f /etc/bash_completion ]; then
+   . /etc/bash_completion
+ fi
+fi
 
 if [ -e "$HOME/.univention-environment" ]; then
 	. "$HOME/.univention-environment"



To write the changes in the bashrc make an commit:
ucr commit /etc/bash.bashrc



Bash completion should now work. You can verify that the profile is loaded by running the following command and should get a output.
echo $BASH_COMPLETION_VERSINFO

Example:
root@dc0:~# echo $BASH_COMPLETION_VERSINFO
2


It would be great to include an update to release the fix, as the main improvements come from the patch file. This bug has been around for three years, and now we have a solid solution to resolve it. Let's take this opportunity to address it promptly!
Comment 6 Juan Pedro Torres univentionstaff 2025-05-23 12:18:02 CEST
Package build for 5.2-1

Successful build
Package: univention-base-files
Version: 11.0.13
Branch: 5.2-0
Scope: errata5.2-1
User: jtorres
Host: ladda
Comment 7 Juan Pedro Torres univentionstaff 2025-05-23 13:01:25 CEST
QA: OK
upgrade: OK
Comment 8 Christian Castens univentionstaff 2025-05-28 13:40:32 CEST
<https://errata.software-univention.de/#/?erratum=5.2x113>