-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildrelease
More file actions
executable file
·144 lines (101 loc) · 4.16 KB
/
buildrelease
File metadata and controls
executable file
·144 lines (101 loc) · 4.16 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
/*
LiveG OS Update Files
Copyright (C) LiveG. All Rights Reserved.
https://liveg.tech/os
Licensed by the LiveG Open-Source Licence, which can be found at LICENCE.md.
*/
const os = require("os");
const fs = require("fs");
const child_process = require("child_process");
const mkdirp = require("mkdirp").mkdirp;
const minimist = require("minimist");
const BOLD_TEXT = "\x1b[1m%s\x1b[0m";
var argv = minimist(process.argv.slice(2));
if (os.EOL != "\n") {
console.error("System must be POSIX-compliant");
process.exit(1);
}
mkdirp.sync("releases");
var currentReleaseData = JSON.parse(fs.readFileSync("release.json"));
currentReleaseData.releasedAt = Date.now();
console.log(BOLD_TEXT, "Checking files...");
console.log("");
var fileStats = {total: 0, pass: 0, fail: 0};
[
currentReleaseData.preinstallScriptPath,
currentReleaseData.postinstallScriptPath,
currentReleaseData.rebootScriptPath,
currentReleaseData.rollbackScriptPath,
...currentReleaseData.files.map((file) => file.path)
].forEach(function(path) {
if (path == undefined) {
return;
}
fileStats.total++;
if (fs.existsSync(`files/${path}`)) {
fileStats.pass++;
console.log("\x1b[42m\x1b[37m%s\x1b[0m %s", " PASS ", path);
} else {
fileStats.fail++;
console.log("\x1b[41m\x1b[37m%s\x1b[0m %s", " FAIL ", path);
}
});
console.log("");
console.log(BOLD_TEXT, `Out of ${fileStats.total} files, ${fileStats.pass} pass and ${fileStats.fail} fail`);
if (fileStats.fail > 0) {
console.error("Cannot continue with nonexistent files");
process.exit(1);
}
console.log("");
console.log(BOLD_TEXT, "Creating archive...");
console.log("");
currentReleaseData.archivePath = `${currentReleaseData.vernum}.tar.gz`;
currentReleaseData.archiveMethod = "tarGzip";
child_process.execSync(`tar -C files -czvf releases/${currentReleaseData.archivePath} .`, {stdio: "inherit"});
currentReleaseData.archiveHash = child_process.execSync(`sha256sum releases/${currentReleaseData.archivePath}`).toString().split(" ")[0];
currentReleaseData.archiveHashMethod = "sha256";
console.log("");
console.log(`Archive hash: ${currentReleaseData.archiveHash}`);
console.log("");
console.log(BOLD_TEXT, "Adding update configuration to index file...");
console.log("");
var indexData = {};
try {
indexData = JSON.parse(fs.readFileSync("releases/index.json"));
console.log("Index file read");
} catch (e) {
console.log("Couldn't open index file, so will create new data");
}
indexData.updates ||= [];
indexData.updates = indexData.updates.filter((update) => update.vernum != currentReleaseData.vernum);
indexData.updates.push(currentReleaseData);
fs.writeFileSync("releases/index.json", JSON.stringify(indexData, null, 4));
console.log("");
console.log(BOLD_TEXT, "Signing index file...");
console.log("");
child_process.execSync("gpg --list-keys", {stdio: "inherit"});
child_process.execSync("gpg --batch --yes --local-user 'LiveG Technologies' --output releases/index.json.sig --armor --detach-sig releases/index.json", {stdio: "inherit"});
console.log("");
console.log(BOLD_TEXT, "Verifying index file signature...");
console.log("");
child_process.execSync("gpg --verify releases/index.json.sig releases/index.json", {stdio: "inherit"});
console.log("");
console.log(BOLD_TEXT, "Release build complete!");
if (argv["ssh-upload"]) {
console.log("");
console.log(BOLD_TEXT, "Uploading to remote server via SSH...");
console.log("");
if (!argv["upload-index-only"]) {
console.log("Upload archive");
child_process.execSync(`scp -r releases/${currentReleaseData.archivePath} ${argv["ssh-upload"]}:resources/osupdates/`, {stdio: "inherit"});
} else {
console.log("Skipping archive upload");
}
console.log("Upload index file");
child_process.execSync(`scp -r releases/index.json ${argv["ssh-upload"]}:resources/osupdates/`, {stdio: "inherit"});
console.log("Upload index file signature");
child_process.execSync(`scp -r releases/index.json.sig ${argv["ssh-upload"]}:resources/osupdates/`, {stdio: "inherit"});
console.log("");
console.log(BOLD_TEXT, "Release upload complete!");
}