Export alt values (YADM_*) when running hooks and bootstrap
Fixes #291.
This commit is contained in:
parent
650644cfb8
commit
87e5cb690d
4 changed files with 19 additions and 4 deletions
|
@ -22,6 +22,7 @@ def test_bootstrap(
|
||||||
paths.bootstrap.write(
|
paths.bootstrap.write(
|
||||||
'#!/bin/bash\n'
|
'#!/bin/bash\n'
|
||||||
f'echo {expect}\n'
|
f'echo {expect}\n'
|
||||||
|
f'[[ $(id -un) = $YADM_USER ]] && echo "user is set"\n'
|
||||||
f'exit {code}\n'
|
f'exit {code}\n'
|
||||||
)
|
)
|
||||||
paths.bootstrap.chmod(0o775)
|
paths.bootstrap.chmod(0o775)
|
||||||
|
@ -30,6 +31,7 @@ def test_bootstrap(
|
||||||
if exists and executable:
|
if exists and executable:
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
assert expect in run.out
|
assert expect in run.out
|
||||||
|
assert 'user is set' in run.out
|
||||||
else:
|
else:
|
||||||
assert expect in run.err
|
assert expect in run.err
|
||||||
assert run.out == ''
|
assert run.out == ''
|
||||||
|
|
|
@ -27,7 +27,7 @@ def test_set_alt_values(
|
||||||
YADM_TEST=1 source {yadm} &&
|
YADM_TEST=1 source {yadm} &&
|
||||||
set_operating_system &&
|
set_operating_system &&
|
||||||
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
|
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
|
||||||
set_alt_values
|
ALT_VALUES_SET=0 set_alt_values
|
||||||
echo "class='$YADM_CLASS'"
|
echo "class='$YADM_CLASS'"
|
||||||
echo "os='$YADM_OS'"
|
echo "os='$YADM_OS'"
|
||||||
echo "host='$YADM_HOSTNAME'"
|
echo "host='$YADM_HOSTNAME'"
|
||||||
|
@ -69,7 +69,7 @@ def test_distro(runner, yadm):
|
||||||
YADM_TEST=1 source {yadm}
|
YADM_TEST=1 source {yadm}
|
||||||
function config() {{ echo "$1"; }}
|
function config() {{ echo "$1"; }}
|
||||||
function query_distro() {{ echo "testdistro"; }}
|
function query_distro() {{ echo "testdistro"; }}
|
||||||
set_alt_values
|
ALT_VALUES_SET=0 set_alt_values
|
||||||
echo "distro='$YADM_DISTRO'"
|
echo "distro='$YADM_DISTRO'"
|
||||||
"""
|
"""
|
||||||
run = runner(command=['bash'], inp=script)
|
run = runner(command=['bash'], inp=script)
|
||||||
|
|
8
yadm
8
yadm
|
@ -63,6 +63,7 @@ ENCRYPT_INCLUDE_FILES="unparsed"
|
||||||
|
|
||||||
LEGACY_WARNING_ISSUED=0
|
LEGACY_WARNING_ISSUED=0
|
||||||
INVALID_ALT=()
|
INVALID_ALT=()
|
||||||
|
ALT_VALUES_SET="${YADM_TEST:-0}"
|
||||||
|
|
||||||
GPG_OPTS=()
|
GPG_OPTS=()
|
||||||
OPENSSL_OPTS=()
|
OPENSSL_OPTS=()
|
||||||
|
@ -596,6 +597,9 @@ function remove_stale_links() {
|
||||||
|
|
||||||
function set_alt_values() {
|
function set_alt_values() {
|
||||||
|
|
||||||
|
[[ $ALT_VALUES_SET = 1 ]] && return
|
||||||
|
ALT_VALUES_SET=1
|
||||||
|
|
||||||
export YADM_CLASS
|
export YADM_CLASS
|
||||||
export YADM_ARCH
|
export YADM_ARCH
|
||||||
export YADM_OS
|
export YADM_OS
|
||||||
|
@ -698,6 +702,8 @@ function bootstrap() {
|
||||||
# GIT_DIR should not be set for user's bootstrap code
|
# GIT_DIR should not be set for user's bootstrap code
|
||||||
unset GIT_DIR
|
unset GIT_DIR
|
||||||
|
|
||||||
|
set_alt_values
|
||||||
|
|
||||||
echo "Executing $YADM_BOOTSTRAP"
|
echo "Executing $YADM_BOOTSTRAP"
|
||||||
exec "$YADM_BOOTSTRAP"
|
exec "$YADM_BOOTSTRAP"
|
||||||
|
|
||||||
|
@ -1770,6 +1776,8 @@ function invoke_hook() {
|
||||||
export -f unix_path
|
export -f unix_path
|
||||||
export -f mixed_path
|
export -f mixed_path
|
||||||
|
|
||||||
|
set_alt_values
|
||||||
|
|
||||||
"$hook_command"
|
"$hook_command"
|
||||||
hook_status=$?
|
hook_status=$?
|
||||||
|
|
||||||
|
|
9
yadm.1
9
yadm.1
|
@ -112,7 +112,9 @@ to "false".
|
||||||
.B bootstrap
|
.B bootstrap
|
||||||
Execute
|
Execute
|
||||||
.I $HOME/.config/yadm/bootstrap
|
.I $HOME/.config/yadm/bootstrap
|
||||||
if it exists.
|
if it exists. The variables that are set when processing Jinja or ESH templates
|
||||||
|
(see the TEMPLATES section) are set in the environment (except for
|
||||||
|
.IR YADM_SOURCE ).
|
||||||
.TP
|
.TP
|
||||||
.BI clone " url
|
.BI clone " url
|
||||||
Clone a remote repository for tracking dotfiles.
|
Clone a remote repository for tracking dotfiles.
|
||||||
|
@ -876,7 +878,10 @@ will never be run. This allows one to "short-circuit" any operation using a
|
||||||
.I pre_
|
.I pre_
|
||||||
hook.
|
hook.
|
||||||
|
|
||||||
Hooks have the following environment variables available to them at runtime:
|
Hooks have the following variables, plus the variables set when processing
|
||||||
|
Jinja or ESH templates (see the TEMPLATES section), available to them as
|
||||||
|
environment variables at runtime (except for
|
||||||
|
.IR YADM_SOURCE ).
|
||||||
.TP
|
.TP
|
||||||
.B YADM_HOOK_COMMAND
|
.B YADM_HOOK_COMMAND
|
||||||
The command which triggered the hook
|
The command which triggered the hook
|
||||||
|
|
Loading…
Reference in a new issue