mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
exec shell: detect default shell
Instead of using configured shell (e.g. bash) we can autodetect default container user's shell and execute it. This is much safer because not all containers may have installed shell that is configured in ctop.
This commit is contained in:
parent
5ec02f760e
commit
53a6b36bf5
12
menus.go
12
menus.go
@ -358,8 +358,16 @@ func ExecShell() MenuFn {
|
||||
|
||||
ui.DefaultEvtStream.ResetHandlers()
|
||||
defer ui.DefaultEvtStream.ResetHandlers()
|
||||
|
||||
if err := c.Exec([]string{"/bin/sh", "-c", "printf '\\e[0m\\e[?25h' && clear && /bin/sh"}); err != nil {
|
||||
// Detect and execute default shell in container.
|
||||
// Execute Ash shell command: /bin/sh -c
|
||||
// Reset colors: printf '\e[0m\e[?25h'
|
||||
// Clear screen
|
||||
// Run default shell for the user. It's configured in /etc/passwd and looks like root:x:0:0:root:/root:/bin/bash:
|
||||
// 1. Get current user id: id -un
|
||||
// 2. Find user's line in /etc/passwd by grep
|
||||
// 3. Extract default user's shell by cutting seven's column separated by :
|
||||
// 4. Execute the shell path with eval
|
||||
if err := c.Exec([]string{"/bin/sh", "-c", "printf '\\e[0m\\e[?25h' && clear && eval `grep ^$(id -un): /etc/passwd | cut -d : -f 7-`"}); err != nil {
|
||||
log.StatusErr(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user