diff --git a/services/adapter.ts b/services/adapter.ts index 607f260..10d9bd9 100644 --- a/services/adapter.ts +++ b/services/adapter.ts @@ -34,7 +34,7 @@ export const asyncExecFile: ( ) => Promise = Bluebird.Promise.promisify(execFile); export const asyncStat: (path: string) => Promise = Bluebird.Promise.promisify(fs.stat); export const asyncUnlink: (path: string) => Promise = Bluebird.Promise.promisify(fs.unlink); -export const asyncReadFile: (path: string, options?: any) => Promise = Bluebird.Promise.promisify(fs.readFile); +export const asyncReadFile: (path: string, options?: any) => Promise = Bluebird.Promise.promisify(fs.readFile); export const asyncWriteFile: (path: string, contents: string, options?: fs.WriteFileOptions) => Promise = Bluebird.Promise.promisify( fs.writeFile, ); diff --git a/services/run-js-service b/services/run-js-service index 8b99578..bf9e84b 100755 --- a/services/run-js-service +++ b/services/run-js-service @@ -1,4 +1,6 @@ -#! /bin/sh +#!/bin/sh # :^) -eval "$(cat /usr/bin/run-js-service | sed 's/^thirdparty_jail=.*/thirdparty_jail=off/')" +eval "$(sed -e '/^thirdparty_jail=/s/=.*/=off/' \ + -e '\@/var/luna/preferences/devmode_enabled@s/if /&false \&\& /' \ + '/usr/bin/run-js-service')" diff --git a/services/service.ts b/services/service.ts index 06de645..b5e4757 100644 --- a/services/service.ts +++ b/services/service.ts @@ -99,6 +99,15 @@ async function hashFile(filePath: string, algorithm: string): Promise { return hash.read(); } +/** + * Hashes a string with specified algorithm. + * + * Input should be UTF-8. + */ +function hashString(data: string, algorithm: string): string { + return createHash(algorithm).update(data, 'utf-8').digest('hex'); +} + /** * Elevates a package by name. */ @@ -527,11 +536,18 @@ function runService() { // RootMyTV v1 if (await isFile(startDevmode)) { - const localChecksum = await hashFile(startDevmode, 'sha256'); + // Warn and return empty string on read error + const startDevmodeContents = (await asyncReadFile(startDevmode, { encoding: 'utf-8' }).catch((err) => { + console.warn(`reading ${startDevmode} failed: ${err.toString()}`); + return ''; + })) as string; + + const localChecksum = hashString(startDevmodeContents, 'sha256'); + if (localChecksum !== bundledStartupChecksum && updatableChecksums.indexOf(localChecksum) !== -1) { await copyScript(bundledStartup, startDevmode); messages.push(`${startDevmode} updated!`); - } else if (localChecksum !== bundledJumpstartChecksum && (await asyncReadFile(startDevmode)).indexOf('org.webosbrew') !== -1) { + } else if (localChecksum !== bundledJumpstartChecksum && startDevmodeContents.indexOf('org.webosbrew') !== -1) { // Show notification about mismatched startup script if contains // org.webosbrew string (which is not used on jumpstart.sh nor // official start-devmode.sh) @@ -539,9 +555,10 @@ function runService() { } } } catch (err) { + console.log(`Startup script update failed: ${err.stack}`); messages = ['Startup script update failed!', ...messages, `Error: ${err.toString()}`]; await createToast(messages.join('
'), service); - return { returnValue: false, statusText: 'Startup script update failed.', messages }; + return { returnValue: false, statusText: 'Startup script update failed.', stack: err.stack, messages }; } if (messages.length) {