Skip to content

Commit

Permalink
Configure bash environment for NGZ root. (oxidecomputer#4712)
Browse files Browse the repository at this point in the history
This removes the special case for the switch zone and deploys a
consistent profile and bashrc to all non-global zones.

While understanding this is subjective, improvements here are:
* A switch zone prompt includes the local switch number (0/1) if it can
be determined;
* PATH is configured to include additional directories useful within the
zone;
* The hostname part of the prompt is truncated in zones which have UUIDs
as part of their name;
 * Coloured prompt, as per the GZ.

Pretty much everyone has their own preferred prompt format, so consensus
is unlikely here, but this is a step forward in having consistency and a
better PATH. In the limit, nobody will be logging into these zones
outside of a development environment anyway.
  • Loading branch information
citrus-it authored Dec 18, 2023
1 parent d5fb85e commit 1032885
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
14 changes: 13 additions & 1 deletion package-manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ service_name = "overlay"
source.type = "composite"
source.packages = [
"logadm.tar.gz",
"profile.tar.gz",
]
output.type = "zone"

Expand All @@ -83,6 +84,18 @@ source.paths = [
]
output.type = "zone"
output.intermediate_only = true
#
# The profile package is an overlay for all non-global zones to configure
# root's bash environment.
[package.profile]
service_name = "profile"
source.type = "local"
source.paths = [
{ from = "smf/profile/profile", to = "/root/.profile" },
{ from = "smf/profile/bashrc", to = "/root/.bashrc" },
]
output.type = "zone"
output.intermediate_only = true

[package.omicron-nexus]
service_name = "nexus"
Expand Down Expand Up @@ -335,7 +348,6 @@ source.paths = [
{ from = "smf/switch_zone_setup/manifest.xml", to = "/var/svc/manifest/site/switch_zone_setup/manifest.xml" },
{ from = "smf/switch_zone_setup/switch_zone_setup", to = "/opt/oxide/bin/switch_zone_setup" },
{ from = "smf/switch_zone_setup/support_authorized_keys", to = "/opt/oxide/support/authorized_keys" },
{ from = "smf/switch_zone_setup/root.profile", to = "/root/.profile" },
]
output.type = "zone"
output.intermediate_only = true
Expand Down
42 changes: 42 additions & 0 deletions smf/profile/bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

C_RED='\[\033[01;31m\]'
C_GREEN='\[\033[01;32m\]'
C_CYAN='\[\033[01;36m\]'
C_BLD='\[\033[1m\]'
C_NUL='\[\033[00m\]'

typeset _hst="$HOSTNAME"
typeset _hstc="$C_RED$HOSTNAME"
case "$_hst" in
oxz_switch)
# Try to determine which switch zone we are
_switchid=$(curl -s http://localhost:12225/local/switch-id \
| /opt/ooce/bin/jq -r .slot)
if (( $? == 0 )) && [[ -n "$_switchid" ]]; then
_hst+="$_switchid"
_hstc+="$C_CYAN$_switchid"
fi
;;
oxz_*-*)
# Shorten the hostname by truncating the UUID so that the prompt
# doesn't take up an excessive amount of width
_hst="${HOSTNAME%%-*}"
_hstc="$C_RED${HOSTNAME%%-*}"
;;
esac

if [[ -n $SSH_CLIENT ]]; then
echo -ne "\033]0;${_hst} \007"
export PROMPT_COMMAND='history -a'
fi

case "$TERM" in
xterm*|rxvt*|screen*|sun-color)
PS1="$C_GREEN\\u$C_NUL@$_hstc$C_NUL:$C_RED\\w$C_NUL$C_BLD\\\$$C_NUL "
;;
*)
PS1="\\u@$_hst:\\w\\$ "
esac

export PS1

24 changes: 24 additions & 0 deletions smf/profile/profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

PATH+=:/opt/ooce/bin

case "$HOSTNAME" in
oxz_switch)
# Add tools like xcvradm, swadm & ddmadm to the PATH by default
PATH+=:/opt/oxide/bin:/opt/oxide/dendrite/bin:/opt/oxide/mg-ddm/bin
;;
oxz_cockroachdb*)
PATH+=:/opt/oxide/cockroachdb/bin
;;
oxz_crucible*)
PATH+=:/opt/oxide/crucible/bin
;;
oxz_clockhouse*)
PATH+=:/opt/oxide/clickhouse
;;
oxz_external_dns*|oxz_internal_dns*)
PATH+=:/opt/oxide/dns-server/bin
;;
esac

[ -f ~/.bashrc ] && . ~/.bashrc

3 changes: 0 additions & 3 deletions smf/switch_zone_setup/root.profile

This file was deleted.

0 comments on commit 1032885

Please sign in to comment.