Skip to content

Commit

Permalink
Merge pull request webosbrew#150 from throwaway96/relative-path-202308
Browse files Browse the repository at this point in the history
Make some paths relative
  • Loading branch information
mariotaku authored Aug 17, 2023
2 parents 335e4c3 + 8b056a7 commit e72b971
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
18 changes: 12 additions & 6 deletions services/elevate-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import { statSync, readFileSync, writeFileSync } from 'fs';
import { existsSync, statSync, readFileSync, writeFileSync } from 'fs';
import { execFile } from 'child_process';
import { dirname } from 'path';
import { dirname, resolve } from 'path';

process.env.PATH = `/usr/sbin:${process.env.PATH}`;

Expand All @@ -28,10 +28,16 @@ function patchServiceFile(serviceFile: string): boolean {

if (serviceFileNew.indexOf('/run-js-service') !== -1) {
console.info(`[ ] ${serviceFile} is a JS service`);
serviceFileNew = serviceFileNew.replace(
/^Exec=\/usr\/bin\/run-js-service/gm,
'Exec=/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/run-js-service',
);

// run-js-service should be in the same directory as this script.
const runJsServicePath = resolve(__dirname, 'run-js-service');

if (!existsSync(runJsServicePath)) {
console.error(`[!] run-js-service does not exist at ${runJsServicePath}`);
return false;
}

serviceFileNew = serviceFileNew.replace(/^Exec=\/usr\/bin\/run-js-service/gm, `Exec=${runJsServicePath}`);
} else if (serviceFileNew.indexOf('/jailer') !== -1) {
console.info(`[ ] ${serviceFile} is a native service`);
serviceFileNew = serviceFileNew.replace(/^Exec=\/usr\/bin\/jailer .* ([^ ]*)$/gm, (match, binaryPath) => `Exec=${binaryPath}`);
Expand Down
2 changes: 2 additions & 0 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ function runService() {
'5caab3681cdd52cc9b59136a180cd0a1ffb98ec39bf571c38c0a4eb528ce13fb',
'befe927c6f62b87545aaefb4b2648a227b22695fa0f78a228dcacf1fbba11aeb',
'd914b3b444433bf49ff83c3c0ae0b729cf7544c074e72c23ec24e5f86aaaf4ac',
'6215795aed50c11bb7be716cf66326f3657a129143b5edc1b635dab8b8d2fc9f',
];

// RootMyTV v2
Expand Down Expand Up @@ -659,6 +660,7 @@ function runService() {
env: {
LD_PRELOAD: '',
SKIP_ELEVATION: 'true',
SERVICE_DIR: __dirname,
},
detached: true,
stdio: ['ignore', 'ignore', 'ignore'],
Expand Down
10 changes: 7 additions & 3 deletions services/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ fi

touch "${once}"

# Use default directory if SERVICE_DIR is not provided.
SERVICE_DIR="${SERVICE_DIR-/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service}"

if [[ -f /var/luna/preferences/webosbrew_failsafe ]]; then
# In case a reboot occured during last startup - open an emergency telnet
# server and nag user to actually fix this. (since further reboots could
Expand Down Expand Up @@ -73,7 +76,7 @@ else
# Start sshd
if [[ -e /var/luna/preferences/webosbrew_sshd_enabled ]]; then
mkdir -p /var/lib/webosbrew/sshd
/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin/dropbear -R 200>&-
"${SERVICE_DIR}/bin/dropbear" -R 200>&-
fi

printf "\033[1;91mNEVER EVER OVERWRITE SYSTEM PARTITIONS LIKE KERNEL, ROOTFS, TVSERVICE.\nYour TV will be bricked, guaranteed! See https://rootmy.tv/warning for more info.\033[0m\n" > /tmp/motd
Expand Down Expand Up @@ -122,8 +125,9 @@ else
fi

# Automatically elevate Homebrew Channel service
if [[ -z "${SKIP_ELEVATION}" && -x /media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service ]]; then
/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/elevate-service
elevate_script="${SERVICE_DIR}/elevate-service"
if [[ -z "${SKIP_ELEVATION}" && -x "${elevate_script}" ]]; then
"${elevate_script}"
fi

# Run user startup hooks
Expand Down

0 comments on commit e72b971

Please sign in to comment.