commit 2e8d1fc0780393f150e9879c3cb3b3a3659439a7 Author: tree Date: Fri Oct 21 10:01:02 2022 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df30fcb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +.DS_Store +build diff --git a/README.md b/README.md new file mode 100644 index 0000000..e8eb87c --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# services + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v0.1.13. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..3e763ef Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..d41d1eb --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "gweicz-services", + "module": "index.ts", + "scripts": { + "build": "bun scripts/build.js" + }, + "type": "module", + "devDependencies": { + "bun-types": "^0.1.0" + }, + "dependencies": { + "js-yaml": "^4.1.0", + "jsonata": "^1.8.6" + } +} \ No newline at end of file diff --git a/scripts/build.js b/scripts/build.js new file mode 100755 index 0000000..e1547ee --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,46 @@ +const yaml = require('js-yaml') +const fs = require('fs') +const jsonata = require('jsonata') + +const outputFn = 'build/spec.json' + +const strategies = { + async default (conf, all) { + const req = await fetch(conf.url) + const resp = await req.json() + return jsonata(conf.query).evaluate(resp) + }, + async github (conf, all) { + const req = await fetch('https://api.github.com/repos/@@/releases/latest'.replace(/@@/, all.repo)) + const resp = await req.json() + return jsonata('$match(tag_name,/^v(.+)/)[0].groups[0]').evaluate(resp) + }, + async html (conf, all) { + const req = await fetch(conf.url) + const resp = await req.text() + return resp.match(conf.query)[1] + } +} + +async function getVersions (config, all) { + const local = await strategies[config.from.strategy ? config.from.strategy : 'default'](config.from, all) + const latest = await strategies[config.to.strategy ? config.to.strategy : 'default'](config.to, all) + return { local, latest } +} + +async function build () { + const spec = yaml.load(fs.readFileSync('./spec/services.yaml')) + + for (const item of spec.services) { + + item.url = item.host ? `https://${item.host}` : item.url + item.versions = await getVersions(item.version_conf, item) + delete item.version_conf + } + + fs.writeFileSync(outputFn, JSON.stringify(spec, null, 2)) + console.log(`saved: ${outputFn}`) + console.log('build done') +} + +build() diff --git a/spec/services.yaml b/spec/services.yaml new file mode 100644 index 0000000..9651867 --- /dev/null +++ b/spec/services.yaml @@ -0,0 +1,100 @@ +services: + - name: Gitea + host: git.gwei.cz + repo: go-gitea/gitea + monitor: 6 + version_conf: + from: + url: https://git.gwei.cz/api/v1/version + query: version + to: + strategy: github + + - name: Mastodon + host: social.gwei.cz + repo: mastodon/mastodon + monitor: 3 + version_conf: + from: + url: https://social.gwei.cz/nodeinfo/2.0 + query: software.version + to: + strategy: github + + - name: Synapse (Matrix) + repo: matrix-org/synapse + monitor: 1 + version_conf: + from: + url: https://gwei.cz/_synapse/admin/v1/server_version + query: server_version + to: + strategy: github + + - name: Cinny + repo: cinnyapp/cinny + monitor: 8 + version_conf: + from: + url: https://cinny.gwei.cz/version.json + query: $match(version,/^v(.+)/)[0].groups[0] + to: + strategy: github + + - name: Tor Relay (#1) (Exit) + monitor: 34 + version_conf: + from: + url: https://onionoo.torproject.org/details?lookup=F36E7C8746649077DA254397F721851ABBD4B528 + query: relays[0].version + to: + strategy: html + url: https://www.torproject.org/download/tor/ + query: "(\\d+\\.\\d+\\.\\d+\\.\\d+)<\/td>" + + - name: Tor Relay (#2) + monitor: 33 + version_conf: + from: + url: https://onionoo.torproject.org/details?lookup=6DD7CFE5DAE710940E8DF978A5495085FEBB1703 + query: relays[0].version + to: + strategy: html + url: https://www.torproject.org/download/tor/ + query: "(\\d+\\.\\d+\\.\\d+\\.\\d+)<\/td>" + + - name: Discourse (Gwei.cz) + host: forum.gwei.cz + repo: discourse/discourse + monitor: 2 + version_conf: + from: + strategy: html + url: https://forum.gwei.cz + query: 'content="Discourse ([^\s]+) -' + to: + strategy: github + + - name: Discourse (dCZK) + host: forum.dczk.cz + repo: discourse/discourse + monitor: 2 + version_conf: + from: + strategy: html + url: https://forum.dczk.cz + query: 'content="Discourse ([^\s]+) -' + to: + strategy: github + + - name: SFTPGo + host: sftpgo.gwei.cz + repo: drakkan/sftpgo + monitor: 37 + version_conf: + from: + strategy: html + url: https://sftpgo.gwei.cz/web/admin/login + query: 'WebAdmin - ([^<]+)<\/h1>' + to: + strategy: github \ No newline at end of file