diff --git a/nix/oci/tanzu/root/etc/profile b/nix/oci/tanzu/root/etc/profile index c087f859..e0e1d74c 100644 --- a/nix/oci/tanzu/root/etc/profile +++ b/nix/oci/tanzu/root/etc/profile @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). diff --git a/nix/oci/tanzu/root/etc/profile.d/shopt.sh b/nix/oci/tanzu/root/etc/profile.d/shopt.sh index cc818a1b..76213259 100755 --- a/nix/oci/tanzu/root/etc/profile.d/shopt.sh +++ b/nix/oci/tanzu/root/etc/profile.d/shopt.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + ################################################## # Name: shopt # Description: Contains the bash shell options configurations diff --git a/nix/oci/tanzu/root/etc/profile.d/tanzu.sh b/nix/oci/tanzu/root/etc/profile.d/tanzu.sh index cf434b16..99f0c356 100755 --- a/nix/oci/tanzu/root/etc/profile.d/tanzu.sh +++ b/nix/oci/tanzu/root/etc/profile.d/tanzu.sh @@ -49,9 +49,9 @@ if [[ -f "${HOME}/.config/tanzu/config.yaml" ]]; then fi # Make sure that the interactive parts are not run in a a VSCode remote env. -if [[ "${ENVIRONMENT_VSCODE^^}" == "CONTAINER" ]]; then +if [[ ${ENVIRONMENT_VSCODE^^} == "CONTAINER" ]]; then - echo "$(date '+%Y/%m/%d %T'): INFO: VSCode container environment detected, skipping interactive parts." | tee -a "/tmp/environment.log" + echo "$(date '+%Y/%m/%d %T'): INFO: Devcontainer is running, skipping Tanzu init." | tee -a "/tmp/environment.log" else @@ -69,92 +69,92 @@ else case "$CHOICE" in - [Yy]*) + [Yy]*) - echo "INFO: Initialising Tanzu CLI..." + echo "INFO: Initialising Tanzu CLI..." - tanzu plugin clean || { - echo "ERROR: Failed to clean the Tanzu CLI plugins" - } + tanzu plugin clean || { + echo "ERROR: Failed to clean the Tanzu CLI plugins" + } - tanzu init || { - echo "ERROR: Failed to initialise the Tanzu CLI configuration" - } + tanzu init || { + echo "ERROR: Failed to initialise the Tanzu CLI configuration" + } - # There are 3 options for the Tanzu CLI OCI registry in preference order: - # 1. A custom registry is provided, use it. - # 2. A pull-through cache is provided, use it. - # 3. No pull-through or custom registry is provided, pull direct from internet. + # There are 3 options for the Tanzu CLI OCI registry in preference order: + # 1. A custom registry is provided, use it. + # 2. A pull-through cache is provided, use it. + # 3. No pull-through or custom registry is provided, pull direct from internet. - # If there is a custom registry, use it as priority. - if [[ ${TANZU_CUSTOM_REGISTRY:-EMPTY} != "EMPTY" ]]; then + # If there is a custom registry, use it as priority. + if [[ ${TANZU_CUSTOM_REGISTRY:-EMPTY} != "EMPTY" ]]; then - echo "INFO: Custom registry provided, using ${TANZU_CUSTOM_REGISTRY}" + echo "INFO: Custom registry provided, using ${TANZU_CUSTOM_REGISTRY}" - # Capture existing OCI URL - TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)" + # Capture existing OCI URL + TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)" - # Strip the VMware registry prefix. - TANZU_CLI_OCI_URL="${TANZU_CLI_OCI_URL#*projects.registry.vmware.com}" + # Strip the VMware registry prefix. + TANZU_CLI_OCI_URL="${TANZU_CLI_OCI_URL#*projects.registry.vmware.com}" - # Add the custom registry OCI URL and update the plugin cache. - TANZU_CLI_OCI_URL="${TANZU_CUSTOM_REGISTRY}${TANZU_CLI_OCI_URL}" + # Add the custom registry OCI URL and update the plugin cache. + TANZU_CLI_OCI_URL="${TANZU_CUSTOM_REGISTRY}${TANZU_CLI_OCI_URL}" - # Update the plugin source and test pulling the image. - tanzu plugin source update \ - default \ - --uri "${TANZU_CLI_OCI_URL}" || { - echo "ERROR: Failed to update plugin configuration to use the provided custom registry." - } + # Update the plugin source and test pulling the image. + tanzu plugin source update \ + default \ + --uri "${TANZU_CLI_OCI_URL}" || { + echo "ERROR: Failed to update plugin configuration to use the provided custom registry." + } - elif [[ ${TANZU_PULL_THROUGH_CACHE:-EMPTY} != "EMPTY" ]]; then + elif [[ ${TANZU_PULL_THROUGH_CACHE:-EMPTY} != "EMPTY" ]]; then - echo "INFO: Pull-through prefix provided, prefixing ${TANZU_PULL_THROUGH_CACHE}" + echo "INFO: Pull-through prefix provided, prefixing ${TANZU_PULL_THROUGH_CACHE}" - # Capture existing OCI URL - TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)" + # Capture existing OCI URL + TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)" - # Add the pull-through prefix - TANZU_CLI_OCI_URL="${TANZU_PULL_THROUGH_CACHE}/${TANZU_CLI_OCI_URL}" + # Add the pull-through prefix + TANZU_CLI_OCI_URL="${TANZU_PULL_THROUGH_CACHE}/${TANZU_CLI_OCI_URL}" - # Add the pull-through cache OCI URL and update the plugin cache. - tanzu plugin source update \ - default \ - --uri "${TANZU_CLI_OCI_URL}" || { - echo "ERROR: Failed to update plugin configuration to use the provided pull-through cache." - } + # Add the pull-through cache OCI URL and update the plugin cache. + tanzu plugin source update \ + default \ + --uri "${TANZU_CLI_OCI_URL}" || { + echo "ERROR: Failed to update plugin configuration to use the provided pull-through cache." + } - else + else - echo "INFO: No custom registry or pull-through cache provided, pulling direct from internet." + echo "INFO: No custom registry or pull-through cache provided, pulling direct from internet." - fi + fi - # Add the VMWare TKG group of plugins at the configured version to match the CLI. - tanzu plugin install \ - --group "vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}" || { - echo "ERROR: Failed to install the Tanzu plugin group vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}" - } + # Add the VMWare TKG group of plugins at the configured version to match the CLI. + tanzu plugin install \ + --group "vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}" || { + echo "ERROR: Failed to install the Tanzu plugin group vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}" + } - tanzu plugin sync || { - echo "ERROR: Failed to synchronise Tanzu CLI plugins" - } + tanzu plugin sync || { + echo "ERROR: Failed to synchronise Tanzu CLI plugins" + } - break + break - ;; + ;; - [Nn]*) + [Nn]*) - break + break - ;; + ;; - *) + *) - echo "Please answer yes or no." + echo "Please answer yes or no." - ;; + ;; esac diff --git a/nix/oci/tanzu/root/etc/skel/.bash_logout b/nix/oci/tanzu/root/etc/skel/.bash_logout index e3ddddd0..c6f796f1 100644 --- a/nix/oci/tanzu/root/etc/skel/.bash_logout +++ b/nix/oci/tanzu/root/etc/skel/.bash_logout @@ -5,3 +5,5 @@ if [ "$SHLVL" = 1 ]; then [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q fi + +echo "$(date '+%Y/%m/%d %T'): INFO: Logout of Devcontainer Environment: ${ENVIRONMENT_VSCODE}" >> "/tmp/environment.log" diff --git a/nix/oci/tanzu/root/etc/skel/.bashrc b/nix/oci/tanzu/root/etc/skel/.bashrc index 57e3aec3..84b38c5e 100644 --- a/nix/oci/tanzu/root/etc/skel/.bashrc +++ b/nix/oci/tanzu/root/etc/skel/.bashrc @@ -1,11 +1,16 @@ +#!/usr/bin/env bash + # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything case $- in - *i*) ;; - *) return ;; + +*i*) ;; + +*) return ;; + esac # don't put duplicate lines or lines starting with space in the history. @@ -40,7 +45,7 @@ fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in - xterm-color | *-256color) color_prompt=yes ;; +xterm-color | *-256color) color_prompt=yes ;; esac # uncomment for a colored prompt, if the terminal has the capability; turned @@ -68,31 +73,35 @@ unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in - xterm* | rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; - *) ;; +xterm* | rxvt*) + PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" + ;; +*) ;; esac # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + + if [[ -r ~/.dircolors ]]; then + eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" + fi + alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' + alias dir='dir --color=auto' + alias vdir='vdir --color=auto' + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' - #alias grep='grep --color=auto' - #alias fgrep='fgrep --color=auto' - #alias egrep='egrep --color=auto' -fi + #colored GCC warnings and errors + export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' -# colored GCC warnings and errors -#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' +fi # some more ls aliases -#alias ll='ls -l' -#alias la='ls -A' -#alias l='ls -CF' +alias ll='ls -l' +alias la='ls -A' +alias l='ls -CF' # Alias definitions. # You may want to put all your additions into a separate file like @@ -100,6 +109,7 @@ fi # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then + # shellcheck disable=SC1090 . ~/.bash_aliases fi @@ -108,14 +118,16 @@ fi # sources /etc/bash.bashrc). if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then + # shellcheck disable=SC1091 . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then + # shellcheck disable=SC1091 . /etc/bash_completion fi fi # Make sure that the interactive parts are not run in a a VSCode remote env. -if [[ "${ENVIRONMENT_VSCODE^^}" == "CONTAINER" ]]; then +if [[ ${ENVIRONMENT_VSCODE^^} == "CONTAINER" ]]; then echo "$(date '+%Y/%m/%d %T'): INFO: VSCode container environment detected, skipping interactive parts." | tee -a "/tmp/environment.log" @@ -124,6 +136,7 @@ else # Starship if [[ ${ENABLE_STARSHIP:-FALSE} == "TRUE" ]]; then echo "INFO: Launching Starship prompt..." + # shellcheck disable=SC1090 source <(/bin/starship init bash) else echo "INFO: Starship prompt is disabled." @@ -134,4 +147,4 @@ fi echo "INFO: Finished loading .bashrc" # When running in a VSCode environment, drop a log file for tracking -echo "$(date '+%Y/%m/%d %T'): INFO: VSCode Environment: ${ENVIRONMENT_VSCODE}" >> "/tmp/environment.log" +echo "$(date '+%Y/%m/%d %T'): INFO: Login to Devcontainer Environment: ${ENVIRONMENT_VSCODE}" >>"/tmp/environment.log" diff --git a/nix/oci/tanzu/root/etc/skel/.profile b/nix/oci/tanzu/root/etc/skel/.profile index 70f94f2e..919421c2 100644 --- a/nix/oci/tanzu/root/etc/skel/.profile +++ b/nix/oci/tanzu/root/etc/skel/.profile @@ -1,3 +1,5 @@ +#/usr/bin/env bash + # ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. diff --git a/nix/oci/tanzu/root/usr/local/bin/entrypoint.sh b/nix/oci/tanzu/root/usr/local/bin/entrypoint.sh index 2e1b2014..40c5b1c4 100755 --- a/nix/oci/tanzu/root/usr/local/bin/entrypoint.sh +++ b/nix/oci/tanzu/root/usr/local/bin/entrypoint.sh @@ -4,16 +4,19 @@ if [[ ${ENABLE_DEBUG:-FALSE} == "TRUE" ]]; then set -x fi -# Start a fresh shell session. -/usr/bin/env bash --login -i || true - # Make sure that the interactive parts are not run in a a VSCode remote env. -if [[ "${ENVIRONMENT_VSCODE^^}" == "CONTAINER" ]]; then +if [[ ${ENVIRONMENT_VSCODE^^} == "CONTAINER" ]]; then - echo "$(date '+%Y/%m/%d %T'): INFO: VSCode container environment detected, skipping interactive parts." | tee -a "/tmp/environment.log" + while true; do + echo "$(date '+%Y/%m/%d %T'): INFO: Devcontainer environment is running..." | tee -a "/tmp/environment.log" + sleep 300 + done else + # Start a fresh shell session. + /usr/bin/env bash --login -i || true + while true; do clear @@ -25,26 +28,26 @@ else case $CHOICE in - [Yy]*) + [Yy]*) - echo "Restarting shell..." - /usr/bin/env bash --login -i || true + echo "Restarting shell..." + /usr/bin/env bash --login -i || true - ;; + ;; - [Nn]*) + [Nn]*) - echo "Exiting..." - break + echo "Exiting..." + break - ;; + ;; - *) + *) - echo "Please answer yes or no." - sleep 1 + echo "Please answer yes or no." + sleep 1 - ;; + ;; esac