dockupdate 0.0.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dockupdate +25 -0
- package/install.js +96 -0
- package/package.json +27 -13
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
package/bin/dockupdate
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Shim: forwards to the platform binary downloaded by install.js.
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const bin = path.join(
|
|
8
|
+
__dirname,
|
|
9
|
+
process.platform === 'win32' ? 'dockupdate.exe' : 'dockupdate-bin'
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(bin)) {
|
|
13
|
+
console.error(
|
|
14
|
+
'dockupdate: binary not found. The postinstall download may have failed;\n' +
|
|
15
|
+
'try reinstalling: npm install -g dockupdate'
|
|
16
|
+
);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const r = spawnSync(bin, process.argv.slice(2), { stdio: 'inherit' });
|
|
21
|
+
if (r.error) {
|
|
22
|
+
console.error('dockupdate: failed to start: ' + r.error.message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
process.exit(r.status === null ? 1 : r.status);
|
package/install.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// postinstall: downloads the dockupdate release archive matching this
|
|
3
|
+
// package version and the current platform from GitHub Releases, verifies
|
|
4
|
+
// its SHA256 against the published checksums, and installs the binary next
|
|
5
|
+
// to the bin shim.
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const https = require('https');
|
|
9
|
+
const http = require('http');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const tar = require('tar');
|
|
12
|
+
|
|
13
|
+
const pkg = require('./package.json');
|
|
14
|
+
|
|
15
|
+
const REPO = 'amagyar/dockupdate';
|
|
16
|
+
const VERSION = process.env.DOCKUPDATE_VERSION || pkg.version;
|
|
17
|
+
const BASE_URL =
|
|
18
|
+
process.env.DOCKUPDATE_BASE_URL ||
|
|
19
|
+
`https://github.com/${REPO}/releases/download/v${VERSION}`;
|
|
20
|
+
|
|
21
|
+
const PLATFORMS = { darwin: 'darwin', linux: 'linux', win32: 'windows' };
|
|
22
|
+
const ARCHES = { x64: 'amd64', arm64: 'arm64' };
|
|
23
|
+
|
|
24
|
+
function fail(msg) {
|
|
25
|
+
console.error(`dockupdate: ${msg}`);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function download(url, dest, redirects = 5) {
|
|
30
|
+
// http is only reachable via the DOCKUPDATE_BASE_URL testing override;
|
|
31
|
+
// the production base URL is always https.
|
|
32
|
+
const transport = url.startsWith('http:') ? http : https;
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
transport
|
|
35
|
+
.get(url, (res) => {
|
|
36
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
37
|
+
res.resume();
|
|
38
|
+
if (redirects <= 0) return reject(new Error('too many redirects'));
|
|
39
|
+
return resolve(download(res.headers.location, dest, redirects - 1));
|
|
40
|
+
}
|
|
41
|
+
if (res.statusCode !== 200) {
|
|
42
|
+
res.resume();
|
|
43
|
+
return reject(new Error(`GET ${url} -> HTTP ${res.statusCode}`));
|
|
44
|
+
}
|
|
45
|
+
const out = fs.createWriteStream(dest);
|
|
46
|
+
res.pipe(out);
|
|
47
|
+
out.on('finish', () => out.close(resolve));
|
|
48
|
+
out.on('error', reject);
|
|
49
|
+
})
|
|
50
|
+
.on('error', reject);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function main() {
|
|
55
|
+
const goos = PLATFORMS[process.platform];
|
|
56
|
+
const goarch = ARCHES[process.arch];
|
|
57
|
+
if (!goos || !goarch) {
|
|
58
|
+
fail(
|
|
59
|
+
`unsupported platform: ${process.platform}/${process.arch}. ` +
|
|
60
|
+
`supported: darwin/linux/win32 on x64/arm64`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const archive = `dockupdate_${VERSION}_${goos}_${goarch}.tar.gz`;
|
|
65
|
+
const tmp = fs.mkdtempSync(path.join(require('os').tmpdir(), 'dockupdate-'));
|
|
66
|
+
|
|
67
|
+
console.error(`dockupdate: downloading ${archive}`);
|
|
68
|
+
await download(`${BASE_URL}/${archive}`, path.join(tmp, archive));
|
|
69
|
+
await download(`${BASE_URL}/checksums.txt`, path.join(tmp, 'checksums.txt'));
|
|
70
|
+
|
|
71
|
+
// Verify checksum.
|
|
72
|
+
const sums = fs.readFileSync(path.join(tmp, 'checksums.txt'), 'utf8');
|
|
73
|
+
const line = sums.split('\n').find((l) => l.trim().endsWith(archive));
|
|
74
|
+
if (!line) fail(`checksums.txt has no entry for ${archive}`);
|
|
75
|
+
const want = line.trim().split(/\s+/)[0];
|
|
76
|
+
const got = crypto
|
|
77
|
+
.createHash('sha256')
|
|
78
|
+
.update(fs.readFileSync(path.join(tmp, archive)))
|
|
79
|
+
.digest('hex');
|
|
80
|
+
if (want !== got) fail(`checksum mismatch for ${archive} (want ${want}, got ${got})`);
|
|
81
|
+
|
|
82
|
+
// Extract the binary and place it next to the shim.
|
|
83
|
+
tar.x({ file: path.join(tmp, archive), cwd: tmp, sync: true });
|
|
84
|
+
const extracted = path.join(tmp, goos === 'windows' ? 'dockupdate.exe' : 'dockupdate');
|
|
85
|
+
const dest = path.join(
|
|
86
|
+
__dirname,
|
|
87
|
+
'bin',
|
|
88
|
+
goos === 'windows' ? 'dockupdate.exe' : 'dockupdate-bin'
|
|
89
|
+
);
|
|
90
|
+
fs.copyFileSync(extracted, dest);
|
|
91
|
+
fs.chmodSync(dest, 0o755);
|
|
92
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
93
|
+
console.error(`dockupdate: installed ${VERSION} (${goos}/${goarch})`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main().catch((err) => fail(err.message));
|
package/package.json
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dockupdate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Terminal UI to manage Docker/Podman containers and their updates",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/amagyar/dockupdate",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/amagyar/dockupdate.git"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"dockupdate": "bin/dockupdate"
|
|
13
|
+
},
|
|
10
14
|
"scripts": {
|
|
11
|
-
"
|
|
15
|
+
"postinstall": "node install.js"
|
|
12
16
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=16"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"tar": "^7.4.3"
|
|
22
|
+
},
|
|
23
|
+
"os": [
|
|
24
|
+
"darwin",
|
|
25
|
+
"linux",
|
|
26
|
+
"win32"
|
|
27
|
+
],
|
|
28
|
+
"cpu": [
|
|
29
|
+
"x64",
|
|
30
|
+
"arm64"
|
|
31
|
+
]
|
|
18
32
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.js
DELETED