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

Set YADM_ env variables in boostrap #291

Open
jankatins opened this issue Jan 3, 2021 · 4 comments
Open

Set YADM_ env variables in boostrap #291

jankatins opened this issue Jan 3, 2021 · 4 comments

Comments

@jankatins
Copy link
Contributor

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.

@rasa
Copy link
Contributor

rasa commented Jan 4, 2021

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"
)

@TheLocehiliosan
Copy link
Owner

@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.

kgadek added a commit to kgadek/yadm-bin that referenced this issue Feb 21, 2021
kgadek added a commit to kgadek/yadm-bin that referenced this issue Aug 8, 2021
kgadek added a commit to kgadek/yadm-bin that referenced this issue Dec 2, 2021
@github-actions
Copy link

github-actions bot commented Jan 2, 2022

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
Copy link

github-actions bot commented Mar 4, 2022

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 github-actions bot added the stale label Mar 4, 2022
@TheLocehiliosan TheLocehiliosan added 1 and removed stale labels Mar 7, 2022
kgadek added a commit to kgadek/yadm-bin that referenced this issue Apr 17, 2022
kgadek added a commit to kgadek/yadm-bin that referenced this issue Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants