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

[BUG] "Jail not found" when both CLICOLOR & CLICOLOR_FORCE environment variables are set #858

Closed
vegged opened this issue Feb 19, 2025 · 14 comments
Labels
bug Something isn't working

Comments

@vegged
Copy link

vegged commented Feb 19, 2025

When both shell environment variables CLICOLOR & CLICOLOR_FORCE are set to 1, several bastille commands (console, etcupdate, htop, jcp, rename, top, update) fail with the following error message:

Jail not found "jailname" 

Forced color escape sequences likely mess with pattern matching in common.sh, as unsetting CLICOLOR_FORCE fixes the issue.

Tested on Bastille 0.13.20250126 with zsh 5.9 (amd64-portbld-freebsd14.0) & GNU bash, version 5.2.37(0)-release (amd64-portbld-freebsd14.1) (all installed via pkg) on FreeBSD 14.2-RELEASE-p1.

@vegged vegged added the bug Something isn't working label Feb 19, 2025
@vegged
Copy link
Author

vegged commented Feb 19, 2025

This commit offers a fix.

@tschettervictor
Copy link
Collaborator

You can run those commands with -x to see what's going on.

@bmac2
Copy link
Collaborator

bmac2 commented Feb 19, 2025

so I have to ask. What is color escape sequences and why do you have them. This is not a bastille bug.

@bmac2 bmac2 added out of scope and removed bug Something isn't working labels Feb 19, 2025
@vegged
Copy link
Author

vegged commented Feb 20, 2025

so I have to ask. What is color escape sequences and why do you have them. This is not a bastille bug.

Setting the CLICOLOR environment variable seems to be a standard method for enabling colorized output for ls (as per ls(1)), while more -R, less -R require CLICOLOR_FORCE.

I believe this isn't an exotic shell environment scenario. Why not accommodate this fairly common FreeBSD setup?

@tschettervictor
Copy link
Collaborator

tschettervictor commented Feb 20, 2025

Can you share both vars and what you set them too? I'll investigate.

EDIT: note to self - read OP

@tschettervictor
Copy link
Collaborator

This has nothing to do with the common.sh functions, but rather the "list.sh" command that is used inside common.sh to list all the jails.

It uses "ls" to find them, and it looks like that might be interfering if one has the "CLICOLOR_FORCE" set to 1.

@tschettervictor
Copy link
Collaborator

root@dev1:~ # bastille list jails
+ [ 1 -gt 0 ]
+ list_jail
+ [ -d /usr/local/bastille/jails ]
+ ls /usr/local/bastille/jails
+ sed 's/\n//g'
+ JAIL_LIST=$'\033[38;5;4mbridge\033[39;49m\033[m
\033[38;5;4mbridge1\033[39;49m\033[m
\033[38;5;4mjail1\033[39;49m\033[m
\033[38;5;4mmy\033[39;49m\033[m
\033[38;5;4mtest\033[39;49m\033[m
\033[38;5;4mtime\033[39;49m\033[m
\033[38;5;4mvnet\033[39;49m\033[m'
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mbridge\033[39;49m\033[m/jail.conf' ]
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mbridge1\033[39;49m\033[m/jail.conf' ]
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mjail1\033[39;49m\033[m/jail.conf' ]
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mmy\033[39;49m\033[m/jail.conf' ]
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mtest\033[39;49m\033[m/jail.conf' ]
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mtime\033[39;49m\033[m/jail.conf' ]
+ [ -f $'/usr/local/bastille/jails/\033[38;5;4mvnet\033[39;49m\033[m/jail.conf' ]

@tschettervictor
Copy link
Collaborator

Can you test #859?
It removes the colour when listing jails.

@bmac2 bmac2 added bug Something isn't working and removed out of scope labels Feb 20, 2025
@bmac2
Copy link
Collaborator

bmac2 commented Feb 20, 2025

@vegged does the patch Victor wrote fix your issue?

@bmac2
Copy link
Collaborator

bmac2 commented Feb 22, 2025

@vegged what do you have in your .shrc for turning on CLICOLOR etc. I can't seem to get it to twork for me . Trying to set it up to test and confirm the errror then the fix.

@bmac2
Copy link
Collaborator

bmac2 commented Feb 22, 2025

@vegged here is my .shrc file. Are you using sh or another shell? Color works fine on all ls commands ll, l ls, etc. I cannot get an error listing jails in bastille with this set. What am I doing different than you, or what am I missing. I am using standard sh as my shell.

#
# .shrc - bourne shell startup file 
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#


# file permissions: rwxr-xr-x
#
# umask	022

# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi


# # some useful aliases
alias sudo="sudo -i "
alias h='fc -l'
alias j=jobs
alias m="$PAGER"
alias ll='ls -laFo'
alias l='ls -l'
alias g='egrep -i'
 
# # be paranoid
# alias cp='cp -ip'
# alias mv='mv -i'
# alias rm='rm -i'

# # csh like history on arrow up and down
bind ^[[A ed-search-prev-history
bind ^[[B ed-search-next-history

# # ctrl+arrow allow to jump from words to words
bind "\\e[1;5C" em-next-word
bind "\\e[1;5D" ed-prev-word
alias history='fc -l'

# Fix home/del for mobaxterm
bind ^[[5~ ed-move-to-beg
bind ^[[6~ ed-move-to-end

# read(2) of directories may not be desirable by default, as this will provoke
# EISDIR errors from each directory encountered.
# alias grep='grep -d skip'

# set prompt: ``username@hostname:directory $ '' 
PS1="\u@\h:\w \\$ "

# search path for cd(1)
# CDPATH=:$HOME


CLICOLOR=1
CLICOLOR_FORCE=1
export CLICOLOR
export CLICOLOR_FORCE

@bmac2
Copy link
Collaborator

bmac2 commented Feb 22, 2025

@vegged nevermind I was able to reproduce. Testing patch to fix this now.

if I su to root the bug is not there. IF I sudo su to root the bug is there.

@bmac2
Copy link
Collaborator

bmac2 commented Feb 22, 2025

Patch #859 has been merged to fix this.

@bmac2 bmac2 closed this as completed Feb 22, 2025
@vegged
Copy link
Author

vegged commented Feb 22, 2025

@vegged does the patch Victor wrote fix your issue?

Yes, @tschettervictor's approach works great, and is much more subtle than my patch, which took a somehow shotgun approach to the problem 😅

Thanks to you both for helping out and pushing a fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants