6 Commits

Author SHA1 Message Date
f3b63d5cbd v3.4.0: list orphan packages
track and list orphan packages

respond to requests while syncing packages

fix crashes due to configuration

bump dependency versions
2024-03-23 04:09:38 -05:00
1f54eae84d 3.3.3: automatically clear lockfiles 2024-02-29 19:18:51 -05:00
ee29453824 update base docker image tag name 2024-02-19 04:32:22 -05:00
9ffcd0b5ee fix userbar base 2024-02-16 04:28:16 -05:00
7410c7ca0c v3.3.2: dynamically generated, old-school userbar
I can't believe I'm doing this. Closes #3
2024-02-16 04:21:31 -05:00
6db2c2d683 v3.3.1: configurable sync frequency 2024-02-15 03:47:05 -05:00
14 changed files with 1120 additions and 115 deletions

View File

@@ -1,4 +1,4 @@
FROM artixlinux/artixlinux:devel as build-env
FROM artixlinux/artixlinux:base-devel as build-env
WORKDIR /usr/notifier
@@ -14,7 +14,7 @@ RUN npm run-script build && \
npm ci --only=production
FROM artixlinux/artixlinux:devel as deploy
FROM artixlinux/artixlinux:base-devel as deploy
VOLUME /usr/notifier/config
WORKDIR /usr/notifier

View File

