yadm icon indicating copy to clipboard operation
yadm copied to clipboard

Set YADM_ env variables in boostrap

Open jankatins opened this issue 4 years ago • 4 comments

Is your feature request related to a problem? Please describe.

It would be nice to be able to run boostrap and rely on the YADM_* env variables (as in the template system) being set. I imagine I can work around that by using the template system for the boostrap file, but just exporting the env variables would be easier.

Describe the solution you'd like

diff --git a/yadm b/yadm
index 64640d4..7dd313a 100755
--- a/yadm
+++ b/yadm
@@ -693,6 +693,13 @@ function bootstrap() {

   # GIT_DIR should not be set for user's bootstrap code
   unset GIT_DIR
+  set_local_alt_values
+  export YADM_CLASS="$local_class"
+  export YADM_OS="$local_system"
+  export YADM_HOSTNAME="$local_host"
+  export YADM_USER="$local_user"
+  export YADM_DISTRO="$local_distro"
+

   echo "Executing $YADM_BOOTSTRAP"
   exec "$YADM_BOOTSTRAP"

Describe alternatives you've considered

  • Using the template system to set these variables up at the top of the boostrap file
  • recomputing them (duplication of code)

Additional context

I would like to use these to make OS/distro/hostname specific commands in the bootstrap file.

jankatins avatar Jan 03 '21 16:01 jankatins

This has worked for me:

export YADM_TEST=1
local nounset=${-//[^u]/}
[ -n "${nounset}" ] && set +o nounset
  # shellcheck disable=1090 source=~/bin/yadm
  source yadm
  process_global_args
  set_operating_system
  set_awk
  set_yadm_dirs
  configure_paths
  set_local_alt_values
[ -n "${nounset}" ] && set -o nounset
unset YADM_TEST

YADM_CLASS="$local_class"
YADM_OS="$local_system"
YADM_HOSTNAME="$local_host"
YADM_USER="$local_user"
YADM_DISTRO="$local_distro"
YADM_SOURCE="${BASH_SOURCE[0]}"
export YADM_CLASS YADM_OS YADM_HOSTNAME YADM_USER YADM_DISTRO YADM_SOURCE

This will introduce other variables into the namespace. If you are concerned about that you can wrap everything in an eval and then export just the variables you want to reference:

# shellcheck disable=2046
eval $(
  export YADM_TEST=1
  set +o nounset
  # shellcheck disable=1090 source=~/bin/yadm
  source yadm
  process_global_args
  set_operating_system
  set_awk
  set_yadm_dirs
  configure_paths
  set_local_alt_values
  # shellcheck disable=2154
  printf 'export YADM_CLASS="%s" YADM_OS="%s" YADM_HOSTNAME="%s" YADM_USER="%s" YADM_DISTRO="%s"' \
  "$local_class" "$local_system" "$local_host" "$local_user" "$local_distro"
)

rasa avatar Jan 04 '21 20:01 rasa

@jankatins I don't see any issues with making these available to bootstraps. I think this change will also expose similar data to hooks. Ideally, the data exposed to hooks and bootstrap should be handled in one bit of unified code.

TheLocehiliosan avatar Jan 04 '21 20:01 TheLocehiliosan

This issue has been labeled as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jan 02 '22 02:01 github-actions[bot]

This issue has been labeled as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Mar 04 '22 01:03 github-actions[bot]