scripts/install-nix-from-closure: only show progress if a terminal is used

While the progress dots during the copying of the store work fine on a
normal terminal, those look pretty off if the script is run inside a
provisioning script of e.g. `vagrant` or `packer` where `stderr` and
`stdout` are captured:

    default: .
    default: ..
    default: .
    default: .
    default: .

To work around this, the script checks with `-t 0` if it's
running on an actual terminal and doesn't show the progress if that's not
the case.
This commit is contained in:
Maximilian Bosch 2021-01-21 17:30:26 +01:00
parent 259100332f
commit d9367a2dd1
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E

View file

@ -166,9 +166,15 @@ fi
mkdir -p $dest/store mkdir -p $dest/store
printf "copying Nix to %s..." "${dest}/store" >&2 printf "copying Nix to %s..." "${dest}/store" >&2
# Insert a newline if no progress is shown.
if [ ! -t 0 ]; then
echo ""
fi
for i in $(cd "$self/store" >/dev/null && echo ./*); do for i in $(cd "$self/store" >/dev/null && echo ./*); do
printf "." >&2 if [ -t 0 ]; then
printf "." >&2
fi
i_tmp="$dest/store/$i.$$" i_tmp="$dest/store/$i.$$"
if [ -e "$i_tmp" ]; then if [ -e "$i_tmp" ]; then
rm -rf "$i_tmp" rm -rf "$i_tmp"