Skip to content

Commit

Permalink
Merge pull request webosbrew#148 from throwaway96/minor-stuff-202307
Browse files Browse the repository at this point in the history
Minor stuff
  • Loading branch information
mariotaku authored Aug 17, 2023
2 parents e72b971 + 54ad059 commit bb70e9e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion services/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const asyncExecFile: (
) => Promise<string> = Bluebird.Promise.promisify(execFile);
export const asyncStat: (path: string) => Promise<fs.Stats> = Bluebird.Promise.promisify(fs.stat);
export const asyncUnlink: (path: string) => Promise<void> = Bluebird.Promise.promisify(fs.unlink);
export const asyncReadFile: (path: string, options?: any) => Promise<Buffer> = Bluebird.Promise.promisify(fs.readFile);
export const asyncReadFile: (path: string, options?: any) => Promise<Buffer | string> = Bluebird.Promise.promisify(fs.readFile);
export const asyncWriteFile: (path: string, contents: string, options?: fs.WriteFileOptions) => Promise<void> = Bluebird.Promise.promisify(
fs.writeFile,
);
Expand Down
6 changes: 4 additions & 2 deletions services/run-js-service
Original file line number Diff line number Diff line change
@@ -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')"
23 changes: 20 additions & 3 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ async function hashFile(filePath: string, algorithm: string): Promise<string> {
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.
*/
Expand Down Expand Up @@ -527,21 +536,29 @@ 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)
messages.push(`${startDevmode} has been manually modified!`);
}
}
} catch (err) {
console.log(`Startup script update failed: ${err.stack}`);
messages = ['Startup script update failed!', ...messages, `Error: ${err.toString()}`];
await createToast(messages.join('<br/>'), 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) {
Expand Down

0 comments on commit bb70e9e

Please sign in to comment.