aboutsummaryrefslogtreecommitdiff
path: root/nixops/scripts/with_env
blob: a442ced2091ed8fe1c643f8fccd85cd930188c8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

if [ -z "$NIXOPS" ]; then
  echo "Please set NIXOPS to the nixops command"
  exit 1;
fi

if [ -z "$NIXOPS_CONFIG_PASS_SUBTREE_PATH" ]; then
  echo "Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path"
  exit 1;
fi

TEMP=$(mktemp -d /tmp/XXXXXX-nixops-files)
chmod go-rwx $TEMP

finish() {
  rm -rf "$TEMP"
  $NIXOPS set-args --unset privateFiles
}

trap finish EXIT

# pass cannot "just" list files in a directory without showing a tree :(
files=$(pass ls $NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/files | sed -e '1d' -e 's/^.* //')

for file in $files; do
  pass show "$NIXOPS_CONFIG_PASS_SUBTREE_PATH/Nixops/files/$file" > $TEMP/$file
done
$NIXOPS set-args --argstr privateFiles "$TEMP"

"$@"