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

Management of /etc/* config files in xsh #1

Open
ghost opened this issue Jan 3, 2021 · 1 comment
Open

Management of /etc/* config files in xsh #1

ghost opened this issue Jan 3, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Jan 3, 2021

Regarding Bash, I have configurations in /etc/bash.bashrc that I used as pre-configs before ~/.bashrc for regular users as well as configs for root user (interactively). Now when I enter in Bash non-login interactively with some user account, this file gets sourced first before xsh. In there, there's also these lines that came with the distro (Arch):

[[ $- != *i* ]] && return

[[ $DISPLAY ]] && shopt -s checkwinsize
[ -r /usr/share/bash-completion/bash_completion   ] && . /usr/share/bash-completion/bash_completion

My question is, how could I organize this with xsh? I'm looking for a fresh start with separate configs for root and regular users. Should I just delete this file and put everything in the @interactive.bash runcom or would it cause problems? Should I instead make a xsh directory for root user and just copy this file to its interactive runcom?

Same question goes with the /etc/profile file which came with more complicated code, including the umask and functions accessible to /etc/profile.d:


# Set our umask
umask 022

# Append "$1" to $PATH when not already in.
# This function API is accessible to scripts in /etc/profile.d
append_path () {
    case ":$PATH:" in
        *:"$1":*)
            ;;
        *)
            PATH="${PATH:+$PATH:}$1"
    esac
}

# Append our default paths
append_path '/usr/local/sbin'
append_path '/usr/local/bin'
append_path '/usr/bin'

# Force PATH to be environment
export PATH

# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
        for profile in /etc/profile.d/*.sh; do
                test -r "$profile" && . "$profile"
        done
        unset profile
fi

# Unload our profile API functions
unset -f append_path

# Source global bash config, when interactive but not posix or sh mode
if test "$BASH" &&\
   test "$PS1" &&\
   test -z "$POSIXLY_CORRECT" &&\
   test "${0#-}" != sh &&\
   test -r /etc/bash.bashrc
then
        . /etc/bash.bashrc
fi

# Termcap is outdated, old, and crusty, kill it.
unset TERMCAP

# Man is much better than us at figuring this out
unset MANPATH

I'm unsure if moving this or the /etc/bash.bashrc will break things, but if possible I'd rather have this in @login runcoms for separate users, would it be possible to delete it and just copy its contents? Should I just copy it without deleting, or maybe a hardlink or maybe don't do anything and make changes only to the ~/.bash_profile @login runcom? I'm looking for advices on how to deal with these /etc/ configs, for Bash and the /etc/zshenv, /etc/zsh/profile configs.

@sgleizes
Copy link
Owner

sgleizes commented Jan 6, 2021

Hello,

Currently, xsh doesn't support system configuration files, but it's something I've been considering for the next version.
It's somewhat tricky because each distribution comes with a different setup, and sometimes shells are compiled with different settings that affect where startup files are supposed to be.
I will close this issue if I ever get it done.

In the meantime, the simplest is to keep arch's default setup, where essentially /etc/profile is sourced for all login shells.
As you pointed out arch also comes with /etc/bash.bashrc which is sourced for bash interactive shells.

If you delete these files, pacman will probably recreate them the next time you upgrade. However, you can keep the files empty and move their contents elsewhere, pacman will then create a .pacnew file whenever it tries to install a new version of that file.

If you really want to move these config snippets to user configuration, you can do so at the cost of duplicating them for each user:

  • Use a posix module with @login.sh being a copy of /etc/profile. Make sure to register it first in init.sh and for all shells you want to support. Registering this module from the zsh init file (init.zsh) is basically equivalent to arch's default /etc/zsh/zprofile.
  • For the profile.d directory, you can use a similar mechanism with files residing in a subdirectory of the module.
  • Use a bash module with @interactive.bash being a copy of /etc/bash.bashrc. Make sure to register it first in init.bash. This runcom can be in a module of the same name than the one for /etc/profile (except it's for bash). I also think you can remove the part from /etc/profile that sources /etc/bash.bashrc, as xsh should properly take care of that logic.

See the README for more details about how to achieve this.

I hope this helps. I will post here status updates on system config support if I manage to find the time.

@sgleizes sgleizes added the enhancement New feature or request label Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant