@backedrelay/relay 0.3.11 → 0.3.12
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/relay.mjs +12 -10
- package/package.json +1 -1
package/bin/relay.mjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {createHash} from 'node:crypto';
|
|
3
|
-
import {closeSync,copyFileSync,existsSync,linkSync,mkdirSync,openSync,readFileSync,readSync,renameSync,statSync} from 'node:fs';
|
|
3
|
+
import {chmodSync,closeSync,copyFileSync,existsSync,linkSync,mkdirSync,openSync,readFileSync,readSync,renameSync,statSync} from 'node:fs';
|
|
4
4
|
import {homedir} from 'node:os';
|
|
5
|
-
import {join,resolve,dirname} from 'node:path';
|
|
5
|
+
import {join,resolve,dirname,isAbsolute} from 'node:path';
|
|
6
6
|
import {spawnSync} from 'node:child_process';
|
|
7
|
-
const REPO='jtravelsworld/relay-hybrid-private-release',TAG='relay-hybrid-0.3.
|
|
8
|
-
const DIST_SHA='
|
|
9
|
-
const
|
|
7
|
+
const REPO='jtravelsworld/relay-hybrid-private-release',TAG='relay-hybrid-0.3.12-private';
|
|
8
|
+
const DIST_SHA='cb9ebc690662d2c85f4f5f27166f7b96eed089ecc7d12ed55135890f39e1144f';
|
|
9
|
+
const cacheBase=process.env.RELAY_CACHE_DIR;
|
|
10
|
+
if(cacheBase!==undefined&&!isAbsolute(cacheBase))throw new Error('RELAY_CACHE_DIR must be an absolute directory');
|
|
11
|
+
const cache=cacheBase===undefined?join(homedir(),'.local','share','relay-private','0.3.12'):join(cacheBase,'0.3.12');
|
|
10
12
|
function hash(path){const h=createHash('sha256'),fd=openSync(path,'r'),buf=Buffer.alloc(1024*1024);try{let n;while((n=readSync(fd,buf,0,buf.length,null))>0)h.update(buf.subarray(0,n));}finally{closeSync(fd);}return h.digest('hex');}
|
|
11
13
|
function run(cmd,args){const r=spawnSync(cmd,args,{stdio:'inherit'});if(r.error)throw r.error;if(r.status!==0)throw new Error(`${cmd} failed (${r.status})`);}
|
|
12
|
-
function privateDir(path){mkdirSync(path,{recursive:true,mode:0o700});}
|
|
14
|
+
function privateDir(path){mkdirSync(path,{recursive:true,mode:0o700});chmodSync(path,0o700);}
|
|
13
15
|
function checked(path,want){return existsSync(path)&&hash(path)===want;}
|
|
14
16
|
function releaseFiles(dir){const manifest=JSON.parse(readFileSync(join(dir,'FILE-MANIFEST.json'),'utf8'));if(manifest.schema!=='relay.private-release-file-manifest/v3.3')throw new Error('Unknown release manifest');for(const [name,entry] of Object.entries(manifest.files)){if(name.startsWith('/')||name.split('/').includes('..')||!checked(join(dir,name),entry.sha256))throw new Error(`Release file hash mismatch: ${name}`);}return manifest;}
|
|
15
17
|
function downloadAsset(name,dir,tag=TAG){run('gh',['release','download',tag,'--repo',REPO,'--pattern',name,'--dir',dir,'--clobber']);}
|
|
@@ -26,14 +28,14 @@ function fetchRelease(){
|
|
|
26
28
|
if(!checked(path,entry.sha256))downloadAsset(name,downloads,tag);
|
|
27
29
|
if(!checked(path,entry.sha256)||statSync(path).size!==entry.bytes)throw new Error(`Downloaded asset mismatch: ${name}`);
|
|
28
30
|
}
|
|
29
|
-
privateDir(release);run('tar',['-xzf',join(downloads,'relay-private-0.3.
|
|
30
|
-
for(const name of ['images-linux-amd64.tar.zst', 'runtime-
|
|
31
|
+
privateDir(release);run('tar',['-xzf',join(downloads,'relay-private-0.3.12-payload.tar.gz'),'-C',release]);
|
|
32
|
+
for(const name of ['images-linux-amd64.tar.zst', 'runtime-selfhost-0312-source.tar.gz', 'parent-history-035-source.tar.gz', 'composer-selfhost-0312-source.tar.gz']){const to=join(release,name);if(!checked(to,dist.assets[name].sha256))renameSync(join(downloads,name),to);}
|
|
31
33
|
if(hash(join(release,'FILE-MANIFEST.json'))!==dist.fileManifestSha256||hash(join(release,'release.json'))!==dist.releaseManifestSha256)throw new Error('Release manifest mismatch');releaseFiles(release);return release;
|
|
32
34
|
}
|
|
33
35
|
let args=process.argv.slice(2),dir=process.env.RELAY_RELEASE_DIR;
|
|
34
36
|
const index=args.indexOf('--release-dir');if(index>=0){if(!args[index+1])throw new Error('--release-dir requires a path');dir=args[index+1];args.splice(index,2);}
|
|
35
|
-
if(args.length===1&&['--version','-v'].includes(args[0])){process.stdout.write('0.3.
|
|
36
|
-
if(args.length===1&&['--help','-h','help'].includes(args[0])){process.stdout.write('Relay 0.3.
|
|
37
|
+
if(args.length===1&&['--version','-v'].includes(args[0])){process.stdout.write('0.3.12\n');process.exit(0);}
|
|
38
|
+
if(args.length===1&&['--help','-h','help'].includes(args[0])){process.stdout.write('Relay 0.3.12: install/setup, doctor, health, status, start, stop, snapshot, restore-local, inference-ollama, inference-configure. Invite-only Runtime downloads require authenticated gh access. See START-HERE.md.'+'\n');process.exit(0);}
|
|
37
39
|
if(args[0]==='fetch'){const path=fetchRelease();process.stdout.write(path+'\n');process.exit(0);}
|
|
38
40
|
if(!args.length)args=['install'];
|
|
39
41
|
if(!args.length){process.stderr.write('Usage: relay [--release-dir PATH] <doctor|install|health|status|start|stop|backup|restore|upgrade|rollback|inference-doctor|inference-ollama|inference-configure|inference-recover> ...\n');process.exit(2);}
|