mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-09-11 14:35:30 +03:00
init: debian indexer
Add an indexer for debian packages based on debians popularity contest. options: - outputFile - maxPackages - exclusions - inclusions Co-authored-by: Ctem <c@ctem.me>
This commit is contained in:
parent
03f9323d2c
commit
dd833d1a2a
65
src/indexers/debian-popcon/default.nix
Normal file
65
src/indexers/debian-popcon/default.nix
Normal file
@ -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)"
|
||||
'';
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"outputFile": "index.json",
|
||||
"maxPackages": 200,
|
||||
"modifications": {
|
||||
"exclusions": ["apt"],
|
||||
"additions": ["htop"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user