Skip to content

Commit

Permalink
services: ensure startup script permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Informatic committed Feb 22, 2022
1 parent 4d3667e commit f5cb496
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions services/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ export const asyncReadFile: (path: string, options?: any) => Promise<Buffer> = B
export const asyncWriteFile: (path: string, contents: string, options?: fs.WriteFileOptions) => Promise<void> = Bluebird.Promise.promisify(
fs.writeFile,
);
export const asyncChmod: (path: string, mode: fs.Mode) => Promise<void> = Bluebird.Promise.promisify(fs.chmod);
11 changes: 6 additions & 5 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Promise } from 'bluebird';
import progress from 'progress-stream';
import Service, { Message } from 'webos-service';
import fetch from 'node-fetch';
import { asyncStat, asyncExecFile, asyncPipeline, asyncUnlink, asyncWriteFile, asyncReadFile } from './adapter';
import { asyncStat, asyncExecFile, asyncPipeline, asyncUnlink, asyncWriteFile, asyncReadFile, asyncChmod } from './adapter';

import rootAppInfo from '../appinfo.json';
import serviceInfo from './services.json';
Expand Down Expand Up @@ -68,12 +68,13 @@ async function isFile(targetPath: string): Promise<boolean> {
/**
* Copies a file
*/
async function copyFile(sourcePath: string, targetPath: string) {
async function copyScript(sourcePath: string, targetPath: string) {
if (!(await isFile(sourcePath))) {
throw new Error(`${sourcePath} is not a file`);
}

await asyncPipeline(fs.createReadStream(sourcePath), fs.createWriteStream(targetPath));
await asyncChmod(targetPath, 0o755);
}

/**
Expand Down Expand Up @@ -390,7 +391,7 @@ function runService() {
const localChecksum = await hashFile(webosbrewStartup, 'sha256');
if (localChecksum !== bundledStartupChecksum) {
if (updateableChecksums.indexOf(localChecksum) !== -1) {
await copyFile(bundledStartup, webosbrewStartup);
await copyScript(bundledStartup, webosbrewStartup);
messages.push(`${webosbrewStartup} updated!`);
} else {
// Show notification about mismatched startup script
Expand All @@ -405,7 +406,7 @@ function runService() {
(await isFile(startDevmode)) &&
(await hashFile(startDevmode, 'sha256')) === '98bf599e3787cc4de949d2e7831308379b8f93a6deacf93887aeed15d5a0317e'
) {
await copyFile(bundledJumpstart, startDevmode);
await copyScript(bundledJumpstart, startDevmode);
messages.push(`${startDevmode} updated!`);
}
}
Expand All @@ -414,7 +415,7 @@ function runService() {
if (await isFile(startDevmode)) {
const localChecksum = await hashFile(startDevmode, 'sha256');
if (localChecksum !== bundledStartupChecksum && updateableChecksums.indexOf(localChecksum) !== -1) {
await copyFile(bundledStartup, startDevmode);
await copyScript(bundledStartup, startDevmode);
messages.push(`${startDevmode} updated!`);
} else if (localChecksum !== bundledJumpstartChecksum && (await asyncReadFile(startDevmode)).indexOf('org.webosbrew') !== -1) {
// Show notification about mismatched startup script if contains
Expand Down

0 comments on commit f5cb496

Please sign in to comment.