mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-25 07:25:33 +03:00
Merge pull request #226 from ngi-nix/init/debian-indexer
init: debian indexer
This commit is contained in:
commit
80fc23bf53
61
src/indexers/debian-popcon/default.nix
Normal file
61
src/indexers/debian-popcon/default.nix
Normal 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)"
|
||||
'';
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"outputFile": "index.json",
|
||||
"maxPackages": 200,
|
||||
"modifications": {
|
||||
"exclusions": ["apt"],
|
||||
"additions": ["htop"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user