From dd833d1a2a52a01791dc8d28abcdcf09fb004069 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Thu, 4 Aug 2022 11:07:48 +0200 Subject: [PATCH 1/2] init: debian indexer Add an indexer for debian packages based on debians popularity contest. options: - outputFile - maxPackages - exclusions - inclusions Co-authored-by: Ctem --- src/indexers/debian-popcon/default.nix | 65 +++++++++++++++++++ .../indexers/debian-popcon/input.example.json | 8 +++ 2 files changed, 73 insertions(+) create mode 100644 src/indexers/debian-popcon/default.nix create mode 100644 src/specifications/indexers/debian-popcon/input.example.json diff --git a/src/indexers/debian-popcon/default.nix b/src/indexers/debian-popcon/default.nix new file mode 100644 index 00000000..ccab78f8 --- /dev/null +++ b/src/indexers/debian-popcon/default.nix @@ -0,0 +1,65 @@ +{...}: { + indexBin = { + utils, + coreutils, + curl, + gnused, + gawk, + jq, + ... + }: + utils.writePureShellScript + [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)" + ''; +} diff --git a/src/specifications/indexers/debian-popcon/input.example.json b/src/specifications/indexers/debian-popcon/input.example.json new file mode 100644 index 00000000..723c0cf3 --- /dev/null +++ b/src/specifications/indexers/debian-popcon/input.example.json @@ -0,0 +1,8 @@ +{ + "outputFile": "index.json", + "maxPackages": 200, + "modifications": { + "exclusions": ["apt"], + "additions": ["htop"] + } +} From 95ebbc827bf6ea7090857c22ea121aabba7d0381 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 23 Oct 2022 06:06:08 +0300 Subject: [PATCH 2/2] fix: make debian-popcon indexer fit new indexer modules --- src/indexers/debian-popcon/default.nix | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/indexers/debian-popcon/default.nix b/src/indexers/debian-popcon/default.nix index ccab78f8..fb5a7ee3 100644 --- a/src/indexers/debian-popcon/default.nix +++ b/src/indexers/debian-popcon/default.nix @@ -1,15 +1,11 @@ -{...}: { - indexBin = { - utils, - coreutils, - curl, - gnused, - gawk, - jq, - ... - }: +{ + pkgs, + utils, + ... +}: { + indexBin = utils.writePureShellScript - [coreutils curl jq gnused gawk] + (with pkgs; [coreutils curl jq gnused gawk]) '' cd $WORKDIR