2024-11-13 15:17:45 -05:00
|
|
|
import { writeFileSync } from 'node:fs';
|
2024-07-20 22:02:22 -04:00
|
|
|
import { spawnSync } from 'node:child_process';
|
|
|
|
|
2024-11-15 11:37:58 -05:00
|
|
|
import { parseFetchurl } from './lib';
|
2024-07-20 22:33:14 -04:00
|
|
|
|
2024-07-20 22:02:22 -04:00
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
const FLAKE = process.env.FLAKE;
|
|
|
|
|
2024-10-20 21:42:54 -04:00
|
|
|
const genVueText = (
|
|
|
|
version: string,
|
|
|
|
hash: string,
|
|
|
|
url: string,
|
|
|
|
) => `# This file was autogenerated. DO NOT EDIT!
|
2024-07-20 22:33:14 -04:00
|
|
|
{
|
|
|
|
version = "${version}";
|
|
|
|
url = "${url}";
|
|
|
|
hash = "${hash}";
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const updateVuetorrent = () => {
|
2024-12-17 00:26:53 -05:00
|
|
|
const FILE = `${FLAKE}/configurations/nos/modules/qbittorrent/vuetorrent.nix`;
|
2024-07-20 22:33:14 -04:00
|
|
|
|
|
|
|
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
|
|
|
};
|
2024-10-20 21:42:54 -04:00
|
|
|
|
2024-10-31 15:35:03 -04:00
|
|
|
export const updateCustomPackage = (pkg: string) => spawnSync(
|
|
|
|
`nix run ${FLAKE}#${pkg}.update`,
|
2024-10-20 21:42:54 -04:00
|
|
|
[],
|
|
|
|
{ shell: true },
|
|
|
|
).stderr.toString();
|
2024-12-21 05:57:56 -05:00
|
|
|
|
|
|
|
export const runNixUpdate = (attr: string, options: string[] = []) => spawnSync(
|
|
|
|
'nix-update',
|
|
|
|
['--flake', attr, ...options],
|
|
|
|
{ shell: true, cwd: FLAKE },
|
|
|
|
).stderr.toString();
|