Skip to content

Commit

Permalink
Autostart Fallback for webOS 4+ (#102)
Browse files Browse the repository at this point in the history
* adding discovery endpoint

* updated startup

* changed autostart endpoint name

* installs startup.sh if not present
  • Loading branch information
mariotaku authored Jul 2, 2022
1 parent b62e395 commit 3e970df
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 5 additions & 1 deletion appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"main": "index.html",
"iconColor": "#cf0652",
"type": "web",
"appDescription": "webOS Homebrew installer"
"appDescription": "webOS Homebrew installer",
"previewMetadata": {
"targetEndpoint": "luna://org.webosbrew.hbchannel.service/autostart",
"sourceEndpoint": "@PREVIEW.ENDPOINT.SOURCE_LOCAL_STOREAPP"
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"description": "Manual installation:",
"main": "frontend/index.js",
"moduleDir": "frontend",
"os": [
"!win32"
],
"scripts": {
"build": "enyo pack",
"build-service": "webpack",
Expand Down
34 changes: 34 additions & 0 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,40 @@ function runService() {
isTimeLimited: false,
})),
);

service.register(
'autostart',
tryRespond(async () => {
if (!runningAsRoot()) {
return { message: 'Not running as root.', returnValue: true };
}
if (fs.existsSync('/tmp/webosbrew_startup')) {
return { message: 'Startup script already executed.', returnValue: true };
}
// Copy startup.sh if doesn't exist
if (!fs.existsSync('/var/lib/webosbrew/startup.sh')) {
try {
fs.mkdirSync('/var/lib/webosbrew/', { mode: 0o755 });
} catch (e) {
// Ignore
}
fs.copyFileSync(path.join(__dirname, 'startup.sh'), '/var/lib/webosbrew/startup.sh');
}
// Make startup.sh executable
try {
fs.accessSync('/var/lib/webosbrew/startup.sh', fs.constants.X_OK);
} catch (e) {
fs.chmodSync('/var/lib/webosbrew/startup.sh', 0o755);
}
child_process.spawn('/bin/sh', ['-c', '/var/lib/webosbrew/startup.sh'], {
cwd: '/home/root',
env: { LD_PRELOAD: '' },
detached: true,
stdio: ['ignore', 'ignore', 'ignore'],
});
return { returnValue: true };
}),
);
}

if (process.argv[2] === 'self-update') {
Expand Down

1 comment on commit 3e970df

@kopiro
Copy link
Contributor

@kopiro kopiro commented on 3e970df Oct 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this issue @mariotaku - #124
Just wondering if this way of autostart also works for webOS 4 or only 4+ ?

Please sign in to comment.