pkgs/den-http-get-updater: use sed instead of awk

This commit is contained in:
Wroclaw 2025-04-07 21:06:21 +02:00
parent a361d01683
commit 890260024f

View file

@ -2,7 +2,7 @@
lib, lib,
curl, curl,
gawk, gnused,
jq, jq,
nix, nix,
writeScript, writeScript,
@ -50,25 +50,24 @@ let
rec { rec {
inherit fileLocation; inherit fileLocation;
mark = builtins.hashString "sha256" x.previousHash; mark = builtins.hashString "sha256" x.previousHash;
markShellEscape = lib.escapeShellArg mark; markRegexEscape = lib.escapeRegex mark;
markShellRegexEscape = lib.escapeShellArg (lib.escapeRegex mark);
realFileLocation = builtins.toString x.fileLocation or fileLocation; realFileLocation = builtins.toString x.fileLocation or fileLocation;
realFileLocationShellEscape = lib.escapeShellArg realFileLocation; realFileLocationShellEscape = lib.escapeShellArg realFileLocation;
prefetchUrlLocationShellEscape = lib.mapAttrs (_: lib.escapeShellArg) x.prefetchUrlLocation; prefetchUrlLocationShellEscape = lib.mapAttrs (_: lib.escapeShellArg) x.prefetchUrlLocation;
previousHashShellRegexEscape = lib.escapeShellArg (lib.escapeRegex x.previousHash); previousHashRegexEscape = lib.escapeRegex x.previousHash;
} // x) prefetchList; } // x) prefetchList;
realFileLocation' = lib.escapeShellArg realFileLocation; realFileLocationShellEscape = lib.escapeShellArg realFileLocation;
versionUrl' = lib.escapeShellArg versionUrl; versionUrlShellEscape = lib.escapeShellArg versionUrl;
previousVersion'' = lib.escapeShellArg (lib.escapeRegex previousVersion); previousVersionRegexEscape = lib.escapeRegex previousVersion;
nixUnpack = lib.optionalString unpack "--unpack"; nixUnpack = lib.optionalString unpack "--unpack";
nixName = lib.optionalString (!builtins.isNull name) "--name \"${lib.escapeShellArg name}\""; nixName = lib.optionalString (!builtins.isNull name) "--name \"${lib.escapeShellArg name}\"";
path = lib.makeBinPath ([ path = lib.makeBinPath ([
curl curl
gawk gnused
jq jq
nix nix
] ++ extraPackages); ] ++ extraPackages);
@ -78,29 +77,29 @@ writeScript "den-http-get-updater" (''
PATH="${lib.escapeShellArg path}" PATH="${lib.escapeShellArg path}"
prefetchFailed= prefetchFailed=
newVersion=$(curl -L "${versionUrl'}") newVersion=$(curl -L "${versionUrlShellEscape}")
if [[ "$?" != 0 ]]; then if [[ "$?" != 0 ]]; then
echo "error: fetching new version failed" 1>&2 echo "error: fetching new version failed" 1>&2
exit 1 exit 1
fi fi
newVersion=$(${contentParser}) newVersion=$(${contentParser})
awk -i inplace "{ sub(/${previousVersion''}/, \"$newVersion\") }1" "${realFileLocation'}" sed -Ei "s!${previousVersionRegexEscape}!$newVersion!g" "${realFileLocationShellEscape}"
'' ''
# invalidate hashes # invalidate hashes
+ lib.concatStringsSep "\n" (lib.map ({ + lib.concatStringsSep "\n" (lib.map ({
markShellEscape, mark,
previousHash, previousHash,
previousHashShellRegexEscape, previousHashRegexEscape,
realFileLocationShellEscape, realFileLocationShellEscape,
... ...
}: '' }: ''
awk -i inplace "{ sub(/${previousHashShellRegexEscape}/, \"${markShellEscape}\") }1" "${realFileLocationShellEscape}" sed -Ei "s!${previousHashRegexEscape}!${mark}!g" "${realFileLocationShellEscape}"
'') prefetchList') '') prefetchList')
+ lib.concatStringsSep "\n" (lib.map ({ + lib.concatStringsSep "\n" (lib.map ({
fileLocation, fileLocation,
markShellRegexEscape, markRegexEscape,
prefetchUrlLocationShellEscape, prefetchUrlLocationShellEscape,
realFileLocationShellEscape, realFileLocationShellEscape,
... ...
@ -128,9 +127,7 @@ writeScript "den-http-get-updater" (''
if [[ -n $expectedHash ]]; then if [[ -n $expectedHash ]]; then
echo "prefetch succeeded!" echo "prefetch succeeded!"
echo "hash: $expectedHash" echo "hash: $expectedHash"
awk -i inplace "{ sed -Ei "s!${markRegexEscape}!$expectedHash!g" "${realFileLocationShellEscape}"
sub(/${markShellRegexEscape}/, \"$expectedHash\")
}1" "${realFileLocationShellEscape}"
prefetchSucceeded= prefetchSucceeded=
break break
fi fi