fix build

This commit is contained in:
陈浩南 2024-05-04 15:38:56 +08:00
parent dbc1cd55d4
commit 2e7feea4bf
2 changed files with 11 additions and 7 deletions

View File

@ -13,6 +13,6 @@
else else
'' ''
wrapProgram $out/bin/hpcstat --set HPCSTAT_SHAREDIR $out/share/hpcstat \ wrapProgram $out/bin/hpcstat --set HPCSTAT_SHAREDIR $out/share/hpcstat \
--set HPCSTAT_DATADIR /var/lib/hpcstat --set HPCSTAT_DATADIR /var/lib/hpcstat --set HPCSTAT_SSH_BINDIR ${openssh}/bin
''; '';
} }

View File

@ -14,12 +14,12 @@ namespace hpcstat::ssh
{ {
std::optional<std::string> fingerprint() std::optional<std::string> fingerprint()
{ {
if (auto sharedir = env::env("HPCSTAT_SHAREDIR", true); !sharedir) if (auto sshbindir = env::env("HPCSTAT_SSH_BINDIR"); !sshbindir)
return std::nullopt; return std::nullopt;
else if else if
( (
auto output = auto output =
exec(std::filesystem::path(*sharedir) / "ssh-add", { "-l" }); exec(std::filesystem::path(*sshbindir) / "ssh-add", { "-l" });
!output !output
) )
{ std::cerr << "Failed to get ssh fingerprints\n"; return std::nullopt; } { std::cerr << "Failed to get ssh fingerprints\n"; return std::nullopt; }
@ -39,13 +39,15 @@ namespace hpcstat::ssh
} }
std::optional<std::string> sign(std::string message, std::string fingerprint) std::optional<std::string> sign(std::string message, std::string fingerprint)
{ {
if (auto sharedir = env::env("HPCSTAT_SHAREDIR", true); !sharedir) if (auto sshbindir = env::env("HPCSTAT_SSH_BINDIR"); !sshbindir)
return std::nullopt;
else if (auto sharedir = env::env("HPCSTAT_SHAREDIR", true); !sharedir)
return std::nullopt; return std::nullopt;
else if else if
( (
auto output = exec auto output = exec
( (
std::filesystem::path(*sharedir) / "ssh-keygen", std::filesystem::path(*sshbindir) / "ssh-keygen",
{ {
"-Y", "sign", "-q", "-Y", "sign", "-q",
"-f", fmt::format("{}/keys/{}", *sharedir, Keys[fingerprint].PubkeyFilename), "-f", fmt::format("{}/keys/{}", *sharedir, Keys[fingerprint].PubkeyFilename),
@ -60,7 +62,9 @@ namespace hpcstat::ssh
} }
bool verify(std::string message, std::string signature, std::string fingerprint) bool verify(std::string message, std::string signature, std::string fingerprint)
{ {
if (auto sharedir = env::env("HPCSTAT_SHAREDIR", true); !sharedir) if (auto sshbindir = env::env("HPCSTAT_SSH_BINDIR"); !sshbindir)
return false;
else if (auto sharedir = env::env("HPCSTAT_SHAREDIR", true); !sharedir)
return false; return false;
else else
{ {
@ -71,7 +75,7 @@ namespace hpcstat::ssh
std::ofstream(signaturefile) << signature; std::ofstream(signaturefile) << signature;
return exec return exec
( (
std::filesystem::path(*sharedir) / "ssh-keygen", std::filesystem::path(*sshbindir) / "ssh-keygen",
{ {
"-Y", "verify", "-Y", "verify",
"-f", fmt::format("{}/keys/{}", *sharedir, Keys[fingerprint].PubkeyFilename), "-f", fmt::format("{}/keys/{}", *sharedir, Keys[fingerprint].PubkeyFilename),