1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-23 03:29:48 +01:00

populate: reference all packages using "pkgs"

This fixes pop.pass's dependency on the caller's PATH for finding
the pass executable, while at the same time keeping its argument
consistent with the naming in other pop.$x functions.
This commit is contained in:
Ingolf Wagner 2018-09-19 06:09:17 +02:00 committed by tv
parent 5ae2b7f369
commit b465376df8

View file

@ -1,7 +1,7 @@
with import ../../lib; with import ../../lib;
with shell; with shell;
{ coreutils, dash, findutils, git, jq, openssh, rsync, writeDash }: { coreutils, findutils, git, openssh, pass, rsync, writeDash }@pkgs:
let let
check = { force, target }: let check = { force, target }: let
@ -53,27 +53,27 @@ let
in /* sh */ '' in /* sh */ ''
umask 0077 umask 0077
tmp_dir=$(${coreutils}/bin/mktemp -dt populate-pass.XXXXXXXX) tmp_dir=$(${pkgs.coreutils}/bin/mktemp -dt populate-pass.XXXXXXXX)
trap cleanup EXIT trap cleanup EXIT
cleanup() { cleanup() {
rm -fR "$tmp_dir" rm -fR "$tmp_dir"
} }
${findutils}/bin/find ${quote passPrefix} -type f | ${pkgs.findutils}/bin/find ${quote passPrefix} -type f |
while read -r gpg_path; do while read -r gpg_path; do
rel_name=''${gpg_path#${quote passPrefix}} rel_name=''${gpg_path#${quote passPrefix}}
rel_name=''${rel_name%.gpg} rel_name=''${rel_name%.gpg}
pass_date=$( pass_date=$(
${git}/bin/git -C ${quote pass.dir} log -1 --format=%aI "$gpg_path" ${pkgs.git}/bin/git -C ${quote pass.dir} log -1 --format=%aI "$gpg_path"
) )
pass_name=${quote pass.name}/$rel_name pass_name=${quote pass.name}/$rel_name
tmp_path=$tmp_dir/$rel_name tmp_path=$tmp_dir/$rel_name
${coreutils}/bin/mkdir -p "$(${coreutils}/bin/dirname "$tmp_path")" ${pkgs.coreutils}/bin/mkdir -p "$(${pkgs.coreutils}/bin/dirname "$tmp_path")"
PASSWORD_STORE_DIR=${quote pass.dir} pass show "$pass_name" > "$tmp_path" PASSWORD_STORE_DIR=${quote pass.dir} ${pkgs.pass}/bin/pass show "$pass_name" > "$tmp_path"
${coreutils}/bin/touch -d "$pass_date" "$tmp_path" ${pkgs.coreutils}/bin/touch -d "$pass_date" "$tmp_path"
done done
${rsync' target /* sh */ "$tmp_dir"} ${rsync' target /* sh */ "$tmp_dir"}
@ -93,7 +93,7 @@ let
populate = target: name: source: let populate = target: name: source: let
source' = source.${source.type}; source' = source.${source.type};
target' = target // { path = "${target.path}/${name}"; }; target' = target // { path = "${target.path}/${name}"; };
in writeDash "populate.${target'.host}.${name}" '' in pkgs.writeDash "populate.${target'.host}.${name}" ''
set -efu set -efu
${pop.${source.type} target' source'} ${pop.${source.type} target' source'}
''; '';
@ -103,7 +103,7 @@ let
if test -d "$source_path"; then if test -d "$source_path"; then
source_path=$source_path/ source_path=$source_path/
fi fi
${rsync}/bin/rsync \ ${pkgs.rsync}/bin/rsync \
-e ${quote (ssh' target)} \ -e ${quote (ssh' target)} \
-vFrlptD \ -vFrlptD \
--delete-excluded \ --delete-excluded \
@ -124,7 +124,7 @@ let
''; '';
ssh' = target: concatMapStringsSep " " quote [ ssh' = target: concatMapStringsSep " " quote [
"${openssh}/bin/ssh" "${pkgs.openssh}/bin/ssh"
"-l" target.user "-l" target.user
"-o" "ControlPersist=no" "-o" "ControlPersist=no"
"-p" target.port "-p" target.port
@ -133,7 +133,7 @@ let
in in
{ force ? false, source, target }: writeDash "populate.${target.host}" '' { force ? false, source, target }: pkgs.writeDash "populate.${target.host}" ''
set -efu set -efu
${check { inherit force target; }} ${check { inherit force target; }}
set -x set -x