Files
myos/lib/cmd/env-update.sh
Yann Autissier 55fae625d6 keep the dynamism of make in pure shell
Two mechanisms, matching what the make engine actually did:

Lazy defaults. A stack setting is a function myos_default_<VAR>, called only
when the variable has no value, and called again at every reference. That is
exactly a recursive ?=: an explicit value wins, and the default follows a
DOMAIN that a .env changes later. The prefix is what makes it safe; the first
version used a bare function named after the variable, and the test suite
caught it running /usr/bin/host for a stack group called host.

Templates. myos env-update fills a .env from the .env.dist files, expanding
${VAR} against the current values and running $(command), forward references
included.

Also fixed: the project .env now wins over /etc/conf.d/myos, which is what the
documentation claimed and the code did not.

share/make/shim.mk lets a project keep make as a front end: every myos command
becomes a target that shells out to bin/myos, and the project keeps its own
targets and its stack .mk files. It sits outside make/ because the legacy
engine globs every .mk in there.
2026-09-03 20:46:28 +02:00

27 lines
1009 B
Bash

#shellcheck shell=sh
# myos env-update fill the .env of the workdir from the .env.dist it finds
#
# Templates are read from the workdir and from every requested stack, so a
# stack can ship the variables it expects and their defaults.
myos_cmd_env_update() {
_target=${ENV_FILE:-$WORKDIR/.env}
_dists=$MYOS_ARGS
if [ -z "$_dists" ]; then
for _ref in $MYOS_STACKS; do
_d=$(myos_stack_resolve "$_ref" 2>/dev/null) || continue
for _c in "$_d/.env.dist" "$_d/$(myos_stack_name "$_ref").env.dist"; do
[ -f "$_c" ] && _dists="${_dists:+$_dists }$_c"
done
done
for _c in "$WORKDIR/.env.dist" "$WORKDIR/.env.example" "$WORKDIR/.env.sample"; do
[ -f "$_c" ] && _dists="${_dists:+$_dists }$_c"
done
fi
[ -n "$_dists" ] || { myos_warning "no .env.dist found for $MYOS_STACKS"; return 0; }
for _dist in $_dists; do
myos_info "env-update $_target from $_dist"
myos_env_update "$_target" "$_dist" "$WORKDIR/.env.$ENV"
done
printf '%s\n' "$_target"
}