Merge pull request #226 from ngi-nix/init/debian-indexer

init: debian indexer
This commit is contained in:
DavHau 2022-10-24 20:00:45 +02:00 committed by GitHub
commit 80fc23bf53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,61 @@
{
pkgs,
utils,
...
}: {
indexBin =
utils.writePureShellScript
(with pkgs; [coreutils curl jq gnused gawk])
''
cd $WORKDIR
input=''${1:?"please provide an input as a JSON file"}
outFile=$(jq '.outputFile' -c -r $input)
maxPackages=$(jq '.maxPackages' -c -r $input)
exclusions=$(jq '.modifications.exclusions' -c -r $input)
additions=$(jq '.modifications.additions' -c -r $input)
tmpFile="$TMPDIR/tmp.json"
helpFile="$TMPDIR/help.json"
url="https://popcon.debian.org/by_vote"
curl -k "$url" > "$tmpFile"
# remove top comment line
sed -i '/^#/d' $tmpFile
head -n$maxPackages $tmpFile > $helpFile
mv $helpFile $tmpFile
awk '{print $2}' $tmpFile > $helpFile
# remove enclosing square brackets
additions=''${additions:1}
additions=''${additions::-1}
# remove double quotes from each package name
additions=$(echo $additions | sed 's/,/ /g')
for pkg in $additions;do
pkg="''${pkg%\"}"
pkg="''${pkg#\"}"
echo $pkg >> $helpFile
done
# remove enclosing square brackets
exclusions=''${exclusions:1}
exclusions=''${exclusions::-1}
# remove double quotes from each package name
exclusions=$(echo $exclusions | sed 's/,/ /g')
for pkg in $exclusions;do
pkg="''${pkg%\"}"
pkg="''${pkg#\"}"
sed -i -e "/$pkg/d" $helpFile
done
jq -R -s -c 'split("\n")' < $helpFile >$tmpFile
sed -i -e 's/,""//g' $tmpFile
sed -i -e 's/\["/\["debian:/g' $tmpFile
sed -i -e 's/,"/,"debian:/g' $tmpFile
mv "$tmpFile" "$(realpath $outFile)"
'';
}

View File

@ -0,0 +1,8 @@
{
"outputFile": "index.json",
"maxPackages": 200,
"modifications": {
"exclusions": ["apt"],
"additions": ["htop"]
}
}