Compare commits
33 Commits
v3.0.0
...
1db899b5c8
Author | SHA1 | Date | |
---|---|---|---|
1db899b5c8 | |||
fc71bc08db | |||
![]() |
c560100a8b | ||
3c34a98e67 | |||
cb28872652 | |||
a8c057245a | |||
d328414186 | |||
5b44841cbf | |||
d07f02f4a2 | |||
fb44cf636f | |||
768b69ce08 | |||
0a63914127 | |||
568e9d186e | |||
fb4b291c81 | |||
56c38bdefd | |||
228c462782 | |||
ad14eff70b | |||
25e7b4b211 | |||
65663c02dd | |||
c4935a0129 | |||
1030873894 | |||
8ca4e2105d | |||
f3b63d5cbd | |||
1f54eae84d | |||
ee29453824 | |||
9ffcd0b5ee | |||
7410c7ca0c | |||
6db2c2d683 | |||
a9191e84a0 | |||
4a4e3d9614 | |||
66f45cae07 | |||
91186f29ff | |||
e148e79195 |
@@ -1,3 +1,4 @@
|
|||||||
volume/
|
volume/
|
||||||
config/
|
config/
|
||||||
|
distribution/
|
||||||
node_modules
|
node_modules
|
90
.github/workflows/build-app-image.yml
vendored
Normal file
90
.github/workflows/build-app-image.yml
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
name: App Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_app_image:
|
||||||
|
name: Build app image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GH_REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
REPOSITORY: ${{ github.event.repository.name }}
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
install: true
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.GH_REGISTRY }}
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata for release Docker image
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
|
- name: Extract metadata for develop Docker image
|
||||||
|
if: "!startsWith(github.ref, 'refs/tags/v')"
|
||||||
|
id: meta-develop
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.GH_REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=pr
|
||||||
|
|
||||||
|
- name: Build and push release Docker image
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
target: deploy
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
platforms: linux/amd64
|
||||||
|
cache-from: type=gha,scope=${{ github.workflow }}
|
||||||
|
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
|
||||||
|
|
||||||
|
- name: Build and push develop Docker image
|
||||||
|
if: "!startsWith(github.ref, 'refs/tags/v')"
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
target: deploy
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta-develop.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta-develop.outputs.labels }}
|
||||||
|
platforms: linux/amd64
|
||||||
|
cache-from: type=gha,scope=${{ github.workflow }}
|
||||||
|
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -109,3 +109,4 @@ assets/css/
|
|||||||
assets/js/
|
assets/js/
|
||||||
assets/webp/
|
assets/webp/
|
||||||
config/
|
config/
|
||||||
|
distribution/
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
image: docker:latest
|
|
||||||
services:
|
|
||||||
- docker:dind
|
|
||||||
|
|
||||||
variables:
|
|
||||||
DOCKER_DRIVER: overlay
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- build
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
artix-packy-pusher:
|
|
||||||
stage: build
|
|
||||||
script:
|
|
||||||
- docker build --pull --no-cache -t "$CI_REGISTRY_IMAGE" .
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
stage: deploy
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
script:
|
|
||||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
||||||
- docker push "$CI_REGISTRY_IMAGE"
|
|
29
Dockerfile
29
Dockerfile
@@ -1,8 +1,12 @@
|
|||||||
FROM artixlinux/artixlinux:devel as build-env
|
FROM artixlinux/artixlinux:base-devel AS baseimg
|
||||||
|
|
||||||
|
RUN pacman -Syu --noconfirm
|
||||||
|
|
||||||
|
FROM baseimg AS build-env
|
||||||
|
|
||||||
WORKDIR /usr/notifier
|
WORKDIR /usr/notifier
|
||||||
|
|
||||||
RUN pacman -Sy --noconfirm nodejs npm
|
RUN pacman -Sy --noconfirm nodejs npm typescript
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
@@ -10,16 +14,17 @@ RUN npm install
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN npm run-script build && \
|
RUN tsc && \
|
||||||
|
npm run-script build && \
|
||||||
npm ci --only=production
|
npm ci --only=production
|
||||||
|
|
||||||
|
|
||||||
FROM artixlinux/artixlinux:devel as deploy
|
FROM baseimg AS deploy
|
||||||
|
|
||||||
VOLUME /usr/notifier/config
|
VOLUME /usr/notifier/config
|
||||||
WORKDIR /usr/notifier
|
WORKDIR /usr/notifier
|
||||||
HEALTHCHECK --timeout=3s \
|
HEALTHCHECK --timeout=15m \
|
||||||
CMD curl --fail http://localhost:8080/healthcheck || exit 1
|
CMD curl --fail http://localhost:8081/healthcheck || exit 1
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
@@ -29,16 +34,18 @@ RUN pacman -Sy --noconfirm curl artools-pkg artix-checkupdates git nodejs npm op
|
|||||||
|
|
||||||
COPY --from=build-env /usr/notifier /usr/notifier
|
COPY --from=build-env /usr/notifier /usr/notifier
|
||||||
|
|
||||||
RUN mkdir -p ./config /home/artix/.config/artix-checkupdates /home/artix/.config/artools && \
|
RUN mkdir -p ./config /home/artix/.config/artix-checkupdates \
|
||||||
|
/home/artix/.config/artools /home/artix/.cache/artix-checkupdates && \
|
||||||
|
ln -sf /usr/notifier/config/artools-pkg.conf /home/artix/.config/artools/artools-pkg.conf && \
|
||||||
|
ln -sf /usr/notifier/config/artix-checkupdates.conf /home/artix/.config/artix-checkupdates/config && \
|
||||||
chown -R artix:artix /home/artix/ && \
|
chown -R artix:artix /home/artix/ && \
|
||||||
chown -R artix:artix .
|
chown -R artix:artix .
|
||||||
|
|
||||||
USER artix
|
USER artix
|
||||||
|
|
||||||
ENV ARTIX_MIRROR="https://mirrors.qontinuum.space/artixlinux/%s/os/x86_64"
|
ENV ARTIX_MIRROR="https://mirror.sanin.dev/artix-linux/%s/os/x86_64/"
|
||||||
ENV ARCH_MIRROR="https://mirrors.qontinuum.space/archlinux/%s/os/x86_64"
|
ENV ARCH_MIRROR="https://mirror.sanin.dev/arch-linux/%s/os/x86_64/"
|
||||||
ENV ARTIX_REPOS="system-goblins,world-goblins,galaxy-goblins,lib32-goblins,system-gremlins,world-gremlins,galaxy-gremlins,lib32-gremlins,system,world,galaxy,lib32"
|
ENV ARTIX_REPOS="system-goblins,world-goblins,galaxy-goblins,lib32-goblins,system-gremlins,world-gremlins,galaxy-gremlins,lib32-gremlins,system,world,galaxy,lib32"
|
||||||
ENV ARCH_REPOS="core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib"
|
ENV ARCH_REPOS="core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib"
|
||||||
ENV GITEA_TOKEN="CHANGEME"
|
|
||||||
|
|
||||||
CMD ./startup.sh
|
CMD [ "node", "distribution/index.mjs"]
|
||||||
|
68
README.md
68
README.md
@@ -1,25 +1,59 @@
|
|||||||
# artix-packy-notifier
|
# artix-checkupdates-web
|
||||||
|
|
||||||
Notify me when one of my packages needs maintaining
|
Notification system and web frontend for Artix packages with pending operations. Notifications can be sent via
|
||||||
|
[Apprise](https://github.com/caronc/apprise/wiki#notification-services) or IRC. Web interface shows all packages with pending operations
|
||||||
|
and publishes prometheus metrics.
|
||||||
|
|
||||||
mount a folder to `/usr/volume`.
|
## configuration
|
||||||
|
|
||||||
Inside the volume, create a `packages.json` with the following schema:
|
create `config/config.json`:
|
||||||
|
|
||||||
| Variable | Description |
|
| Variable | Description |
|
||||||
|-----------------|-----------------------------------------------------------------------------------------------------------------------|
|
|-----------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||||
| PREVIOUS | The path to store the generated list of actionable packages. Defaults to `previous.json` in the mounted volume. |
|
| apprise | The URL of the Apprise instance for sending notifications |
|
||||||
| packages | An array of packages to look for pending operations for. |
|
| maintainers | Array of maintainer names as strings or objects containing the `name` of the maintainer and a list of `channels` to send notifications to |
|
||||||
| writeAllPending | Boolean. If all pending packages should be included in the PREVIOUS file. Provided as `allPackages` and `allMovable`. |
|
| cron | The cron schedule for when the application should check for pending operations via [artix-checkupdates](https://gitea.artixlinux.org/artix/artix-checkupdates) |
|
||||||
| apprise.api | The url of the Apprise server to use for sending notifications. For example, "http://192.168.1.123:8000" |
|
| syncfreq | How often (in days) should the application sync package ownership from Gitea |
|
||||||
| apprise.urls | An array of Apprise destination URLs to deliver notifications to. For example, "tgram://bot-token/chat-id" |
|
| port | What port to run the webserver on (defaults to 8080) |
|
||||||
|
| savePath | Location of auxiliary save data (defaults to `config/data.db`) |
|
||||||
|
| db | Location of the SQLite DB (defaults to `config/packages.db`) |
|
||||||
|
| irc-framework | The options to feed into [irc-framework](https://github.com/kiwiirc/irc-framework/blob/master/docs/clientapi.md) |
|
||||||
|
| ircClient | Auxilary config data for the IRC bot. For now, it takes `ircClient.channel` and optionally `ircClient.channel_key` |
|
||||||
|
|
||||||
The following environment variables should be supplied.
|
Note that the IRC bot needs to be exempt from excess flooding. The following command permanently voices a bot on Libera.chat:
|
||||||
|
```
|
||||||
|
/msg ChanServ FLAGS #example artix-update-bot +V
|
||||||
|
```
|
||||||
|
If the channel is intended only for the bot to broadcast, consider setting the channel mode to "moderated":
|
||||||
|
```
|
||||||
|
/mode +m #example
|
||||||
|
```
|
||||||
|
|
||||||
| Variable | Description |
|
## How to run
|
||||||
|--------------|--------------------------------------------|
|
|
||||||
| CRON | The cron schedule for checking for updates |
|
```
|
||||||
| ARTIX_MIRROR | The Artix mirror to use |
|
npm install
|
||||||
| ARCH_MIRROR | The Arch mirror to use |
|
npm exec tsc
|
||||||
| ARTIX_REPOS | The Artix repos to check |
|
node distribution/index.mjs
|
||||||
| ARCH_REPOS | The Arch repos to check |
|
```
|
||||||
|
|
||||||
|
## Docker Setup
|
||||||
|
|
||||||
|
Image : `ghcr.io/corysanin/artix-checkupdates-web:latest`
|
||||||
|
|
||||||
|
mount a folder to `/usr/notifier/config`.
|
||||||
|
|
||||||
|
Include a `config.json` as described above.
|
||||||
|
|
||||||
|
Include `artools-pkg.conf`:
|
||||||
|
```
|
||||||
|
GIT_TOKEN='YOUR-GITEA-TOKEN-HERE'
|
||||||
|
```
|
||||||
|
|
||||||
|
Include `artix-checkupdates.conf`:
|
||||||
|
```
|
||||||
|
ARTIX_MIRROR=https://example.com/%s/os/x86_64
|
||||||
|
ARCH_MIRROR=https://example.com/%s/os/x86_64
|
||||||
|
ARTIX_REPOS=system-goblins,world-goblins,galaxy-goblins,lib32-goblins,system-gremlins,world-gremlins,galaxy-gremlins,lib32-gremlins,system,world,galaxy,lib32
|
||||||
|
ARCH_REPOS=core-staging,extra-staging,multilib-staging,core-testing,extra-testing,multilib-testing,core,extra,multilib
|
||||||
|
```
|
@@ -16,7 +16,7 @@
|
|||||||
<linearGradient xlink:href="#b" id="d" x1="105.834" x2="80.209" y1="15.354" y2="30.531" gradientTransform="translate(-56.383 115.378)" gradientUnits="userSpaceOnUse"/>
|
<linearGradient xlink:href="#b" id="d" x1="105.834" x2="80.209" y1="15.354" y2="30.531" gradientTransform="translate(-56.383 115.378)" gradientUnits="userSpaceOnUse"/>
|
||||||
<linearGradient xlink:href="#a" id="c" x1="75.543" x2="81.2" y1="145.986" y2="143.227" gradientTransform="translate(-16.572 -7.109)" gradientUnits="userSpaceOnUse"/>
|
<linearGradient xlink:href="#a" id="c" x1="75.543" x2="81.2" y1="145.986" y2="143.227" gradientTransform="translate(-16.572 -7.109)" gradientUnits="userSpaceOnUse"/>
|
||||||
</defs>
|
</defs>
|
||||||
<path fill="#10a0cc" stroke-width=".1" d="m23.362 0-8.034 16.474 22.112 12.39zM12.901 21.45.574 46.726l36.578-15.111zm26.955 12.368L28.32 40.441l17.832 6.284z"/>
|
<path class="artix-logo-base" fill="#10a0cc" stroke-width=".1" d="m23.362 0-8.034 16.474 22.112 12.39zM12.901 21.45.574 46.726l36.578-15.111zm26.955 12.368L28.32 40.441l17.832 6.284z"/>
|
||||||
<path fill="url(#c)" stroke-width=".265" d="m58.971 138.877 4.138-5.876 6.295 12.908z" transform="translate(-23.253 -99.183)"/>
|
<path fill="url(#c)" stroke-width=".265" d="m58.971 138.877 4.138-5.876 6.295 12.908z" transform="translate(-23.253 -99.183)"/>
|
||||||
<path fill="url(#d)" stroke-width=".265" d="m23.826 145.909 25.626-15.177 10.952.065z" transform="translate(-23.253 -99.183)"/>
|
<path fill="url(#d)" stroke-width=".265" d="m23.826 145.909 25.626-15.177 10.952.065z" transform="translate(-23.253 -99.183)"/>
|
||||||
<path fill="url(#e)" stroke-width=".265" d="m60.693 128.047-22.112-12.39 5.744-2.213z" transform="translate(-23.253 -99.183)"/>
|
<path fill="url(#e)" stroke-width=".265" d="m60.693 128.047-22.112-12.39 5.744-2.213z" transform="translate(-23.253 -99.183)"/>
|
||||||
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
@@ -1,31 +1,29 @@
|
|||||||
/**
|
import fs from 'fs';
|
||||||
* Writing this myself because gulp has a billion garbage dependencies
|
import path from 'path';
|
||||||
* and webpack sucks poop through a straw. Everyone is stupid.
|
import child_process from 'child_process';
|
||||||
*/
|
import uglifyjs from "uglify-js";
|
||||||
const fsp = require('fs').promises;
|
import * as sass from 'sass';
|
||||||
const path = require('path');
|
import * as csso from 'csso';
|
||||||
const spawn = require('child_process').spawn;
|
|
||||||
const sass = require('sass');
|
|
||||||
const csso = require('csso');
|
|
||||||
const uglifyjs = require("uglify-js");
|
|
||||||
|
|
||||||
|
const spawn = child_process.spawn;
|
||||||
|
const fsp = fs.promises;
|
||||||
const STYLESDIR = 'styles';
|
const STYLESDIR = 'styles';
|
||||||
const SCRIPTSDIR = 'scripts';
|
const SCRIPTSDIR = 'scripts';
|
||||||
const IMAGESDIR = path.join('assets', 'images');
|
const IMAGESDIR = path.join('assets', 'images');
|
||||||
const STYLEOUTDIR = process.env.STYLEOUTDIR || path.join(__dirname, 'assets', 'css');
|
const STYLEOUTDIR = process.env.STYLEOUTDIR || path.join('assets', 'css');
|
||||||
const SCRIPTSOUTDIR = process.env.SCRIPTSOUTDIR || path.join(__dirname, 'assets', 'js');
|
const SCRIPTSOUTDIR = process.env.SCRIPTSOUTDIR || path.join('assets', 'js');
|
||||||
const IMAGESOUTDIR = process.env.IMAGESOUTDIR || path.join(__dirname, 'assets', 'webp');
|
const IMAGESOUTDIR = process.env.IMAGESOUTDIR || path.join('assets', 'webp');
|
||||||
const STYLEOUTFILE = process.env.STYLEOUTFILE || 'styles.css';
|
const STYLEOUTFILE = process.env.STYLEOUTFILE || 'styles.css';
|
||||||
const SQUASH = new RegExp('^[0-9]+-');
|
const SQUASH = new RegExp('^[0-9]+-');
|
||||||
|
|
||||||
async function emptyDir(dir) {
|
async function emptyDir(dir: string) {
|
||||||
await Promise.all((await fsp.readdir(dir, { withFileTypes: true })).map(f => path.join(dir, f.name)).map(p => fsp.rm(p, {
|
await Promise.all((await fsp.readdir(dir, { withFileTypes: true })).map(f => path.join(dir, f.name)).map(p => fsp.rm(p, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
force: true
|
force: true
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mkdir(dir) {
|
async function mkdir(dir: string | string[]) {
|
||||||
if (typeof dir === 'string') {
|
if (typeof dir === 'string') {
|
||||||
await fsp.mkdir(dir, { recursive: true });
|
await fsp.mkdir(dir, { recursive: true });
|
||||||
}
|
}
|
||||||
@@ -37,8 +35,8 @@ async function mkdir(dir) {
|
|||||||
// Process styles
|
// Process styles
|
||||||
async function styles() {
|
async function styles() {
|
||||||
await mkdir([STYLEOUTDIR, STYLESDIR]);
|
await mkdir([STYLEOUTDIR, STYLESDIR]);
|
||||||
await await emptyDir(STYLEOUTDIR);
|
await emptyDir(STYLEOUTDIR);
|
||||||
let styles = [];
|
let styles: string[] = [];
|
||||||
let files = await fsp.readdir(STYLESDIR);
|
let files = await fsp.readdir(STYLESDIR);
|
||||||
await Promise.all(files.map(f => new Promise(async (res, reject) => {
|
await Promise.all(files.map(f => new Promise(async (res, reject) => {
|
||||||
let p = path.join(STYLESDIR, f);
|
let p = path.join(STYLESDIR, f);
|
||||||
@@ -110,7 +108,7 @@ async function images(dir = '') {
|
|||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
console.log(`Wrote ${outfile}`);
|
console.log(`Wrote ${outfile}`);
|
||||||
res();
|
res(null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
reject(code);
|
reject(code);
|
||||||
@@ -124,6 +122,10 @@ async function images(dir = '') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAbortError(err: unknown): boolean {
|
||||||
|
return typeof err === 'object' && err !== null && 'name' in err && err.name === 'AbortError';
|
||||||
|
}
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
await Promise.all([styles(), scripts(), images()]);
|
await Promise.all([styles(), scripts(), images()]);
|
||||||
if (process.argv.indexOf('--watch') >= 0) {
|
if (process.argv.indexOf('--watch') >= 0) {
|
||||||
@@ -134,7 +136,7 @@ async function images(dir = '') {
|
|||||||
for await (const _ of watcher)
|
for await (const _ of watcher)
|
||||||
await styles();
|
await styles();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name === 'AbortError')
|
if (isAbortError(err))
|
||||||
return;
|
return;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -146,7 +148,7 @@ async function images(dir = '') {
|
|||||||
for await (const _ of watcher)
|
for await (const _ of watcher)
|
||||||
await scripts();
|
await scripts();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name === 'AbortError')
|
if (isAbortError(err))
|
||||||
return;
|
return;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -160,7 +162,7 @@ async function images(dir = '') {
|
|||||||
for await (const _ of watcher)
|
for await (const _ of watcher)
|
||||||
await images();
|
await images();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name === 'AbortError')
|
if (isAbortError(err))
|
||||||
return;
|
return;
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
@@ -1,7 +1,31 @@
|
|||||||
version: '2'
|
version: '2'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
packy:
|
artix-notifier-daemon:
|
||||||
|
container_name: artix-notifier-daemon
|
||||||
|
build:
|
||||||
|
context: ./
|
||||||
|
volumes:
|
||||||
|
- ./config:/usr/notifier/config
|
||||||
|
depends_on:
|
||||||
|
- artix-notifier-irc
|
||||||
|
- artix-notifier-web
|
||||||
|
environment:
|
||||||
|
COMPONENT: "daemon"
|
||||||
|
ARTIX_REPOS: "system-goblins,world-goblins,system-gremlins,world-gremlins,system,world"
|
||||||
|
ARCH_REPOS: "core-staging,extra-staging,core-testing,extra-testing,core,extra"
|
||||||
|
|
||||||
|
artix-notifier-irc:
|
||||||
|
container_name: artix-notifier-irc
|
||||||
|
build:
|
||||||
|
context: ./
|
||||||
|
volumes:
|
||||||
|
- ./config:/usr/notifier/config
|
||||||
|
environment:
|
||||||
|
COMPONENT: "ircbot"
|
||||||
|
|
||||||
|
artix-notifier-web:
|
||||||
|
container_name: artix-notifier-web
|
||||||
build:
|
build:
|
||||||
context: ./
|
context: ./
|
||||||
volumes:
|
volumes:
|
||||||
@@ -9,7 +33,4 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 8080:8080
|
||||||
environment:
|
environment:
|
||||||
ARTIX_MIRROR: "https://mirrors.qontinuum.space/artixlinux/%s/os/x86_64"
|
COMPONENT: "web"
|
||||||
ARCH_MIRROR: "https://mirrors.qontinuum.space/archlinux/%s/os/x86_64"
|
|
||||||
ARTIX_REPOS: "system-goblins,world-goblins,system-gremlins,world-gremlins,system,world"
|
|
||||||
ARCH_REPOS: "core-staging,extra-staging,core-testing,extra-testing,core,extra"
|
|
||||||
|
215
index.js
215
index.js
@@ -1,215 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
const fs = require('fs');
|
|
||||||
const spawn = require('child_process').spawn;
|
|
||||||
const cron = require('node-cron');
|
|
||||||
const dayjs = require('dayjs');
|
|
||||||
const json5 = require('json5');
|
|
||||||
const phin = require('phin');
|
|
||||||
const DB = require('./db');
|
|
||||||
const Web = require('./web');
|
|
||||||
const fsp = fs.promises;
|
|
||||||
|
|
||||||
const TIMEOUT = 180000;
|
|
||||||
const EXTRASPACE = new RegExp('\\s+', 'g');
|
|
||||||
const NICETYPES = {
|
|
||||||
move: 'move',
|
|
||||||
udate: 'update'
|
|
||||||
}
|
|
||||||
|
|
||||||
let saveData = {
|
|
||||||
'last-sync': null,
|
|
||||||
move: [],
|
|
||||||
update: []
|
|
||||||
}
|
|
||||||
|
|
||||||
let cronjob;
|
|
||||||
|
|
||||||
let savePath = process.env.SAVEPATH || path.join(__dirname, 'config', 'data.json');
|
|
||||||
|
|
||||||
fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.json'), async (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const config = json5.parse(data);
|
|
||||||
savePath = config.savePath || savePath;
|
|
||||||
const db = new DB(process.env.DBPATH || config.db || path.join(__dirname, 'config', 'packages.db'));
|
|
||||||
|
|
||||||
try {
|
|
||||||
saveData = JSON.parse(await fsp.readFile(savePath));
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
console.error(`Failed to read existing save data at ${savePath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// resetting flags in case of improper shutdown
|
|
||||||
db.restoreFlags();
|
|
||||||
|
|
||||||
cronjob = cron.schedule(process.env.CRON || config.cron || '*/30 * * * *', () => {
|
|
||||||
main(config, db);
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on('SIGTERM', (new Web(db, config, saveData)).close);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function main(config, db) {
|
|
||||||
console.log('Starting scheduled task');
|
|
||||||
cronjob.stop();
|
|
||||||
let now = dayjs();
|
|
||||||
if (!('last-sync' in saveData) || !saveData['last-sync'] || dayjs(saveData['last-sync']).isBefore(now.subtract(3, 'days'))) {
|
|
||||||
await updateMaintainers(config, db);
|
|
||||||
saveData['last-sync'] = now.toJSON();
|
|
||||||
await writeSaveData();
|
|
||||||
}
|
|
||||||
await checkupdates(config, db);
|
|
||||||
await writeSaveData();
|
|
||||||
cronjob.start();
|
|
||||||
console.log('Task complete.');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function writeSaveData() {
|
|
||||||
try {
|
|
||||||
await fsp.writeFile(savePath, JSON.stringify(saveData));
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
console.error(`Failed to write save data to ${savePath}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function checkupdates(config, db) {
|
|
||||||
await handleUpdates(config, db, saveData.move = await execCheckUpdates(['-m']), 'move');
|
|
||||||
await handleUpdates(config, db, saveData.update = await execCheckUpdates(['-u']), 'udate');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleUpdates(config, db, packs, type) {
|
|
||||||
packs.forEach(v => {
|
|
||||||
let p = db.getPackage(v);
|
|
||||||
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let i = 0; i < config.maintainers.length; i++) {
|
|
||||||
let m = config.maintainers[i];
|
|
||||||
if (typeof m === 'object') {
|
|
||||||
notify({
|
|
||||||
api: config.apprise,
|
|
||||||
urls: m.channels
|
|
||||||
}, db.getNewByMaintainer(m.name, type), NICETYPES[type])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
db.decrementFlags(type);
|
|
||||||
db.restoreFlags(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateMaintainers(config, db) {
|
|
||||||
console.log('Syncing packages...');
|
|
||||||
const lastseen = (new Date()).getTime();
|
|
||||||
const maintainers = config.maintainers;
|
|
||||||
for (let i = 0; maintainers && i < maintainers.length; i++) {
|
|
||||||
let maintainer = maintainers[i];
|
|
||||||
if (typeof maintainer === 'object') {
|
|
||||||
maintainer = maintainer.name;
|
|
||||||
}
|
|
||||||
console.log(`Syncing ${maintainer}...`);
|
|
||||||
try {
|
|
||||||
(await getMaintainersPackages(maintainer)).forEach(package => db.updatePackage(package, maintainer, lastseen));
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(`Failed to get packages for ${maintainer}`);
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(`removing unused packages...`);
|
|
||||||
db.cleanOldPackages(lastseen);
|
|
||||||
console.log(`Package sync complete`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMaintainersPackages(maintainer) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let process = spawn('artixpkg', ['admin', 'query', '-m', maintainer]);
|
|
||||||
let timeout = setTimeout(() => {
|
|
||||||
reject('Timed out');
|
|
||||||
process.kill();
|
|
||||||
}, TIMEOUT);
|
|
||||||
let packagelist = [];
|
|
||||||
process.stdout.on('data', data => {
|
|
||||||
packagelist = packagelist.concat(data.toString().trim().split('\n'));
|
|
||||||
});
|
|
||||||
process.stderr.on('data', err => {
|
|
||||||
console.error(err.toString());
|
|
||||||
})
|
|
||||||
process.on('exit', async (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve(packagelist);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reject(code);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function notify(apprise, packarr, type) {
|
|
||||||
if (!(packarr && packarr.length)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < 25; i++) {
|
|
||||||
try {
|
|
||||||
return await phin({
|
|
||||||
url: `${apprise.api}/notify/`,
|
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
title: `${packarr[0].maintainer}: packages ready to ${type}`,
|
|
||||||
body: packarr.map(p => p.package).join('\n'),
|
|
||||||
urls: apprise.urls.join(',')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (ex) {
|
|
||||||
console.error('Failed to send notification, attempt #%d', i + 1);
|
|
||||||
console.error(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCheckUpdatesOutput(output) {
|
|
||||||
let packages = [];
|
|
||||||
let lines = output.split('\n');
|
|
||||||
lines.forEach(l => {
|
|
||||||
let package = l.trim().replace(EXTRASPACE, ' ');
|
|
||||||
if (package.length > 0 && package.indexOf('Package basename') < 0) {
|
|
||||||
packages.push(package.split(' ', 2)[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return packages;
|
|
||||||
}
|
|
||||||
|
|
||||||
function execCheckUpdates(flags) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let process = spawn('artix-checkupdates', flags);
|
|
||||||
let timeout = setTimeout(() => {
|
|
||||||
reject('Timed out');
|
|
||||||
process.kill();
|
|
||||||
}, TIMEOUT);
|
|
||||||
let outputstr = '';
|
|
||||||
process.stdout.on('data', data => {
|
|
||||||
outputstr += data.toString();
|
|
||||||
});
|
|
||||||
process.stderr.on('data', err => {
|
|
||||||
console.error(err.toString());
|
|
||||||
})
|
|
||||||
process.on('exit', async (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve(parseCheckUpdatesOutput(outputstr));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
reject(code);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
2793
package-lock.json
generated
2793
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
50
package.json
50
package.json
@@ -1,40 +1,56 @@
|
|||||||
{
|
{
|
||||||
"name": "artix-packy-notifier",
|
"name": "artix-checkupdates-web",
|
||||||
"version": "3.0.0",
|
"version": "4.1.2",
|
||||||
"description": "Determine packages that need attention",
|
"description": "Determine packages that need attention",
|
||||||
"main": "index.js",
|
"main": "./distribution/index.js",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build.js",
|
"build": "npx build-shit",
|
||||||
"watch": "node build.js --watch"
|
"watch": "npx build-shit --watch"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/sanin.dev/artix-packy-notifier.git"
|
"url": "git+ssh://git@github.com:CorySanin/artix-checkupdates-web.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"artix",
|
"artix",
|
||||||
"linux",
|
"linux",
|
||||||
"packages"
|
"packages"
|
||||||
],
|
],
|
||||||
|
"files": [
|
||||||
|
"distribution",
|
||||||
|
"assets",
|
||||||
|
"views",
|
||||||
|
"userbar"
|
||||||
|
],
|
||||||
"author": "Cory Sanin",
|
"author": "Cory Sanin",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/sanin.dev/artix-packy-notifier/issues"
|
"url": "https://github.com/CorySanin/artix-checkupdates-web/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/sanin.dev/artix-packy-notifier#readme",
|
"homepage": "https://github.com/CorySanin/artix-checkupdates-web#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "9.4.0",
|
"artix-checkupdates": "1.0.2",
|
||||||
"dayjs": "1.11.10",
|
"better-sqlite3": "11.9.1",
|
||||||
"ejs": "3.1.9",
|
"dayjs": "1.11.13",
|
||||||
"express": "4.18.2",
|
"ejs": "3.1.10",
|
||||||
|
"express": "4.21.2",
|
||||||
|
"express-useragent": "1.0.15",
|
||||||
|
"irc-framework": "4.14.0",
|
||||||
"json5": "2.2.3",
|
"json5": "2.2.3",
|
||||||
|
"ky": "1.8.1",
|
||||||
"node-cron": "3.0.3",
|
"node-cron": "3.0.3",
|
||||||
"phin": "^3.7.0",
|
"prom-client": "15.1.3",
|
||||||
"prom-client": "15.1.0"
|
"sharp": "0.34.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"csso": "5.0.5",
|
"@sindresorhus/tsconfig": "7.0.0",
|
||||||
"sass": "1.66.1",
|
"@types/better-sqlite3": "^7.6.12",
|
||||||
"uglify-js": "3.17.4"
|
"@types/express": "^5.0.0",
|
||||||
|
"@types/express-useragent": "1.0.5",
|
||||||
|
"@types/node": "22.10.7",
|
||||||
|
"@types/node-cron": "3.0.11",
|
||||||
|
"forking-build-shit": "0.0.2",
|
||||||
|
"typescript": "5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
src/config.d.ts
vendored
Normal file
35
src/config.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { } from "node:os";
|
||||||
|
|
||||||
|
export type IRCFrameworkConfig = {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
nick: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuxiliaryIRCConfig = {
|
||||||
|
channel?: string;
|
||||||
|
channel_key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Maintainer = {
|
||||||
|
name: string;
|
||||||
|
channels?: string[];
|
||||||
|
ircName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type MaintainerArrayElement = (string | Maintainer);
|
||||||
|
|
||||||
|
export type Config = {
|
||||||
|
webhostname: string;
|
||||||
|
apprise: string;
|
||||||
|
maintainers: MaintainerArrayElement[];
|
||||||
|
cron?: string;
|
||||||
|
syncfreq: number;
|
||||||
|
db?: string;
|
||||||
|
port?: number;
|
||||||
|
privateport?: number;
|
||||||
|
savePath?: string;
|
||||||
|
irchostname?: string;
|
||||||
|
'irc-framework'?: IRCFrameworkConfig;
|
||||||
|
ircClient?: AuxiliaryIRCConfig;
|
||||||
|
}
|
268
src/daemon.mts
Normal file
268
src/daemon.mts
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
import { Checkupdates } from 'artix-checkupdates';
|
||||||
|
import { DB } from './db.mjs';
|
||||||
|
import { spawn } from 'child_process';
|
||||||
|
import ky from 'ky';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fsp from 'node:fs/promises';
|
||||||
|
import * as cron from 'node-cron';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import express from 'express';
|
||||||
|
import type http from "http";
|
||||||
|
import type { Express } from "express";
|
||||||
|
import type { Config, MaintainerArrayElement } from './config.js';
|
||||||
|
import type { Category, PackageDBEntry } from './db.mjs';
|
||||||
|
|
||||||
|
const TIMEOUT = 180000;
|
||||||
|
const ORPHAN = {
|
||||||
|
"name": "orphan",
|
||||||
|
"ircName": "orphaned"
|
||||||
|
};
|
||||||
|
const NICETYPES = {
|
||||||
|
move: 'move',
|
||||||
|
udate: 'update'
|
||||||
|
};
|
||||||
|
|
||||||
|
type SaveData = {
|
||||||
|
'last-sync': string | null;
|
||||||
|
move: string[];
|
||||||
|
update: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppriseConf = {
|
||||||
|
api: string;
|
||||||
|
urls: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function notStupidParseInt(v: string | undefined): number {
|
||||||
|
return v === undefined ? NaN : parseInt(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Daemon {
|
||||||
|
private _config: Config;
|
||||||
|
private _savePath: string;
|
||||||
|
private _locked: boolean;
|
||||||
|
private _saveData: SaveData;
|
||||||
|
private _db: DB;
|
||||||
|
private _cronjob: cron.ScheduledTask;
|
||||||
|
private _webserver: http.Server;
|
||||||
|
|
||||||
|
constructor(config: Config) {
|
||||||
|
const PROJECT_ROOT = path.resolve(import.meta.dirname, '..');
|
||||||
|
const app: Express = express();
|
||||||
|
const port = process.env['PRIVATEPORT'] || config.privateport || 8081;
|
||||||
|
this._config = config;
|
||||||
|
this._savePath = process.env['SAVEPATH'] || config.savePath || path.join(PROJECT_ROOT, 'config', 'data.json');
|
||||||
|
console.log('Written by Cory Sanin for Artix Linux');
|
||||||
|
this._locked = false;
|
||||||
|
const db = this._db = new DB(process.env['DBPATH'] || config.db || path.join(PROJECT_ROOT, 'config', 'packages.db'));
|
||||||
|
this._saveData = {
|
||||||
|
'last-sync': null,
|
||||||
|
move: [],
|
||||||
|
update: []
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set('trust proxy', 1);
|
||||||
|
|
||||||
|
app.get('/healthcheck', (_, res) => {
|
||||||
|
res.send('Healthy');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.readSaveData();
|
||||||
|
|
||||||
|
// resetting flags in case of improper shutdown
|
||||||
|
db.restoreFlags();
|
||||||
|
|
||||||
|
this._cronjob = cron.schedule(process.env['CRON'] || config.cron || '*/30 * * * *', () => {
|
||||||
|
this.main(this._config);
|
||||||
|
});
|
||||||
|
|
||||||
|
this._webserver = app.listen(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
main = async (config: Config) => {
|
||||||
|
if (this._locked) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this._locked = true;
|
||||||
|
console.log('Starting scheduled task');
|
||||||
|
let now = dayjs();
|
||||||
|
if (!('last-sync' in this._saveData) || !this._saveData['last-sync'] || dayjs(this._saveData['last-sync']).isBefore(now.subtract(notStupidParseInt(process.env['SYNCFREQ']) || config.syncfreq || 2, 'days'))) {
|
||||||
|
await this.updateMaintainers(config);
|
||||||
|
this._saveData['last-sync'] = now.toJSON();
|
||||||
|
await this.writeSaveData();
|
||||||
|
}
|
||||||
|
await this.checkupdates(config);
|
||||||
|
await this.writeSaveData();
|
||||||
|
this._locked = false;
|
||||||
|
console.log('Task complete.');
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMaintainers = async (config: Config) => {
|
||||||
|
const db = this._db;
|
||||||
|
console.log('Syncing packages...');
|
||||||
|
const lastseen = (new Date()).getTime();
|
||||||
|
const maintainers = [...(config.maintainers || []), ORPHAN];
|
||||||
|
for (let i = 0; i < maintainers.length; i++) {
|
||||||
|
let maintainer = maintainers[i] as MaintainerArrayElement;
|
||||||
|
if (typeof maintainer === 'object') {
|
||||||
|
maintainer = maintainer.name;
|
||||||
|
}
|
||||||
|
console.log(`Syncing ${maintainer}...`);
|
||||||
|
try {
|
||||||
|
const packages: string[] = await this.getMaintainersPackages(maintainer);
|
||||||
|
for (let j = 0; j < packages.length; j++) {
|
||||||
|
db.updatePackage(packages[j] as string, maintainer, lastseen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(`Failed to get packages for ${maintainer}`);
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`removing unused packages...`);
|
||||||
|
db.cleanOldPackages(lastseen);
|
||||||
|
console.log(`Package sync complete`);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkupdates = async (config: Config) => {
|
||||||
|
const check = new Checkupdates();
|
||||||
|
try {
|
||||||
|
await this.handleUpdates(config, this._saveData.move = (await check.fetchMovable()).map(p => p.basename), 'move');
|
||||||
|
await this.handleUpdates(config, this._saveData.update = (await check.fetchUpgradable()).map(p => p.basename), 'udate');
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error('Failed to check for updates:', ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getMaintainersPackages = (maintainer: string): Promise<string[]> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let process = spawn('artixpkg', ['admin', 'query', maintainer === ORPHAN.name ? '-t' : '-m', maintainer]);
|
||||||
|
let timeout = setTimeout(() => {
|
||||||
|
reject('Timed out');
|
||||||
|
process.kill();
|
||||||
|
}, TIMEOUT);
|
||||||
|
let packagelist: string[] = [];
|
||||||
|
process.stdout.on('data', data => {
|
||||||
|
packagelist = packagelist.concat(data.toString().trim().split('\n'));
|
||||||
|
});
|
||||||
|
process.stderr.on('data', err => {
|
||||||
|
console.error(err.toString());
|
||||||
|
})
|
||||||
|
process.on('exit', async (code) => {
|
||||||
|
if (code === 0) {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
resolve(packagelist);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reject(code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdates = async (config: Config, packs: string[], type: Category) => {
|
||||||
|
const db = this._db;
|
||||||
|
packs.forEach(v => {
|
||||||
|
let p = db.getPackage(v);
|
||||||
|
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
|
||||||
|
});
|
||||||
|
const maintainers: MaintainerArrayElement[] = [...config.maintainers, ORPHAN];
|
||||||
|
for (let i = 0; i < maintainers.length; i++) {
|
||||||
|
const m = maintainers[i] as MaintainerArrayElement;
|
||||||
|
const mname: string = typeof m === 'object' ? m.name : m;
|
||||||
|
const ircName = typeof m === 'object' ? (m.ircName || mname) : m;
|
||||||
|
const packages = db.getNewByMaintainer(mname, type);
|
||||||
|
if (typeof m === 'object' && m.channels) {
|
||||||
|
this.notify({
|
||||||
|
api: config.apprise,
|
||||||
|
urls: m.channels
|
||||||
|
}, packages, NICETYPES[type]);
|
||||||
|
}
|
||||||
|
this.ircNotify(packages, ircName, NICETYPES[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.decrementFlags(type);
|
||||||
|
db.restoreFlags(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
notify = async (apprise: AppriseConf, packarr: PackageDBEntry[], type: string) => {
|
||||||
|
if (!(packarr && packarr.length && apprise && apprise.api && apprise.urls)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const packagesStr = packarr.map(p => p.package).join('\n');
|
||||||
|
for (let i = 0; i < 25; i++) {
|
||||||
|
try {
|
||||||
|
return await ky.post(`${apprise.api}/notify/`, {
|
||||||
|
json: {
|
||||||
|
title: `${packarr[0]?.maintainer}: packages ready to ${type}`,
|
||||||
|
body: packagesStr,
|
||||||
|
urls: apprise.urls.join(',')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error('Failed to send notification, attempt #%d', i + 1);
|
||||||
|
console.error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ircNotify = async (packarr: PackageDBEntry[], maintainer: string, type: string) => {
|
||||||
|
const config = this._config;
|
||||||
|
if (!(packarr && packarr.length && config['irc-framework'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const hostname = process.env['IRCHOSTNAME'] || config.irchostname || 'http://artix-notifier-irc:8081';
|
||||||
|
const packagesStr = packarr.map(p => p.package).join('\n');
|
||||||
|
for (let i = 0; i < 25; i++) {
|
||||||
|
try {
|
||||||
|
return await ky.post(`${hostname}/api/1.0/notifications`, {
|
||||||
|
json: {
|
||||||
|
message: `${maintainer}: packages ready to ${type}\n${packagesStr}\n-------- EOF --------`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error('Failed to send IRC notification, attempt #%d', i + 1);
|
||||||
|
console.error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
readSaveData = async () => {
|
||||||
|
try {
|
||||||
|
this._saveData = JSON.parse((await fsp.readFile(this._savePath)).toString());
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
console.error(`Failed to read existing save data at ${this._savePath}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeSaveData = async () => {
|
||||||
|
const config = this._config;
|
||||||
|
const hostname = process.env['WEBHOSTNAME'] || config.webhostname || 'http://artix-notifier-web:8081';
|
||||||
|
try {
|
||||||
|
await fsp.writeFile(this._savePath, JSON.stringify(this._saveData));
|
||||||
|
ky.put(`${hostname}/api/1.0/data`);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
console.error(`Failed to write save data to ${this._savePath}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close = () => {
|
||||||
|
if (this._webserver) {
|
||||||
|
this._webserver.close();
|
||||||
|
}
|
||||||
|
if (this._cronjob) {
|
||||||
|
this._cronjob.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Daemon;
|
||||||
|
export { Daemon };
|
||||||
|
export type { SaveData };
|
@@ -1,10 +1,52 @@
|
|||||||
const sqlite = require('better-sqlite3');
|
import Database from 'better-sqlite3';
|
||||||
|
|
||||||
const TABLE = 'packages';
|
const TABLE = 'packages';
|
||||||
|
|
||||||
|
type Category = 'move' | 'udate';
|
||||||
|
|
||||||
|
interface CommonOperations {
|
||||||
|
GET: Database.Statement;
|
||||||
|
GETNEWBYMAINTAINER: Database.Statement;
|
||||||
|
UPDATE: Database.Statement;
|
||||||
|
INCREMENT: Database.Statement;
|
||||||
|
DECREMENT: Database.Statement;
|
||||||
|
FIXFLAG: Database.Statement;
|
||||||
|
GETPACKAGESBYMAINTAINER: Database.Statement;
|
||||||
|
GETPACKAGECOUNTBYMAINTAINER: Database.Statement;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DatabaseOperations {
|
||||||
|
GETPACKAGE: Database.Statement;
|
||||||
|
ADDPACKAGE: Database.Statement;
|
||||||
|
GETPACKAGES: Database.Statement;
|
||||||
|
GETPACKAGESSTARTWITH: Database.Statement;
|
||||||
|
UPDATEMAINTAINER: Database.Statement;
|
||||||
|
GETMAINTAINERPACKAGECOUNT: Database.Statement;
|
||||||
|
REMOVEOLDPACKAGE: Database.Statement;
|
||||||
|
move: CommonOperations;
|
||||||
|
udate: CommonOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PackageDBEntry {
|
||||||
|
package: string;
|
||||||
|
maintainer: string;
|
||||||
|
move: number;
|
||||||
|
udate: number;
|
||||||
|
lastseen: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CountResult {
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
class DB {
|
class DB {
|
||||||
constructor(file) {
|
private _db: Database.Database;
|
||||||
this._db = new sqlite(file);
|
private _queries: DatabaseOperations;
|
||||||
|
|
||||||
|
constructor(file: string | Buffer) {
|
||||||
|
this._db = new Database(file);
|
||||||
const db = this._db;
|
const db = this._db;
|
||||||
|
db.pragma('journal_mode = WAL');
|
||||||
|
|
||||||
if (!db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='${TABLE}';`).get()) {
|
if (!db.prepare(`SELECT name FROM sqlite_master WHERE type='table' AND name='${TABLE}';`).get()) {
|
||||||
db.prepare(`CREATE TABLE ${TABLE} (package VARCHAR(128) PRIMARY KEY, maintainer VARCHAR(128), move INTEGER, udate INTEGER, lastseen DATETIME);`).run();
|
db.prepare(`CREATE TABLE ${TABLE} (package VARCHAR(128) PRIMARY KEY, maintainer VARCHAR(128), move INTEGER, udate INTEGER, lastseen DATETIME);`).run();
|
||||||
@@ -13,6 +55,8 @@ class DB {
|
|||||||
this._queries = {
|
this._queries = {
|
||||||
GETPACKAGE: db.prepare(`SELECT * FROM ${TABLE} WHERE package = @package;`),
|
GETPACKAGE: db.prepare(`SELECT * FROM ${TABLE} WHERE package = @package;`),
|
||||||
ADDPACKAGE: db.prepare(`INSERT INTO ${TABLE} (package,maintainer,move,udate,lastseen) VALUES (@package, @maintainer, 0, 0, @lastseen);`),
|
ADDPACKAGE: db.prepare(`INSERT INTO ${TABLE} (package,maintainer,move,udate,lastseen) VALUES (@package, @maintainer, 0, 0, @lastseen);`),
|
||||||
|
GETPACKAGES: db.prepare(`SELECT package FROM ${TABLE}`),
|
||||||
|
GETPACKAGESSTARTWITH: db.prepare(`SELECT package FROM ${TABLE} WHERE package LIKE @startsWith || '%'`),
|
||||||
UPDATEMAINTAINER: db.prepare(`UPDATE ${TABLE} SET maintainer = @maintainer, lastseen= @lastseen WHERE package = @package`),
|
UPDATEMAINTAINER: db.prepare(`UPDATE ${TABLE} SET maintainer = @maintainer, lastseen= @lastseen WHERE package = @package`),
|
||||||
GETMAINTAINERPACKAGECOUNT: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer;`),
|
GETMAINTAINERPACKAGECOUNT: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer;`),
|
||||||
REMOVEOLDPACKAGE: db.prepare(`DELETE FROM ${TABLE} WHERE lastseen < @lastseen;`),
|
REMOVEOLDPACKAGE: db.prepare(`DELETE FROM ${TABLE} WHERE lastseen < @lastseen;`),
|
||||||
@@ -23,7 +67,7 @@ class DB {
|
|||||||
INCREMENT: db.prepare(`UPDATE ${TABLE} SET move = move + 1 WHERE package = @package`),
|
INCREMENT: db.prepare(`UPDATE ${TABLE} SET move = move + 1 WHERE package = @package`),
|
||||||
DECREMENT: db.prepare(`UPDATE ${TABLE} SET move = 0 WHERE move = 1`),
|
DECREMENT: db.prepare(`UPDATE ${TABLE} SET move = 0 WHERE move = 1`),
|
||||||
FIXFLAG: db.prepare(`UPDATE ${TABLE} SET move = 1 WHERE move > 1`),
|
FIXFLAG: db.prepare(`UPDATE ${TABLE} SET move = 1 WHERE move > 1`),
|
||||||
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0;`),
|
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0 ORDER BY package ASC;`),
|
||||||
GETPACKAGECOUNTBYMAINTAINER: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0;`)
|
GETPACKAGECOUNTBYMAINTAINER: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer AND move > 0;`)
|
||||||
},
|
},
|
||||||
udate: {
|
udate: {
|
||||||
@@ -33,24 +77,33 @@ class DB {
|
|||||||
INCREMENT: db.prepare(`UPDATE ${TABLE} SET udate = udate + 1 WHERE package = @package`),
|
INCREMENT: db.prepare(`UPDATE ${TABLE} SET udate = udate + 1 WHERE package = @package`),
|
||||||
DECREMENT: db.prepare(`UPDATE ${TABLE} SET udate = 0 WHERE udate = 1`),
|
DECREMENT: db.prepare(`UPDATE ${TABLE} SET udate = 0 WHERE udate = 1`),
|
||||||
FIXFLAG: db.prepare(`UPDATE ${TABLE} SET udate = 1 WHERE udate > 1`),
|
FIXFLAG: db.prepare(`UPDATE ${TABLE} SET udate = 1 WHERE udate > 1`),
|
||||||
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0;`),
|
GETPACKAGESBYMAINTAINER: db.prepare(`SELECT * FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0 ORDER BY package ASC;`),
|
||||||
GETPACKAGECOUNTBYMAINTAINER: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0;`)
|
GETPACKAGECOUNTBYMAINTAINER: db.prepare(`SELECT COUNT(package) as count FROM ${TABLE} WHERE maintainer = @maintainer AND udate > 0;`)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreFlags() {
|
restoreFlags(type: Category | null = null) {
|
||||||
|
if (type !== 'udate') {
|
||||||
this._queries.move.FIXFLAG.run();
|
this._queries.move.FIXFLAG.run();
|
||||||
|
}
|
||||||
|
if (type !== 'move') {
|
||||||
this._queries.udate.FIXFLAG.run();
|
this._queries.udate.FIXFLAG.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
getPackage(pack) {
|
|
||||||
return this._queries.GETPACKAGE.get({
|
|
||||||
package: pack
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePackage(pack, maintainer, lastseen) {
|
getPackage(pack: string): PackageDBEntry {
|
||||||
|
return this._queries.GETPACKAGE.get({
|
||||||
|
package: pack
|
||||||
|
}) as PackageDBEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPackages(startsWith: string | null = null): string[] {
|
||||||
|
return ((!!startsWith) ? this._queries.GETPACKAGESSTARTWITH.all({ startsWith }) :
|
||||||
|
this._queries.GETPACKAGES.all()).map(p => (p as PackageDBEntry).package);
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePackage(pack: string, maintainer: string, lastseen: number): Database.RunResult {
|
||||||
return this._queries[this.getPackage(pack) ? 'UPDATEMAINTAINER' : 'ADDPACKAGE'].run({
|
return this._queries[this.getPackage(pack) ? 'UPDATEMAINTAINER' : 'ADDPACKAGE'].run({
|
||||||
package: pack,
|
package: pack,
|
||||||
maintainer,
|
maintainer,
|
||||||
@@ -58,19 +111,19 @@ class DB {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementFlag(pack, type) {
|
incrementFlag(pack: string, type: Category): boolean {
|
||||||
this._queries[type].INCREMENT.run({
|
this._queries[type].INCREMENT.run({
|
||||||
package: pack
|
package: pack
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
decrementFlags(type) {
|
decrementFlags(type: Category): boolean {
|
||||||
this._queries[type].DECREMENT.run();
|
this._queries[type].DECREMENT.run();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFlag(pack, type, bool) {
|
updateFlag(pack: string, type: Category, bool: number): boolean {
|
||||||
this._queries[type].UPDATE.run({
|
this._queries[type].UPDATE.run({
|
||||||
package: pack,
|
package: pack,
|
||||||
bool
|
bool
|
||||||
@@ -78,41 +131,43 @@ class DB {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFlag(type, bool = true) {
|
getFlag(type: Category, bool: boolean = true): PackageDBEntry[] {
|
||||||
return this._queries[type].GET.all({
|
return this._queries[type].GET.all({
|
||||||
bool
|
bool
|
||||||
});
|
}) as PackageDBEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
getNewByMaintainer(maintainer, type) {
|
getNewByMaintainer(maintainer: string, type: Category): PackageDBEntry[] {
|
||||||
return this._queries[type].GETNEWBYMAINTAINER.all({
|
return this._queries[type].GETNEWBYMAINTAINER.all({
|
||||||
maintainer
|
maintainer
|
||||||
});
|
}) as PackageDBEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
getPackagesByMaintainer(maintainer, type) {
|
getPackagesByMaintainer(maintainer: string, type: Category): PackageDBEntry[] {
|
||||||
return this._queries[type].GETPACKAGESBYMAINTAINER.all({
|
return this._queries[type].GETPACKAGESBYMAINTAINER.all({
|
||||||
maintainer
|
maintainer
|
||||||
});
|
}) as PackageDBEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
getPackageCountByMaintainer(maintainer, type) {
|
getPackageCountByMaintainer(maintainer: string, type: Category): number {
|
||||||
return this._queries[type].GETPACKAGECOUNTBYMAINTAINER.get({
|
return (this._queries[type].GETPACKAGECOUNTBYMAINTAINER.get({
|
||||||
maintainer
|
maintainer
|
||||||
}).count;
|
}) as CountResult).count;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanOldPackages(lastseen) {
|
cleanOldPackages(lastseen: number): Database.RunResult {
|
||||||
return this._queries.REMOVEOLDPACKAGE.run({
|
return this._queries.REMOVEOLDPACKAGE.run({
|
||||||
lastseen
|
lastseen
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getMaintainerPackageCount(maintainer) {
|
getMaintainerPackageCount(maintainer: string): number {
|
||||||
return this._queries.GETMAINTAINERPACKAGECOUNT.get({
|
return (this._queries.GETMAINTAINERPACKAGECOUNT.get({
|
||||||
maintainer
|
maintainer
|
||||||
}).count;
|
}) as CountResult).count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DB;
|
export default DB;
|
||||||
|
export { DB };
|
||||||
|
export type { PackageDBEntry, Category };
|
29
src/index.mts
Normal file
29
src/index.mts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import * as fsp from 'node:fs/promises';
|
||||||
|
import JSON5 from 'json5';
|
||||||
|
import { IRCBot } from './ircBot.mjs';
|
||||||
|
import { Daemon } from './daemon.mjs';
|
||||||
|
import { Web } from './web.mjs';
|
||||||
|
|
||||||
|
const PROJECT_ROOT = path.resolve(import.meta.dirname, '..');
|
||||||
|
const data = await fsp.readFile(process.env['CONFIG'] || path.join(PROJECT_ROOT, 'config', 'config.json'));
|
||||||
|
|
||||||
|
let config = JSON5.parse(data.toString());
|
||||||
|
let arg = process.env['COMPONENT'] || (process.execArgv && process.execArgv[0]);
|
||||||
|
|
||||||
|
if (arg === 'daemon') {
|
||||||
|
const daemon = new Daemon(config);
|
||||||
|
process.on('SIGTERM', daemon.close);
|
||||||
|
}
|
||||||
|
else if (arg === 'ircbot') {
|
||||||
|
const bot = new IRCBot(config);
|
||||||
|
bot.connect();
|
||||||
|
process.on('SIGTERM', bot.close);
|
||||||
|
}
|
||||||
|
else if (arg === 'web') {
|
||||||
|
const web = new Web(config);
|
||||||
|
process.on('SIGTERM', web.close);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error('Please pass the component you wish to run.');
|
||||||
|
}
|
119
src/ircBot.mts
Normal file
119
src/ircBot.mts
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import express from 'express';
|
||||||
|
import type { Config, AuxiliaryIRCConfig } from './config.js';
|
||||||
|
import type http from "http";
|
||||||
|
// @ts-ignore
|
||||||
|
import IRC from 'irc-framework';
|
||||||
|
|
||||||
|
class IRCBot {
|
||||||
|
private _aux: AuxiliaryIRCConfig | undefined;
|
||||||
|
private _channel: string | undefined;
|
||||||
|
private _bot: any;
|
||||||
|
private _enabled: boolean;
|
||||||
|
private _messageQueue: string[];
|
||||||
|
private _webserver: http.Server | undefined;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(config: Config) {
|
||||||
|
const options = config['irc-framework'];
|
||||||
|
const aux = this._aux = config.ircClient || undefined;
|
||||||
|
const app = express();
|
||||||
|
const port = process.env['PRIVATEPORT'] || config.privateport || 8081;
|
||||||
|
this._channel = aux?.channel;
|
||||||
|
this._messageQueue = [];
|
||||||
|
this._enabled = !!options;
|
||||||
|
|
||||||
|
app.set('trust proxy', 1);
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.get('/healthcheck', (_, res) => {
|
||||||
|
if (this._bot && this._bot.connected) {
|
||||||
|
res.send('healthy');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.status(500).send('offline');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/1.0/notifications', (req, res) => {
|
||||||
|
const body = req.body;
|
||||||
|
if (body && body.message) {
|
||||||
|
this.sendMessage(body.message);
|
||||||
|
res.json({
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
error: 'must include `message` property in request body'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (options) {
|
||||||
|
const bot = this._bot = new IRC.Client(options);
|
||||||
|
|
||||||
|
bot.on('sasl failed', (d: Error) => console.error(d));
|
||||||
|
|
||||||
|
bot.on('notice', (d: Error) => console.log(`irc:notice: ${d.message}`));
|
||||||
|
|
||||||
|
bot.on('action', (d: Error) => console.log(`irc:action: ${d.message}`));
|
||||||
|
|
||||||
|
setInterval(() => this.processMessageQueue(), 2000);
|
||||||
|
|
||||||
|
this._webserver = app.listen(port, () => console.log(`artix-checkupdates-notifier-irc running on port ${port}`));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log('"ircClient" not provided in config. IRC notifications will not be delivered.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (this._enabled) {
|
||||||
|
const bot = this._bot;
|
||||||
|
bot.connect();
|
||||||
|
const callback = () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
console.log(`IRC bot ${bot.user.nick} connected.`);
|
||||||
|
bot.join(this._aux?.channel, this._aux?.channel_key);
|
||||||
|
bot.removeListener('registered', callback);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
bot.removeListener('registered', callback);
|
||||||
|
reject('timeout exceeded');
|
||||||
|
}, 60000);
|
||||||
|
bot.on('registered', callback);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage(str: string) {
|
||||||
|
(this._enabled ? str.split('\n') : []).forEach(line => {
|
||||||
|
this._messageQueue.push(line);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
processMessageQueue() {
|
||||||
|
const bot = this._bot
|
||||||
|
let message = bot.connected && this._messageQueue.shift();
|
||||||
|
message && bot.say(this._channel, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
if (this._webserver) {
|
||||||
|
this._webserver.close();
|
||||||
|
}
|
||||||
|
if (this._enabled && this._bot.connected) {
|
||||||
|
this._bot.quit('Shutting down');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IRCBot;
|
||||||
|
export { IRCBot };
|
398
src/web.mts
Normal file
398
src/web.mts
Normal file
@@ -0,0 +1,398 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import * as fsp from 'node:fs/promises';
|
||||||
|
import { DB } from './db.mjs';
|
||||||
|
import express from 'express';
|
||||||
|
import exuseragent from 'express-useragent';
|
||||||
|
import prom from 'prom-client';
|
||||||
|
import sharp from 'sharp';
|
||||||
|
import * as path from 'path';
|
||||||
|
import type http from "http";
|
||||||
|
import type { Request, Response } from "express";
|
||||||
|
import type { Details } from "express-useragent";
|
||||||
|
import type { Config } from './config.js';
|
||||||
|
import type { PackageDBEntry } from './db.mjs';
|
||||||
|
import type { SaveData } from './daemon.mjs';
|
||||||
|
|
||||||
|
const PROJECT_ROOT = path.resolve(import.meta.dirname, '..');
|
||||||
|
const VIEWOPTIONS = {
|
||||||
|
outputFunctionName: 'echo'
|
||||||
|
};
|
||||||
|
|
||||||
|
type Action = "Move" | "Update";
|
||||||
|
|
||||||
|
type WebPackageObject = {
|
||||||
|
package: string;
|
||||||
|
action: Action;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParseablePackage = string | PackageDBEntry;
|
||||||
|
|
||||||
|
function inliner(file: string) {
|
||||||
|
return fs.readFileSync(path.join(PROJECT_ROOT, file));
|
||||||
|
}
|
||||||
|
|
||||||
|
function parsePackage(p: ParseablePackage): string {
|
||||||
|
return typeof p === 'string' ? p : p.package;
|
||||||
|
}
|
||||||
|
|
||||||
|
function packageUrl(p: ParseablePackage) {
|
||||||
|
return `https://gitea.artixlinux.org/packages/${parsePackage(p)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepPackages(arr: ParseablePackage[], action: Action): WebPackageObject[] {
|
||||||
|
return arr.map(m => {
|
||||||
|
return {
|
||||||
|
package: parsePackage(m),
|
||||||
|
action,
|
||||||
|
url: packageUrl(m)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createOutlinedText(string: string, meta: sharp.Metadata, gravity: sharp.Gravity = 'west') {
|
||||||
|
const txt = sharp({
|
||||||
|
create: {
|
||||||
|
width: meta.width || 0,
|
||||||
|
height: meta.height || 0,
|
||||||
|
channels: 4,
|
||||||
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||||
|
}
|
||||||
|
}).composite([
|
||||||
|
{
|
||||||
|
input: {
|
||||||
|
text: {
|
||||||
|
text: string,
|
||||||
|
font: 'Visitor TT2 BRK',
|
||||||
|
fontfile: path.join(PROJECT_ROOT, 'userbar', 'visitor', 'visitor2.ttf'),
|
||||||
|
width: meta.width || 0,
|
||||||
|
dpi: 109,
|
||||||
|
rgba: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
gravity
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const outline = await txt.clone().png().toBuffer();
|
||||||
|
|
||||||
|
const mult = gravity === 'east' ? -1 : 1;
|
||||||
|
|
||||||
|
const layers = [
|
||||||
|
{
|
||||||
|
input: (outline),
|
||||||
|
top: 1 * mult,
|
||||||
|
left: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: (outline),
|
||||||
|
top: 0,
|
||||||
|
left: 1 * mult
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: (outline),
|
||||||
|
top: 1 * mult,
|
||||||
|
left: 2 * mult
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: (outline),
|
||||||
|
top: 2 * mult,
|
||||||
|
left: 1 * mult
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: (await txt.clone().linear(0, 255).png().toBuffer()),
|
||||||
|
top: 1 * mult,
|
||||||
|
left: 1 * mult
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
return txt.composite(layers);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Web {
|
||||||
|
private _webserver: http.Server;
|
||||||
|
private _privateserver: http.Server;
|
||||||
|
|
||||||
|
constructor(options: Config) {
|
||||||
|
const db = new DB(process.env['DBPATH'] || options.db || path.join(PROJECT_ROOT, 'config', 'packages.db'));
|
||||||
|
const app = express();
|
||||||
|
const privateapp = express();
|
||||||
|
const port = process.env['PORT'] || options.port || 8080;
|
||||||
|
const privateport = process.env['PRIVATEPORT'] || options.privateport || 8081;
|
||||||
|
const METRICPREFIX = process.env['METRICPREFIX'] || 'artixpackages_';
|
||||||
|
const maintainers = (options.maintainers || []).map(m => typeof m === 'object' ? m.name : m).sort();
|
||||||
|
const savePath = process.env['SAVEPATH'] || options.savePath || path.join(PROJECT_ROOT, 'config', 'data.json');
|
||||||
|
let saveData: SaveData = {
|
||||||
|
'last-sync': null,
|
||||||
|
move: [],
|
||||||
|
update: []
|
||||||
|
};
|
||||||
|
|
||||||
|
app.set('trust proxy', 1);
|
||||||
|
app.set('view engine', 'ejs');
|
||||||
|
app.set('view options', VIEWOPTIONS);
|
||||||
|
|
||||||
|
app.use(exuseragent.express());
|
||||||
|
|
||||||
|
function sendError(req: Request, res: Response, status: number, description: string) {
|
||||||
|
console.log(`${status} (${description}): ${req.url} requested by ${req.ip} "${req.headers['user-agent']}"`);
|
||||||
|
if ((req.useragent as Details).browser === 'curl') {
|
||||||
|
res.send('404: not found\n');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.render('error',
|
||||||
|
{
|
||||||
|
inliner,
|
||||||
|
site: {
|
||||||
|
prefix: 'Artix Checkupdates',
|
||||||
|
suffix: 'Error'
|
||||||
|
},
|
||||||
|
status,
|
||||||
|
description
|
||||||
|
},
|
||||||
|
function (err, html) {
|
||||||
|
if (!err) {
|
||||||
|
res.status(status).send(html);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).send(description);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readSave() {
|
||||||
|
saveData = JSON.parse((await fsp.readFile(savePath)).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderForCurl(packages: WebPackageObject[]) {
|
||||||
|
const colHeader = 'Package basename';
|
||||||
|
const tabSize = packages.reduce((acc, cur) => Math.max(acc, cur.package?.length || 0), colHeader.length) + 4;
|
||||||
|
return `${colHeader.padEnd(tabSize, ' ')}Action\n${packages.map(p => `${p.package?.padEnd(tabSize, ' ')}${p.action}`).join('\n')}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/healthcheck', async (_, res) => {
|
||||||
|
res.send('Healthy');
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/', async (req, res) => {
|
||||||
|
let packages = prepPackages(saveData.move, 'Move');
|
||||||
|
packages = packages.concat(prepPackages(saveData.update, 'Update'));
|
||||||
|
if ((req.useragent as Details).browser === 'curl') {
|
||||||
|
res.send(renderForCurl(packages));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.render('index',
|
||||||
|
{
|
||||||
|
inliner,
|
||||||
|
site: {
|
||||||
|
prefix: 'Artix Checkupdates',
|
||||||
|
suffix: 'Web Edition'
|
||||||
|
},
|
||||||
|
packages,
|
||||||
|
maintainers: maintainers
|
||||||
|
},
|
||||||
|
function (err, html) {
|
||||||
|
if (!err) {
|
||||||
|
res.send(html);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(err);
|
||||||
|
sendError(req, res, 500, 'Something went wrong. Try again later.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/maintainer/:maintainer', async (req, res) => {
|
||||||
|
const maintainer = req.params.maintainer;
|
||||||
|
const packagesOwned = db.getMaintainerPackageCount(maintainer);
|
||||||
|
let packages = prepPackages(db.getPackagesByMaintainer(maintainer, 'move'), 'Move');
|
||||||
|
packages = packages.concat(prepPackages(db.getPackagesByMaintainer(maintainer, 'udate'), 'Update'));
|
||||||
|
if (packagesOwned > 0) {
|
||||||
|
if ((req.useragent as Details).browser === 'curl') {
|
||||||
|
res.send(`${maintainer}'s pending actions\n\n${renderForCurl(packages)}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
res.render('maintainer',
|
||||||
|
{
|
||||||
|
inliner,
|
||||||
|
site: {
|
||||||
|
prefix: 'Artix Checkupdates',
|
||||||
|
suffix: `${maintainer}'s pending actions`
|
||||||
|
},
|
||||||
|
maintainer,
|
||||||
|
packagesOwned,
|
||||||
|
packages
|
||||||
|
},
|
||||||
|
function (err, html) {
|
||||||
|
if (!err) {
|
||||||
|
res.send(html);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(err);
|
||||||
|
res.status(500).send('Something went wrong. Try again later.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sendError(req, res, 404, 'File not found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/userbar/:maintainer.png', async (req, res) => {
|
||||||
|
const maintainer = req.params.maintainer;
|
||||||
|
const packagesOwned = db.getMaintainerPackageCount(maintainer);
|
||||||
|
if (packagesOwned > 0) {
|
||||||
|
const img = sharp(path.join(PROJECT_ROOT, 'userbar', 'userbar.png'));
|
||||||
|
const meta: sharp.Metadata = await img.metadata();
|
||||||
|
|
||||||
|
const layers = [
|
||||||
|
{
|
||||||
|
input: (await (await createOutlinedText('Artix Maintainer', meta)).png().toBuffer()),
|
||||||
|
top: 1,
|
||||||
|
left: 55
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: (await (await createOutlinedText(`${packagesOwned} packages`, meta, 'east')).png().toBuffer()),
|
||||||
|
top: 3,
|
||||||
|
left: -12
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
res.set('Content-Type', 'image/png')
|
||||||
|
.set('Cache-Control', 'public, max-age=172800')
|
||||||
|
.send(await img.composite(layers).png({
|
||||||
|
quality: 90,
|
||||||
|
compressionLevel: 3
|
||||||
|
}).toBuffer());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sendError(req, res, 404, 'File not found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/robots.txt', (_, res) => {
|
||||||
|
res.set('content-type', 'text/plain').send('User-agent: *\nDisallow: /metrics\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/1.0/maintainers', (req, res) => {
|
||||||
|
const acceptHeader = req.headers.accept;
|
||||||
|
res.set('Cache-Control', 'public, max-age=360');
|
||||||
|
if (acceptHeader && acceptHeader.includes('application/json')) {
|
||||||
|
res.json({
|
||||||
|
maintainers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.send(maintainers.join(' '));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/1.0/packages', (req, res) => {
|
||||||
|
const acceptHeader = req.headers.accept;
|
||||||
|
const startsWith = req.query['startswith'] as string;
|
||||||
|
const packages = db.getPackages(startsWith);
|
||||||
|
res.set('Cache-Control', 'public, max-age=360');
|
||||||
|
if (acceptHeader && acceptHeader.includes('application/json')) {
|
||||||
|
res.json({
|
||||||
|
packages
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.send(packages.join(' '));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
privateapp.put('/api/1.0/data', (_, res) => {
|
||||||
|
try {
|
||||||
|
readSave();
|
||||||
|
res.json({
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error(ex);
|
||||||
|
res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
error: 'failed to read save data'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const register = prom.register;
|
||||||
|
|
||||||
|
new prom.Gauge({
|
||||||
|
name: `${METRICPREFIX}pending_packages`,
|
||||||
|
help: 'Number of packages that have pending moves and updates.',
|
||||||
|
labelNames: ['maintainer', 'action'],
|
||||||
|
collect() {
|
||||||
|
maintainers.forEach(m => {
|
||||||
|
this.set({
|
||||||
|
maintainer: `${m}`,
|
||||||
|
action: 'move'
|
||||||
|
}, db.getPackageCountByMaintainer(m, 'move'));
|
||||||
|
this.set({
|
||||||
|
maintainer: `${m}`,
|
||||||
|
action: 'update'
|
||||||
|
}, db.getPackageCountByMaintainer(m, 'udate'));
|
||||||
|
});
|
||||||
|
this.set({
|
||||||
|
maintainer: 'any',
|
||||||
|
action: 'move'
|
||||||
|
}, saveData.move.length);
|
||||||
|
this.set({
|
||||||
|
maintainer: 'any',
|
||||||
|
action: 'update'
|
||||||
|
}, saveData.update.length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
new prom.Gauge({
|
||||||
|
name: `${METRICPREFIX}watched_packages`,
|
||||||
|
help: 'Number of packages being monitored for updates.',
|
||||||
|
labelNames: ['maintainer'],
|
||||||
|
collect() {
|
||||||
|
maintainers.forEach(m => {
|
||||||
|
this.set({
|
||||||
|
maintainer: `${m}`
|
||||||
|
}, db.getMaintainerPackageCount(m));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/metrics', async (_, res) => {
|
||||||
|
try {
|
||||||
|
res.set('Content-Type', register.contentType);
|
||||||
|
res.end(await register.metrics());
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
console.error(ex);
|
||||||
|
res.status(500).send('something went wrong.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use('/assets/', express.static('assets', {
|
||||||
|
maxAge: '30d'
|
||||||
|
}));
|
||||||
|
|
||||||
|
app.use((req, res) => sendError(req, res, 404, 'File not found'));
|
||||||
|
|
||||||
|
privateapp.use('/', app);
|
||||||
|
|
||||||
|
readSave();
|
||||||
|
|
||||||
|
this._webserver = app.listen(port, () => console.log(`artix-checkupdates-web running on port ${port}`));
|
||||||
|
this._privateserver = privateapp.listen(privateport);
|
||||||
|
}
|
||||||
|
|
||||||
|
close = () => {
|
||||||
|
this._webserver.close();
|
||||||
|
this._privateserver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Web;
|
||||||
|
export { Web };
|
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
printf "GIT_TOKEN=$GITEA_TOKEN\n" > ~/.config/artools/artools-pkg.conf
|
|
||||||
printf "ARTIX_MIRROR=$ARTIX_MIRROR\nARCH_MIRROR=$ARCH_MIRROR\nARTIX_REPOS=$ARTIX_REPOS\nARCH_REPOS=$ARCH_REPOS" "%s" "%s" > ~/.config/artix-checkupdates/config && \
|
|
||||||
node index.js
|
|
@@ -97,6 +97,10 @@ header {
|
|||||||
a:hover,
|
a:hover,
|
||||||
a:focus {
|
a:focus {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
|
||||||
|
&.logo svg .artix-logo-base {
|
||||||
|
fill: #53bffc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.logo {
|
a.logo {
|
||||||
@@ -137,6 +141,15 @@ header {
|
|||||||
|
|
||||||
footer {
|
footer {
|
||||||
font-size: 9pt;
|
font-size: 9pt;
|
||||||
|
|
||||||
|
ul li {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0 1em 0 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr td:last-child {
|
||||||
|
min-width: 6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
@@ -151,14 +164,14 @@ footer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width:790px) {
|
@media screen and (max-width:910px) {
|
||||||
.container {
|
.container {
|
||||||
width: initial;
|
width: initial;
|
||||||
margin: .5em .5em;
|
margin: .5em .5em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width:660px) {
|
@media screen and (max-width:740px) {
|
||||||
header {
|
header {
|
||||||
nav {
|
nav {
|
||||||
float: initial;
|
float: initial;
|
||||||
@@ -167,6 +180,10 @@ footer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width:270px) {
|
@media screen and (max-width:270px) {
|
||||||
|
footer ul li {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
header nav ul li {
|
header nav ul li {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
@@ -174,4 +191,10 @@ footer {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
font-size: 1em;
|
||||||
|
line-height: 1.1em;
|
||||||
|
}
|
||||||
}
|
}
|
12
tsconfig.dist.json
Normal file
12
tsconfig.dist.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"sourceMap": true,
|
||||||
|
"inlineSources": true,
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./distribution"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src"
|
||||||
|
]
|
||||||
|
}
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": "@sindresorhus/tsconfig",
|
||||||
|
"compilerOptions": {
|
||||||
|
"exactOptionalPropertyTypes": true,
|
||||||
|
"esModuleInterop": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src"
|
||||||
|
]
|
||||||
|
}
|
BIN
userbar/userbar.png
Normal file
BIN
userbar/userbar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
userbar/userbar.psd
Normal file
BIN
userbar/userbar.psd
Normal file
Binary file not shown.
86
userbar/visitor/visitor.txt
Normal file
86
userbar/visitor/visitor.txt
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
______________________________
|
||||||
|
Visitor Created by Brian Kent
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
Thanks for Downloading Visitor.
|
||||||
|
|
||||||
|
-Visitor TT1 [.ttf]
|
||||||
|
-Visitor TT2 [.ttf]
|
||||||
|
-Visitor [7pt] [.fon]
|
||||||
|
|
||||||
|
'Visitor.fon' is a Windows Bitmap Font (.fon). This font is best
|
||||||
|
used at 7pt. To use it at larger point sizes (for images), try using
|
||||||
|
a graphics program like Photo Shop, Paint Shop Pro, or the Paint
|
||||||
|
program that comes with Windows. Type out your text at the recommended
|
||||||
|
point size [7pt], then resize the image. Set the color mode to 256
|
||||||
|
or 2 colors so the edges don't get blured when resizing, then after you
|
||||||
|
have the text to the size that you want, then change back to a higher
|
||||||
|
color mode and edit the image.
|
||||||
|
|
||||||
|
For programs that don't show Bitmap Fonts in the Font Selector, you
|
||||||
|
may be able to get the font to work by typing in:
|
||||||
|
visitor -brk-
|
||||||
|
|
||||||
|
The TTF versions were created different ways. TT1 was created from
|
||||||
|
within FontLab and TT2 was created in Illustrator then imported into
|
||||||
|
FontLab. I didn't know which one to include so I just included both.
|
||||||
|
|
||||||
|
|
||||||
|
If you have any questions or comments, you can e-mail me at
|
||||||
|
kentpw@norwich.net
|
||||||
|
|
||||||
|
You can visit my Homepage <<3C>NIGMA GAMES & FONTS> at
|
||||||
|
http://www.aenigmafonts.com/
|
||||||
|
|
||||||
|
____________
|
||||||
|
!!! NOTE !!!
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
This font has been updated! I've edited the (BRK) in the font name
|
||||||
|
to just BRK. It seems that Adobe Illustrator and web pages with CSS
|
||||||
|
don't like fonts with ( and ) in their name.
|
||||||
|
|
||||||
|
________________
|
||||||
|
INSTALLING FONTS
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
There's a couple of ways to install Fonts. The 'easy' way to
|
||||||
|
install fonts is to just Unzip/place the font file(s) into your
|
||||||
|
Windows\Fonts directory (I always use this method). If you're unable
|
||||||
|
to do it the 'easy' way, then try to do it this way (for Windows
|
||||||
|
95/98/NT):
|
||||||
|
|
||||||
|
1] Unzip the Font(s) to a folder (or somewhere, just remember where
|
||||||
|
you unzipped it) on your Computer.
|
||||||
|
|
||||||
|
2] Next, click on the START button, then select SETTINGS then
|
||||||
|
CONTROL PANEL.
|
||||||
|
|
||||||
|
3] When the Control Panel Window pops up, Double Click on FONTS.
|
||||||
|
|
||||||
|
4] When the FONTS window pops up, select File then Install New Font...
|
||||||
|
|
||||||
|
5] A Add Fonts window will pop up, just go to the folder that you
|
||||||
|
unzipped the Font(s) to, select the Font(s) and then click on OK.
|
||||||
|
Now the Font(s) are installed.
|
||||||
|
|
||||||
|
Now you can use the Font(s) in programs the utilize Fonts. Make
|
||||||
|
sure that you install the font(s) first, then open up your apps
|
||||||
|
(so the app will recognize the font). Sometimes you'll have to
|
||||||
|
wait until you computer 'auto-refreshes' for programs to recognize
|
||||||
|
fonts (Windows is sometimes slow to do that). You can refresh your
|
||||||
|
computer quicker by going into Windows Explorer -or- My Computer and
|
||||||
|
press F5 (or in the menubar select VIEW then REFRESH).
|
||||||
|
|
||||||
|
|
||||||
|
__________
|
||||||
|
DISCLAIMER
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
-The font(s) in this zip file were created by me (Brian Kent). All
|
||||||
|
of my Fonts are Freeware, you can use them any way you want to
|
||||||
|
(Personal use, Commercial use, or whatever).
|
||||||
|
|
||||||
|
-If you have a Font related site and would like to offer my fonts on
|
||||||
|
your site, go right ahead. All I ask is that you keep this text file
|
||||||
|
intact with the Font.
|
||||||
|
|
||||||
|
-You may not Sell or Distribute my Fonts for profit or alter them in
|
||||||
|
any way without asking me first. [e-mail - kentpw@norwich.net]
|
BIN
userbar/visitor/visitor1.ttf
Normal file
BIN
userbar/visitor/visitor1.ttf
Normal file
Binary file not shown.
BIN
userbar/visitor/visitor2.ttf
Normal file
BIN
userbar/visitor/visitor2.ttf
Normal file
Binary file not shown.
@@ -1,5 +1,9 @@
|
|||||||
<div class="container bg">
|
<div class="container bg">
|
||||||
<footer>
|
<footer>
|
||||||
© <%= (new Date()).getFullYear() %> Artix Linux
|
<ul>
|
||||||
|
<li>© <%= (new Date()).getFullYear() %> Artix Linux</li>
|
||||||
|
<li>Developed by Cory Sanin</li>
|
||||||
|
<li><a href="https://github.com/CorySanin/artix-checkupdates-web">Source</a></li>
|
||||||
|
</ul>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
@@ -9,6 +9,6 @@
|
|||||||
<meta name="apple-mobile-web-app-title" content="Artix Checkupdates">
|
<meta name="apple-mobile-web-app-title" content="Artix Checkupdates">
|
||||||
<meta name="application-name" content="Artix Checkupdates">
|
<meta name="application-name" content="Artix Checkupdates">
|
||||||
<meta name="theme-color" content="#212121">
|
<meta name="theme-color" content="#212121">
|
||||||
<link rel="stylesheet" href="/assets/css/styles.css?v=1">
|
<link rel="stylesheet" href="/assets/css/styles.css?v=3">
|
||||||
<link rel="shortcut icon" href="/assets/svg/artix_logo.svg">
|
<link rel="shortcut icon" href="/assets/svg/artix_logo.svg">
|
||||||
</head>
|
</head>
|
@@ -9,7 +9,8 @@
|
|||||||
<li><a href="https://artixlinux.org/">Artix Linux</a></li>
|
<li><a href="https://artixlinux.org/">Artix Linux</a></li>
|
||||||
<li><a href="https://forum.artixlinux.org/">Forum</a></li>
|
<li><a href="https://forum.artixlinux.org/">Forum</a></li>
|
||||||
<li><a href="https://wiki.artixlinux.org/">Wiki</a></li>
|
<li><a href="https://wiki.artixlinux.org/">Wiki</a></li>
|
||||||
<li><a href="https://gitea.artixlinux.org/">Sources</a></li>
|
<li><a href="https://gitea.artixlinux.org/explore/repos">Sources</a></li>
|
||||||
|
<li><a href="https://packages.artixlinux.org/">Packages</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
@@ -9,23 +9,18 @@
|
|||||||
<% maintainers && maintainers.forEach(m => { %>
|
<% maintainers && maintainers.forEach(m => { %>
|
||||||
<li><a href="/maintainer/<%= m %>"><%= m %></a></li>
|
<li><a href="/maintainer/<%= m %>"><%= m %></a></li>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
|
<li><a href="/maintainer/orphan">Orphan Packages</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<h2>All Pending</h2>
|
<h2>All Pending (<%= (packages && packages.length) || 0 %> packages)</h2>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Package</th>
|
<th>Package</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% savedata.move && savedata.move.forEach(p => { %>
|
<% packages && packages.forEach(p => { %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= p %></td>
|
<td><a href="<%= p.url %>"><%= p.package %></a></td>
|
||||||
<td>Move</td>
|
<td><%= p.action %></td>
|
||||||
</tr>
|
|
||||||
<% }); %>
|
|
||||||
<% savedata.update && savedata.update.forEach(p => { %>
|
|
||||||
<tr>
|
|
||||||
<td><%= p %></td>
|
|
||||||
<td>Update</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</table>
|
</table>
|
||||||
|
@@ -3,27 +3,32 @@
|
|||||||
<body>
|
<body>
|
||||||
<%- include("header", locals) %>
|
<%- include("header", locals) %>
|
||||||
<div class="container bg">
|
<div class="container bg">
|
||||||
|
<% if (maintainer === 'orphan') { %>
|
||||||
|
<h1>Orphaned Packages with Pending Operations</h1>
|
||||||
|
<p>
|
||||||
|
There are <a href="https://gitea.artixlinux.org/explore/repos?q=<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a> without a maintainer.
|
||||||
|
</p>
|
||||||
|
<% } else { %>
|
||||||
<h1><%= maintainer %>'s Operations</h1>
|
<h1><%= maintainer %>'s Operations</h1>
|
||||||
<p>
|
<p>
|
||||||
<%= maintainer %> owns <a href="https://gitea.artixlinux.org/explore/repos?q=maintainer-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a>.
|
<%= maintainer %> owns <a href="https://gitea.artixlinux.org/explore/repos?q=maintainer-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a>.
|
||||||
</p>
|
</p>
|
||||||
|
<% } %>
|
||||||
|
<p>
|
||||||
|
<%= (packages && packages.length) || 0 %> of which require attention.
|
||||||
|
</p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Package</th>
|
<th>Package</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% moves && moves.forEach(p => { %>
|
<% packages && packages.forEach(p => { %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= p.package %></td>
|
<td><a href="<%= p.url %>"><%= p.package %></a></td>
|
||||||
<td>Move</td>
|
<td><%= p.action %></td>
|
||||||
</tr>
|
|
||||||
<% }); %>
|
|
||||||
<% updates && updates.forEach(p => { %>
|
|
||||||
<tr>
|
|
||||||
<td><%= p.package %></td>
|
|
||||||
<td>Update</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% }); %>
|
<% }); %>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<%- include("footer", locals) %>
|
||||||
</body>
|
</body>
|
175
web.js
175
web.js
@@ -1,175 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const prom = require('prom-client');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const PROJECT_ROOT = __dirname;
|
|
||||||
const VIEWOPTIONS = {
|
|
||||||
outputFunctionName: 'echo'
|
|
||||||
};
|
|
||||||
|
|
||||||
function inliner(file) {
|
|
||||||
return fs.readFileSync(path.join(PROJECT_ROOT, file));
|
|
||||||
}
|
|
||||||
|
|
||||||
class Web {
|
|
||||||
constructor(db, options, savedata) {
|
|
||||||
const app = express();
|
|
||||||
const port = process.env.PORT || options.port || 8080;
|
|
||||||
const METRICPREFIX = process.env.METRICPREFIX || 'artixpackages_';
|
|
||||||
const maintainers = this._maintainers = options.maintainers.map(m => typeof m === 'object' ? m.name : m).sort();
|
|
||||||
|
|
||||||
app.set('trust proxy', 1);
|
|
||||||
app.set('view engine', 'ejs');
|
|
||||||
app.set('view options', VIEWOPTIONS);
|
|
||||||
|
|
||||||
function sendError(res, status, description) {
|
|
||||||
res.render('error',
|
|
||||||
{
|
|
||||||
inliner,
|
|
||||||
site: {
|
|
||||||
prefix: 'Artix Checkupdates',
|
|
||||||
suffix: 'Error'
|
|
||||||
},
|
|
||||||
status,
|
|
||||||
description
|
|
||||||
},
|
|
||||||
function (err, html) {
|
|
||||||
if (!err) {
|
|
||||||
res.status(status).send(html);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(err);
|
|
||||||
res.status(500).send(description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
app.get('/healthcheck', async (_, res) => {
|
|
||||||
res.send('Healthy');
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/', async (_, res) => {
|
|
||||||
res.render('index',
|
|
||||||
{
|
|
||||||
inliner,
|
|
||||||
site: {
|
|
||||||
prefix: 'Artix Checkupdates',
|
|
||||||
suffix: 'Web Edition'
|
|
||||||
},
|
|
||||||
savedata,
|
|
||||||
maintainers: maintainers
|
|
||||||
},
|
|
||||||
function (err, html) {
|
|
||||||
if (!err) {
|
|
||||||
res.send(html);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(err);
|
|
||||||
sendError(res, 500, 'Something went wrong. Try again later.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/maintainer/:maintainer', async (req, res) => {
|
|
||||||
const maintainer = req.params.maintainer;
|
|
||||||
const packagesOwned = db.getMaintainerPackageCount(maintainer);
|
|
||||||
if (packagesOwned > 0) {
|
|
||||||
res.render('maintainer',
|
|
||||||
{
|
|
||||||
inliner,
|
|
||||||
site: {
|
|
||||||
prefix: 'Artix Checkupdates',
|
|
||||||
suffix: `${maintainer}'s pending actions`
|
|
||||||
},
|
|
||||||
maintainer,
|
|
||||||
packagesOwned,
|
|
||||||
moves: db.getPackagesByMaintainer(maintainer, 'move'),
|
|
||||||
updates: db.getPackagesByMaintainer(maintainer, 'udate'),
|
|
||||||
},
|
|
||||||
function (err, html) {
|
|
||||||
if (!err) {
|
|
||||||
res.send(html);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(err);
|
|
||||||
res.status(500).send('Something went wrong. Try again later.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sendError(res, 404, 'File not found');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/robots.txt', (_, res) => {
|
|
||||||
res.set('content-type', 'text/plain').send('User-agent: *\nDisallow: /metrics\n');
|
|
||||||
});
|
|
||||||
|
|
||||||
const register = prom.register;
|
|
||||||
|
|
||||||
new prom.Gauge({
|
|
||||||
name: `${METRICPREFIX}pending_packages`,
|
|
||||||
help: 'Number of packages that have pending moves and updates.',
|
|
||||||
labelNames: ['maintainer', 'action'],
|
|
||||||
collect() {
|
|
||||||
maintainers.forEach(m => {
|
|
||||||
this.set({
|
|
||||||
maintainer: `${m}`,
|
|
||||||
action: 'move'
|
|
||||||
}, db.getPackageCountByMaintainer(m, 'move'));
|
|
||||||
this.set({
|
|
||||||
maintainer: `${m}`,
|
|
||||||
action: 'update'
|
|
||||||
}, db.getPackageCountByMaintainer(m, 'udate'));
|
|
||||||
});
|
|
||||||
this.set({
|
|
||||||
maintainer: 'any',
|
|
||||||
action: 'move'
|
|
||||||
}, savedata.move.length);
|
|
||||||
this.set({
|
|
||||||
maintainer: 'any',
|
|
||||||
action: 'update'
|
|
||||||
}, savedata.update.length);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
new prom.Gauge({
|
|
||||||
name: `${METRICPREFIX}watched_packages`,
|
|
||||||
help: 'Number of packages being monitored for updates.',
|
|
||||||
labelNames: ['maintainer'],
|
|
||||||
collect() {
|
|
||||||
maintainers.forEach(m => {
|
|
||||||
this.set({
|
|
||||||
maintainer: `${m}`
|
|
||||||
}, db.getMaintainerPackageCount(m));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/metrics', async (_, res) => {
|
|
||||||
try {
|
|
||||||
res.set('Content-Type', register.contentType);
|
|
||||||
res.end(await register.metrics());
|
|
||||||
}
|
|
||||||
catch (ex) {
|
|
||||||
res.status(500).send(ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use('/assets/', express.static('assets', {
|
|
||||||
maxAge: '30d'
|
|
||||||
}));
|
|
||||||
|
|
||||||
this._webserver = app.listen(port, () => console.log(`artix-packy-notifier-web running on port ${port}`));
|
|
||||||
}
|
|
||||||
|
|
||||||
close = () => {
|
|
||||||
this._webserver.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Web;
|
|
Reference in New Issue
Block a user