Browse Source

Alpine support

master
Milan Pässler 11 months ago
parent
commit
20c556f7b2
3 changed files with 82 additions and 1 deletions
  1. +80
    -0
      server/alpine.js
  2. +1
    -0
      server/index.js
  3. +1
    -1
      server/openwrt.js

+ 80
- 0
server/alpine.js View File

@@ -0,0 +1,80 @@
"use strict";

const { spawn } = require("child_process");
const fetch = require("node-fetch");
const HTTPError = require("./error");

const urls = [
"http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz",
"http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz",
"http://dl-cdn.alpinelinux.org/alpine/edge/releases/x86_64/APKINDEX.tar.gz",
"http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz",
];

let packages = {};

const stripVersion = (s) => s.split(/[<>]?=.*/)[0];

const getKey = (text, key) => {
let res = "";
text.split("\n").forEach(line => {
if (line.startsWith(key)) res += line.slice(2) + " ";
});
return res.slice(0, -1); // cut last space
};

const getPackageLists = async () => {
const newPackages = {};

for (let url of urls) {
console.log(`fetching ${url}`);
const packageList = await fetch(url)
.then(resp => {
const child = spawn("tar", ["-xOzf-", "APKINDEX"]);
resp.body.pipe(child.stdin);

return new Promise((fulfill, reject) => {
let res = "";
child.stdout.on('data', chunk => res+=String(chunk));
child.stdout.on('end', () => {
fulfill(res)
});
});
});
packageList.split("\n\n")
.forEach(pkg => {
const p = {
deps: getKey(pkg, "D").split(" ").map(dep => stripVersion(dep)),
name: getKey(pkg, "P") + getKey(pkg, "V"),
id: getKey(pkg, "P"),
size: getKey(pkg, "S"),
};
newPackages[getKey(pkg, "P")] = p;
for (let name of getKey(pkg, "p").split(" ")) {
newPackages[stripVersion(name)] = p;
}
});
}

packages = newPackages;
console.log("packages loaded");
}

setInterval(getPackageLists, 24 * 60 * 60 * 1000); // 24 hours
getPackageLists();

const getNode = async (parameters) => {
if (parameters.length < 2) {
throw new HTTPError(404, "Invalid URI");
}

const name = parameters[parameters.length-1];
if (!packages[name]) {
throw new HTTPError(404, "Failed to get package info");
}
return packages[name];
};

module.exports = getNode;

+ 1
- 0
server/index.js View File

@@ -13,6 +13,7 @@ const backends = {
NixOS: require("./nixpkgs"),
OpenWRT: require("./openwrt"),
ArchLinux: require("./archlinux"),
Alpine: require("./alpine"),
backends: listBackends
};



+ 1
- 1
server/openwrt.js View File

@@ -24,7 +24,7 @@ const getPackageLists = async () => {
const packageList = await fetch(url)
.then(res => res.text());

let packages = packageList.split("\n\n")
packageList.split("\n\n")
.forEach(pkg => {
let attrs = InternetMessage.parse(pkg + "\n")
if (attrs.package && attrs.depends) {


Loading…
Cancel
Save