From 20ed523b302f9faa04de51c7feff9716167f84b0 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 2 Sep 2023 17:25:29 -0700 Subject: [PATCH] cloud: fix EACCES --- plugins/cloud/package-lock.json | 4 ++-- plugins/cloud/package.json | 2 +- plugins/cloud/src/main.ts | 31 +++++++++++++++++-------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/plugins/cloud/package-lock.json b/plugins/cloud/package-lock.json index 024846e9f8..31a8a2f98b 100644 --- a/plugins/cloud/package-lock.json +++ b/plugins/cloud/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/cloud", - "version": "0.1.34", + "version": "0.1.35", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/cloud", - "version": "0.1.34", + "version": "0.1.35", "dependencies": { "@eneris/push-receiver": "^3.1.4", "@scrypted/common": "file:../../common", diff --git a/plugins/cloud/package.json b/plugins/cloud/package.json index 1b0508e9aa..f4ff9b4fdf 100644 --- a/plugins/cloud/package.json +++ b/plugins/cloud/package.json @@ -54,5 +54,5 @@ "@types/nat-upnp": "^1.1.2", "@types/node": "^20.4.5" }, - "version": "0.1.34" + "version": "0.1.35" } diff --git a/plugins/cloud/src/main.ts b/plugins/cloud/src/main.ts index 39015c2cdc..62e793b9ce 100644 --- a/plugins/cloud/src/main.ts +++ b/plugins/cloud/src/main.ts @@ -798,35 +798,38 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings, this.console.log('starting cloudflared'); this.cloudflared = await backOff(async () => { const pluginVolume = process.env.SCRYPTED_PLUGIN_VOLUME; - const version = 'v1'; - const cloudflareD = path.join(pluginVolume, 'cloudflare.d', `${process.platform}-${process.arch}-${version}`); - mkdirSync(cloudflareD, { - recursive: true, - }) - process.chdir(cloudflareD); + const version = 2; + const cloudflareD = path.join(pluginVolume, 'cloudflare.d', `v${version}`, `${process.platform}-${process.arch}`); if (!fs.existsSync(cloudflared.bin)) { - if (process.platform === 'darwin' && process.arch === 'arm64') { - mkdirSync(path.dirname(cloudflared.bin), { - recursive: true, - }) - const tmp = `${cloudflared.bin}.tmp`; - rmSync(tmp, { + for (let i = 0; i <= version; i++) { + const cloudflareD = path.join(pluginVolume, 'cloudflare.d', `v${version}`); + rmSync(cloudflareD, { force: true, recursive: true, }); + } + if (process.platform === 'darwin' && process.arch === 'arm64') { + const bin = path.join(cloudflareD, cloudflared.bin); + mkdirSync(path.dirname(bin), { + recursive: true, + }); + const tmp = `${bin}.tmp`; + const stream = await axios('https://github.com/scryptedapp/cloudflared/releases/download/2023.8.2/cloudflared-darwin-arm64', { responseType: 'stream', }); - const write = stream.data.pipe(fs.createWriteStream(cloudflared.bin)); + const write = stream.data.pipe(fs.createWriteStream(tmp)); await once(write, 'close'); renameSync(tmp, cloudflared.bin); - fs.chmodSync(cloudflared.bin, 0o777) + fs.chmodSync(cloudflared.bin, 0o0755) } else { await cloudflared.install(cloudflared.bin); } } + process.chdir(cloudflareD); + const secureUrl = `https://127.0.0.1:${this.securePort}`; const args: any = {}; if (this.storageSettings.values.cloudflaredTunnelToken) {