forked from OpenAF/roJob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genScripts.yaml
85 lines (76 loc) · 2.56 KB
/
genScripts.yaml
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
ojob:
async: true
logToConsole: false
todo:
- Detect OS
- Detect Python version
- Generate API key
- Generate Python script
- Generate OS script
- Generate Watchdog oJob
jobs:
#----------------
- name: Detect OS
exec: |
ow.loadFormat();
global.os = (ow.format.getOS().match(/windows/i) ? "win" : "unix");
log("OS type: " + global.os);
#----------------------------
- name: Detect Python version
exec: |
var res = sh("python --version");
global.python = (res.match(/ 2\./) ? 2 : 3);
log("Python version: " + global.python);
#-----------------------
- name: Generate API key
exec: |
var key = sha512(genUUID());
io.writeFileString(getOPackPath("roJob") + "/.apikey", key);
global.key = key;
log("Generated new key: " + key);
#-----------------------------
- name: Generate Python script
deps:
- Detect Python version
- Generate API key
exec: |
var script;
if (global.python == 2) {
script = io.readFileString(getOPackPath("roJob") + "/rojob.py.sample2");
} else {
script = io.readFileString(getOPackPath("roJob") + "/rojob.py.sample3");
}
script = script.replace(/APIKEY = \"[^"]*\"/, "APIKEY = \"" + global.key + "\"");
io.writeFileString(getOPackPath("roJob") + "/rojob.py", script);
log("Generated " + getOPackPath("roJob") + "/rojob.py.");
#-------------------------
- name: Generate OS script
deps:
- Detect OS
- Generate Python script
exec: |
var script = "";
if (global.os == "win") {
script += "@echo off\n\n";
script += "python " + getOPackPath("roJob") + "\\rojob.py %*\n";
io.writeFileString("rojob.bat", script);
log("Generated rojob.bat.");
} else {
script += "#!/bin/sh\n\n";
script += "python " + getOPackPath("roJob") + "/rojob.py \"$@\"\n";
io.writeFileString("rojob.sh", script);
log("Generated rojob.sh.");
}
#-----------------------------
- name: Generate Watchdog oJob
deps:
- Detect OS
exec: |
io.writeFileString("watchdog.yaml", templify(io.readFileString(getOPackPath("roJob") + "/watchdog.yaml.sample"), {
win: (global.os == "win"),
opackHome: getOPackPath("roJob").replace(/\\/g, "/"),
openafHome: getOpenAFPath().replace(/\\/g, "/"),
//ports: [ 8787, 8788, 8789 ]
ports: [ 8787 ]
}));
log("Generated watchdog.yaml.");