parent
d4d07b8a8d
commit
59cfbec460
4 changed files with 99 additions and 78 deletions
|
@ -3,6 +3,7 @@ import { writeFileSync } from 'node:fs';
|
||||||
|
|
||||||
import { parseArgs } from './lib';
|
import { parseArgs } from './lib';
|
||||||
|
|
||||||
|
import { updateCaddyPlugins } from './caddy';
|
||||||
import { updateDocker } from './docker';
|
import { updateDocker } from './docker';
|
||||||
import { updateFirefoxAddons } from '././firefox';
|
import { updateFirefoxAddons } from '././firefox';
|
||||||
import { updateFlakeInputs } from './flake';
|
import { updateFlakeInputs } from './flake';
|
||||||
|
@ -10,7 +11,6 @@ import updateNodeModules from './node-modules';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
runNixUpdate,
|
runNixUpdate,
|
||||||
updateCaddyPlugins,
|
|
||||||
updateVuetorrent,
|
updateVuetorrent,
|
||||||
} from './misc';
|
} from './misc';
|
||||||
|
|
||||||
|
|
89
apps/update-sources/src/caddy.ts
Normal file
89
apps/update-sources/src/caddy.ts
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
import { writeFileSync } from 'node:fs';
|
||||||
|
import { spawnSync } from 'node:child_process';
|
||||||
|
|
||||||
|
import { replaceInFile } from './lib';
|
||||||
|
|
||||||
|
/* Types */
|
||||||
|
interface Plugin {
|
||||||
|
url: string
|
||||||
|
version: string
|
||||||
|
type: 'version' | 'git'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Constants */
|
||||||
|
const FLAKE = process.env.FLAKE;
|
||||||
|
|
||||||
|
const genPluginsText = (
|
||||||
|
plugins: Record<string, Plugin>,
|
||||||
|
) => `{
|
||||||
|
plugins = {
|
||||||
|
${Object.entries(plugins)
|
||||||
|
.map(([key, value]) => `
|
||||||
|
${key} = {
|
||||||
|
url = "${value.url}";
|
||||||
|
version = "${value.version}";
|
||||||
|
type = "${value.type}";
|
||||||
|
};
|
||||||
|
`)
|
||||||
|
.join('')}
|
||||||
|
};
|
||||||
|
|
||||||
|
hash = "";
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const updateCaddyPlugins = () => {
|
||||||
|
let updates = '';
|
||||||
|
const dir = `${FLAKE}/configurations/cluster/modules/caddy`;
|
||||||
|
|
||||||
|
// Setup workspace
|
||||||
|
spawnSync(
|
||||||
|
[
|
||||||
|
'rm -rf /tmp/update-caddy',
|
||||||
|
'mkdir -p /tmp/update-caddy',
|
||||||
|
'cd /tmp/update-caddy || exit 1',
|
||||||
|
'go mod init temp',
|
||||||
|
].join('; '),
|
||||||
|
[],
|
||||||
|
{ shell: true, cwd: '/tmp' },
|
||||||
|
);
|
||||||
|
|
||||||
|
const plugins = JSON.parse(spawnSync('nix',
|
||||||
|
['eval', '-f', `${dir}/plugins.nix`, '--json'],
|
||||||
|
{ shell: true }).stdout.toString()).plugins as Record<string, Plugin>;
|
||||||
|
|
||||||
|
// Get most recent versions of plugins
|
||||||
|
Object.entries(plugins).forEach(([key, value]) => {
|
||||||
|
const NEW_VERSION = spawnSync([
|
||||||
|
'go mod init temp > /dev/null',
|
||||||
|
`go get ${value.url}${value.type === 'git' ? '@HEAD' : ''} > /dev/null`,
|
||||||
|
`grep '${value.url}' go.mod`,
|
||||||
|
].join('; '), [], { shell: true, cwd: '/tmp/update-caddy' })
|
||||||
|
.stdout
|
||||||
|
.toString()
|
||||||
|
.trim()
|
||||||
|
.replace(' // indirect', '')
|
||||||
|
.split(' ')[1];
|
||||||
|
|
||||||
|
if (plugins[key].version !== NEW_VERSION) {
|
||||||
|
updates += `${key}: ${plugins[key].version} -> ${NEW_VERSION}\n`;
|
||||||
|
plugins[key].version = NEW_VERSION;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
writeFileSync(`${dir}/plugins.nix`, genPluginsText(plugins));
|
||||||
|
|
||||||
|
// Get new hash
|
||||||
|
const caddyPkgAttr = 'nixosConfigurations.thingone.config.services.caddy.package';
|
||||||
|
|
||||||
|
const NEW_HASH = spawnSync(
|
||||||
|
`nix build "$FLAKE#${caddyPkgAttr}" |& sed -n 's/.*got: *//p'`,
|
||||||
|
[],
|
||||||
|
{ shell: true },
|
||||||
|
).stdout.toString().trim();
|
||||||
|
|
||||||
|
replaceInFile(/hash = ".*";/, `hash = "${NEW_HASH}";`, `${dir}/plugins.nix`);
|
||||||
|
|
||||||
|
return updates;
|
||||||
|
};
|
|
@ -1,7 +1,7 @@
|
||||||
import { writeFileSync } from 'node:fs';
|
import { writeFileSync } from 'node:fs';
|
||||||
import { spawnSync } from 'node:child_process';
|
import { spawnSync } from 'node:child_process';
|
||||||
|
|
||||||
import { parseFetchurl, replaceInFile } from './lib';
|
import { parseFetchurl } from './lib';
|
||||||
|
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
|
@ -84,78 +84,3 @@ export const runNixUpdate = (
|
||||||
stderr: execution.stderr.toString(),
|
stderr: execution.stderr.toString(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const genPluginsText = (
|
|
||||||
plugins: Record<string, { url: string, version: string }>,
|
|
||||||
) => `# This file was autogenerated. DO NOT EDIT!
|
|
||||||
{
|
|
||||||
plugins = {
|
|
||||||
${Object.entries(plugins)
|
|
||||||
.map(([key, value]) => `
|
|
||||||
${key} = {
|
|
||||||
url = "${value.url}";
|
|
||||||
version = "${value.version}";
|
|
||||||
};
|
|
||||||
`)
|
|
||||||
.join('')}
|
|
||||||
};
|
|
||||||
|
|
||||||
hash = "";
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const updateCaddyPlugins = () => {
|
|
||||||
let updates = '';
|
|
||||||
const dir = `${FLAKE}/configurations/cluster/modules/caddy`;
|
|
||||||
|
|
||||||
// Setup workspace
|
|
||||||
spawnSync(
|
|
||||||
[
|
|
||||||
'rm -rf /tmp/update-caddy',
|
|
||||||
'mkdir -p /tmp/update-caddy',
|
|
||||||
'cd /tmp/update-caddy || exit 1',
|
|
||||||
'go mod init temp',
|
|
||||||
].join('; '),
|
|
||||||
[],
|
|
||||||
{ shell: true, cwd: '/tmp' },
|
|
||||||
);
|
|
||||||
|
|
||||||
const plugins = JSON.parse(spawnSync('nix',
|
|
||||||
['eval', '-f', `${dir}/plugins.nix`, '--json'],
|
|
||||||
{ shell: true }).stdout.toString()).plugins as Record<string, { url: string, version: string }>;
|
|
||||||
|
|
||||||
// Get most recent versions of plugins
|
|
||||||
Object.entries(plugins).forEach(([key, value]) => {
|
|
||||||
const NEW_VERSION = spawnSync([
|
|
||||||
'go mod init temp > /dev/null',
|
|
||||||
`go get ${value.url} > /dev/null`,
|
|
||||||
`grep '${value.url}' go.mod`,
|
|
||||||
].join('; '), [], { shell: true, cwd: '/tmp/update-caddy' })
|
|
||||||
.stdout
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
.replace(' // indirect', '')
|
|
||||||
.split(' ')[1];
|
|
||||||
|
|
||||||
if (plugins[key].version !== NEW_VERSION) {
|
|
||||||
updates += `${key}: ${plugins[key].version} -> ${NEW_VERSION}`;
|
|
||||||
plugins[key].version = NEW_VERSION;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
writeFileSync(`${dir}/plugins.nix`, genPluginsText(plugins));
|
|
||||||
|
|
||||||
// Get new hash
|
|
||||||
const caddyPkgAttr = 'nixosConfigurations.thingone.config.services.caddy.package';
|
|
||||||
|
|
||||||
const NEW_HASH = spawnSync(
|
|
||||||
`nix build "$FLAKE#${caddyPkgAttr}" |& sed -n 's/.*got: *//p'`,
|
|
||||||
[],
|
|
||||||
{ shell: true },
|
|
||||||
).stdout.toString().trim();
|
|
||||||
|
|
||||||
replaceInFile(/hash = ".*";/, `hash = "${NEW_HASH}";`, `${dir}/plugins.nix`);
|
|
||||||
|
|
||||||
return updates;
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
# This file was autogenerated. DO NOT EDIT!
|
# This file was autogenerated. DO NOT EDIT!
|
||||||
{
|
{
|
||||||
plugins = {
|
plugins = {
|
||||||
|
certmagic = {
|
||||||
|
url = "github.com/caddyserver/certmagic";
|
||||||
|
version = "v0.22.2";
|
||||||
|
type = "version";
|
||||||
|
};
|
||||||
|
|
||||||
cloudflare = {
|
cloudflare = {
|
||||||
url = "github.com/caddy-dns/cloudflare";
|
url = "github.com/caddy-dns/cloudflare";
|
||||||
version = "v0.0.0-20250228175314-1fb64108d4de";
|
version = "v0.0.0-20250228175314-1fb64108d4de";
|
||||||
|
type = "version";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
hash = "sha256-YYpsf8HMONR1teMiSymo2y+HrKoxuJMKIea5/NEykGc=";
|
hash = "sha256-rT+igzVTqHXUHqYFENH9GJYNTgY6oB4XlEzUU/vihdk=";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue