-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserscripts.ts
More file actions
55 lines (45 loc) · 1.69 KB
/
userscripts.ts
File metadata and controls
55 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { listUserscripts } from '../../../bash-scripts';
import { UnraidModuleExtensionBase } from '../unraid-module-extension-base';
import { UserScript } from './userscripts/user-script';
export interface IScheduleTask {
script: string;
frequency: string;
id: string;
custom: string;
}
export interface IUserScriptSchedule {
[key: string]: IScheduleTask;
}
export interface Schedule {
script: string;
frequency: string;
id: string;
custom: string;
}
export interface UserScriptJSON {
name: string;
dirName: string;
running: boolean;
script: string;
description?: string;
schedule: Schedule | null;
}
export class UnraidModuleUserScriptsExtension extends UnraidModuleExtensionBase {
async hasUserScriptsInstalled(): Promise<boolean> {
const { code } = await this.instance.execute(`test -f /boot/config/plugins/user.scripts.plg`);
return code === 0;
}
async getUserScriptSchedule(): Promise<IUserScriptSchedule> {
const { code, stdout } = await this.instance.execute(`cat /boot/config/plugins/user.scripts/schedule.json`);
if (code !== 0) throw new Error('Got non-zero exit code while reading userscript schedule');
return JSON.parse(stdout.join(''));
}
async getUserScripts(): Promise<UserScript[]> {
const { stdout, code } = await this.instance.execute(listUserscripts());
if (code !== 0) throw new Error('Got non-zero exit code while reading userscripts');
const parsedUserScripts: UserScriptJSON[] = JSON.parse(stdout.join('\n'));
return parsedUserScripts.map((userScriptInfo) => {
return new UserScript(this.instance, userScriptInfo);
});
}
}