2024-07-20 22:33:14 -04:00
|
|
|
import { readdirSync, writeFileSync } from 'node:fs';
|
2024-07-20 22:02:22 -04:00
|
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
|
2024-07-20 22:33:14 -04:00
|
|
|
import { parseFetchurl } from './lib.ts';
|
|
|
|
|
2024-07-20 22:02:22 -04:00
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
const FLAKE = process.env.FLAKE;
|
|
|
|
|
2024-07-20 23:40:06 -04:00
|
|
|
export const updateFlakeInputs = () => {
|
|
|
|
const output = spawnSync(
|
|
|
|
`nix flake update --flake ${FLAKE} |& grep -v "warning: updating lock file"`,
|
|
|
|
[],
|
|
|
|
{ shell: true },
|
|
|
|
).stdout
|
|
|
|
.toString()
|
2024-07-21 01:17:10 -04:00
|
|
|
// Add an extra blank line between inputs
|
2024-07-20 23:40:06 -04:00
|
|
|
.split('\n•')
|
|
|
|
.join('\n\n•')
|
2024-07-21 01:17:10 -04:00
|
|
|
// Shorten git revs to help readability
|
2024-07-20 23:40:06 -04:00
|
|
|
.split('\n')
|
|
|
|
.map((l) => l
|
|
|
|
.replace(/.{33}\?narHash=sha256[^']*/, '')
|
|
|
|
.replace(/&rev=(.{7})[^'&]*/, (_, backref) => `&rev=${backref}`))
|
|
|
|
.join('\n');
|
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
2024-07-20 22:02:22 -04:00
|
|
|
export const updateDocker = () => {
|
|
|
|
let updates = '';
|
|
|
|
|
|
|
|
const FILE = `${FLAKE}/devices/nos/modules/arion`;
|
|
|
|
|
|
|
|
readdirSync(FILE, { withFileTypes: true, recursive: true }).forEach((path) => {
|
|
|
|
if (path.name === 'compose.nix') {
|
|
|
|
updates += spawnSync('updateImages', [path.parentPath], { shell: true })
|
|
|
|
.stdout.toString();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return updates;
|
|
|
|
};
|
2024-07-20 22:33:14 -04:00
|
|
|
|
|
|
|
const genVueText = (version: string, hash: string, url: string) =>
|
|
|
|
`# This file was autogenerated. DO NOT EDIT!
|
|
|
|
{
|
|
|
|
version = "${version}";
|
|
|
|
url = "${url}";
|
|
|
|
hash = "${hash}";
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const updateVuetorrent = () => {
|
|
|
|
const FILE = `${FLAKE}/devices/nos/modules/qbittorrent/vuetorrent.nix`;
|
|
|
|
|
|
|
|
const OLD_VERSION = JSON.parse(spawnSync('nix',
|
|
|
|
['eval', '-f', FILE, '--json'],
|
|
|
|
{ shell: true }).stdout.toString()).version;
|
|
|
|
|
|
|
|
const VERSION = JSON.parse(spawnSync('curl',
|
|
|
|
['-s', 'https://api.github.com/repos/VueTorrent/VueTorrent/releases/latest'],
|
|
|
|
{ shell: true }).stdout.toString()).tag_name.replace('v', '');
|
|
|
|
|
|
|
|
const URL = `https://github.com/VueTorrent/VueTorrent/releases/download/v${VERSION}/vuetorrent.zip`;
|
|
|
|
const HASH = parseFetchurl(URL);
|
|
|
|
|
|
|
|
const fileText = genVueText(VERSION, HASH, URL);
|
|
|
|
|
|
|
|
writeFileSync(FILE, fileText);
|
|
|
|
|
2024-07-22 20:16:03 -04:00
|
|
|
return OLD_VERSION !== VERSION ? `Vuetorrent: ${OLD_VERSION} -> ${VERSION}` : '';
|
2024-07-20 22:33:14 -04:00
|
|
|
};
|