@@ -13,6 +13,7 @@ create `config/config.json`:
| apprise | The URL of the Apprise instance for sending notifications |
| maintainers | Array of maintainer names as strings or objects containing the `name` of the maintainer and a list of `channels` to send notifications to |
| cron | The cron schedule for when the application should check for pending operations via [artix-checkupdates](https://gitea.artixlinux.org/artix/artix-checkupdates) |
| syncfreq | How often (in days) should the application sync package ownership from Gitea |
| 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`) |

View File

@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const os = require('os');
const spawn = require('child_process').spawn;
const cron = require('node-cron');
const dayjs = require('dayjs');
@@ -11,7 +12,12 @@ const Web = require('./web');
const fsp = fs.promises;
const TIMEOUT = 180000;
const ORPHAN = {
"name": "orphan",
"ircName": "orphaned"
};
const EXTRASPACE = new RegExp('\\s+', 'g');
const CHECKUPDATESCACHE = path.join(os.homedir(), '.cache', 'artix-checkupdates');
const NICETYPES = {
move: 'move',
udate: 'update'
@@ -23,8 +29,8 @@ let saveData = {
update: []
}
let cronjob;
let ircBot;
let locked = false;
let savePath = process.env.SAVEPATH || path.join(__dirname, 'config', 'data.json');
@@ -34,6 +40,7 @@ fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.jso
process.exit(1);
}
else {
console.log('Written by Cory Sanin for Artix Linux');
const config = json5.parse(data);
savePath = config.savePath || savePath;
const db = new DB(process.env.DBPATH || config.db || path.join(__dirname, 'config', 'packages.db'));
@@ -48,7 +55,7 @@ fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.jso
// resetting flags in case of improper shutdown
db.restoreFlags();
cronjob = cron.schedule(process.env.CRON || config.cron || '*/30 * * * *', () => {
let cronjob = cron.schedule(process.env.CRON || config.cron || '*/30 * * * *', () => {
main(config, db);
});
@@ -59,16 +66,19 @@ fs.readFile(process.env.CONFIGPATH || path.join(__dirname, 'config', 'config.jso
process.on('SIGTERM', () => {
cronjob.stop();
web.close();
ircBot.clouse();
ircBot.close();
});
}
});
async function main(config, db) {
if (locked) {
return
}
locked = true;
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'))) {
if (!('last-sync' in saveData) || !saveData['last-sync'] || dayjs(saveData['last-sync']).isBefore(now.subtract(process.env.SYNCFREQ || config.syncfreq || 2, 'days'))) {
ircBot.close();
await updateMaintainers(config, db);
saveData['last-sync'] = now.toJSON();
@@ -77,7 +87,7 @@ async function main(config, db) {
}
await checkupdates(config, db);
await writeSaveData();
cronjob.start();
locked = false;
console.log('Task complete.');
}
@@ -91,8 +101,13 @@ async function writeSaveData() {
}
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');
try {
await handleUpdates(config, db, saveData.move = await execCheckUpdates(['-m']), 'move');
await handleUpdates(config, db, saveData.update = await execCheckUpdates(['-u']), 'udate');
}
catch (ex) {
console.error('Failed to check for updates:', ex);
}
}
async function handleUpdates(config, db, packs, type) {
@@ -100,13 +115,13 @@ async function handleUpdates(config, db, packs, type) {
let p = db.getPackage(v);
p && db.updateFlag(v, type, p[type] > 0 ? 2 : 4);
});
for (let i = 0; i < config.maintainers.length; i++) {
const m = config.maintainers[i];
const maintainers = [...config.maintainers, ORPHAN];
for (let i = 0; i < maintainers.length; i++) {
const m = maintainers[i];
const mname = 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') {
if (typeof m === 'object' && m.channels) {
notify({
api: config.apprise,
urls: m.channels
@@ -122,15 +137,20 @@ async function handleUpdates(config, db, packs, 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++) {
const maintainers = [...(config.maintainers || []), ORPHAN];
for (let i = 0; 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));
const packages = await getMaintainersPackages(maintainer);
for (let j = 0; j < packages.length; j++) {
const package = packages[j];
db.updatePackage(package, maintainer, lastseen);
await asyncSleep(50);
}
}
catch (err) {
console.error(`Failed to get packages for ${maintainer}`);
@@ -144,7 +164,7 @@ async function updateMaintainers(config, db) {
function getMaintainersPackages(maintainer) {
return new Promise((resolve, reject) => {
let process = spawn('artixpkg', ['admin', 'query', '-m', maintainer]);
let process = spawn('artixpkg', ['admin', 'query', maintainer === ORPHAN.name ? '-t' : '-m', maintainer]);
let timeout = setTimeout(() => {
reject('Timed out');
process.kill();
@@ -222,28 +242,47 @@ function parseCheckUpdatesOutput(output) {
return packages;
}
function execCheckUpdates(flags) {
async function cleanUpLockfiles() {
try {
await fsp.rm(CHECKUPDATESCACHE, { recursive: true, force: true });
}
catch (ex) {
console.error('Failed to remove the artix-checkupdates cache directory:', ex);
}
}
function execCheckUpdates(flags, errCallback) {
return new Promise((resolve, reject) => {
let process = spawn('artix-checkupdates', flags);
let timeout = setTimeout(() => {
let timeout = setTimeout(async () => {
process.kill() && await cleanUpLockfiles();
reject('Timed out');
process.kill();
}, TIMEOUT);
let outputstr = '';
let errorOutput = '';
process.stdout.on('data', data => {
outputstr += data.toString();
});
process.stderr.on('data', err => {
console.error(err.toString());
const errstr = err.toString();
errorOutput += `${errstr}, `;
console.error(errstr);
})
process.on('exit', async (code) => {
if (code === 0) {
if (code === 0 && errorOutput.length === 0) {
clearTimeout(timeout);
resolve(parseCheckUpdatesOutput(outputstr));
}
else {
reject(code);
errorOutput.includes('unable to lock database') && cleanUpLockfiles();
reject((code && `exited with ${code}`) || errorOutput);
}
});
});
}
function asyncSleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}

View File

@@ -7,6 +7,7 @@ class IRCBot {
const aux = this._aux = config.ircClient || {};
this._channel = aux.channel;
this._messageQueue = [];
this._enabled = !!options;
if (options) {
const bot = this._bot = new IRC.Client(options);
@@ -18,29 +19,37 @@ class IRCBot {
setInterval(() => this.processMessageQueue(), 2000);
}
else {
console.log('"ircClient" not provided in config. IRC notifications will not be delivered.');
}
}
connect() {
return new Promise((resolve, reject) => {
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);
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();
};
const timeout = setTimeout(() => {
bot.removeListener('registered', callback);
reject('timeout exceeded');
}, 60000);
bot.on('registered', callback);
}
});
}
sendMessage(str) {
str.split('\n').forEach(line => {
(this._enabled ? str.split('\n') : []).forEach(line => {
this._messageQueue.push(line);
});
}
@@ -52,7 +61,7 @@ class IRCBot {
}
close() {
if (this._bot.connected) {
if (this._enabled && this._bot.connected) {
this._bot.quit('Shutting down');
}
}

897
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "artix-packy-notifier",
"version": "3.3.0",
"version": "3.4.0",
"description": "Determine packages that need attention",
"main": "index.js",
"scripts": {
@@ -23,19 +23,20 @@
},
"homepage": "https://gitlab.com/sanin.dev/artix-packy-notifier#readme",
"dependencies": {
"better-sqlite3": "9.4.0",
"better-sqlite3": "9.4.3",
"dayjs": "1.11.10",
"ejs": "3.1.9",
"express": "4.18.2",
"express": "4.19.1",
"irc-framework": "4.13.1",
"json5": "2.2.3",
"node-cron": "3.0.3",
"phin": "^3.7.0",
"prom-client": "15.1.0"
"prom-client": "15.1.0",
"sharp": "0.33.2"
},
"devDependencies": {
"csso": "5.0.5",
"sass": "1.66.1",
"sass": "1.72.0",
"uglify-js": "3.17.4"
}
}

BIN
userbar/userbar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
userbar/userbar.psd Normal file

Binary file not shown.

View 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]

Binary file not shown.

Binary file not shown.

View File

@@ -9,6 +9,7 @@
<% maintainers && maintainers.forEach(m => { %>
<li><a href="/maintainer/<%= m %>"><%= m %></a></li>
<% }); %>
<li><a href="/maintainer/orphan">Orphan Packages</a></li>
</ul>
<h2>All Pending</h2>
<table>

View File

@@ -3,10 +3,17 @@
<body>
<%- include("header", locals) %>
<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-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a> without a maintainer.
</p>
<% } else { %>
<h1><%= maintainer %>'s Operations</h1>
<p>
<%= maintainer %> owns <a href="https://gitea.artixlinux.org/explore/repos?q=maintainer-<%= maintainer %>&topic=1"><%= packagesOwned %> packages</a>.
</p>
<% } %>
<table>
<tr>
<th>Package</th>

106
web.js
View File

@@ -1,5 +1,6 @@
const express = require('express');
const prom = require('prom-client');
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
@@ -33,12 +34,71 @@ function prepPackages(arr, action) {
});
}
async function createOutlinedText(string, meta, gravity = 'west') {
const txt = sharp({
create: {
width: meta.width,
height: meta.height,
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,
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 {
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();
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');
@@ -130,10 +190,54 @@ class Web {
}
});
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 = 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;
if (acceptHeader && acceptHeader.includes('application/json')) {
res.json({
maintainers
});
}
else {
res.send(maintainers.join(' '));
}
});
const register = prom.register;
new prom.Gauge({