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