webosbrew / webos-homebrew-channel

Unofficial webOS TV homebrew store and root-related tooling
MIT License
839 stars 44 forks source link

webOS <4.0 doesn't run startup.sh, hence no SSH or Telnet #124

Open kopiro opened 1 year ago

kopiro commented 1 year ago

I had a working version of Homebrew until I decided to upgrade to 05.50 system software, now webOS 4.4.2 (from 05.40).

The initial symptoms after upgrading are that SSH server is not working, Telnet is not working and also PicCap doesn't auto-start - but I still have elevated privileges.

After some debugging, it looks like that the autostart service registered by Homebrew is not being called; hence no startup.sh called.

I built a companion app that tries to call the autostart service via LunaBus; once installed, you can see that the first call to the autostart services fails because of a LunaBus error - but trying again it works.

image

Our assumption is that probably the service doesn't get registered in time or there are some overloads of the LunaBus at startup.

The error we get from LunaBus is this: https://github.com/webosose/luna-service2/blob/master/src/libluna-service2/transport.c#L239


Most likely, this new method of using previewMetadata in the appinfo.json doesn't work on webOS 4+, and the startup method was working in the previous firmware because of the presence of /etc/wam/plugins/conf.sh that called our script in the $EXTRA_CONF path:

EXTRA_CONF=/mnt/lg/cmn_data/wam/extra_conf.sh

if test -f $EXTRA_CONF; then
    source $EXTRA_CONF;
fi

That has now been removed from the 4.4 firmware.

kopiro commented 1 year ago

In my case, I've a running Homebrew + startup with the companion app I built myself and managed to manually run the startup.sh script and everything works correctly, but U guess we ned to find a new way to run services at startup.

mariotaku commented 1 year ago

Hi, I think the previewMetadata was working on webOS 4 and above. Did it stop working recently?

kopiro commented 1 year ago

It doesn't work for me on webOs 4.4 - and most likely not working before?

mariotaku commented 1 year ago

I was using webOS 4.9 and 5.3 and it worked. Could you install Netflix and see if there are suggestions when you focus the icon?

kopiro commented 1 year ago

Nope, no suggestions.

Also, the Netflix ipk I inspected installed on the TV doesn't have any previewMetadata attribute.

I did a grep search and none of the package appinfo.json have it.

This is a TV from 2018, LG B8 running latest software with webos 4.4

image

kopiro commented 1 year ago

It may be possible that with webOS4.4 we are stick in a limbo where none of the previous startup method works (extra_conf.sh or start_devmode.sh) as they patched this but the firmware is too old to support new features like the previewMetadata.

Also, what I've noticed after some usage is that Homebrew stops working and all INSTALL options are greyed-out.

After some digging I found out that's because the LunaBus stop being responsive, causing no luna-message to be dispatched (by looking at ls-monitor).

mariotaku commented 1 year ago

That's really unfortunate. I think in such case only crashd method is available (if they are still working).

kopiro commented 1 year ago

Isn't crashd method only to gain root?

mariotaku commented 1 year ago

IIRC if the file is there it will always work.

fryc88 commented 1 year ago

I'm on same boat with kopiro, with SK8500PLA, MY2018 tv, with webos 4.4 as well. Looks like i have same issues with doing root, with help of hellobox on discord i've managed to get kopiros ipk working on my tv because even that didn't work for me at the beggining, it was just showing some weird output, but hellobox suggested to do some magic, and after that i've got it. However now, after starting up tv, few minutes later homebrew ipk stop working, root status becomes pending and i can't launch/install new apps. After power cycle it does work for few minutes and then back on that again.

CoreyD97 commented 1 year ago

Similar boat to @kopiro and @fryc88 here. Managed to crashd my way to root, but autostart isn't working for me. I tried installing https://github.com/kopiro/webosbrew-autostart, but that encounters errors when running the autostart service as luna-send -n 1 'luna://org.webosbrew.hbchannel.service/autostart' '{}' gives the error {"returnValue":false,"errorText":"undefined is not a function"}.

Unlike @kopiro though, I do seem to get suggestions when hovering over home icons like Netflix as suggested earlier ( https://github.com/webosbrew/webos-homebrew-channel/issues/124#issuecomment-1296841694)

HagiaHaya commented 1 year ago

If you can't access the telnet via homebrew app, add this repo https://repo.webosapp.club -> install root.telnet and connect normally.

kopiro commented 1 year ago

@mariotaku yes, the file is there and you can get root - but no startup scripts.

soeren-a commented 1 year ago

I'm facing the exact same issue. Successfully rooted via crashd, PicCap and Hyperion are working as expected but only if I start the apps manually after TV start. Autostart is just not working, even though the option is enabled for both services. Telnet and SSH are also not working. Using webOS 5.50.10, and HomeBrew 0.5.1 on a OLED55B8LLA. Any chance that the issue will be fixed?

throwaway96 commented 1 year ago

It's not something that can really be "fixed", since webOS 4.[0-4] is missing the feature we're currently using for autostart functionality. There are other ways of hooking into the boot process, but only for newer versions of webOS. The next version of Homebrew Channel will try to work around this to a limited extent by running startup.sh when the app is launched.

If anyone wants to look for new boot hooks, it would be greatly appreciated.

kopiro commented 1 year ago

Hello; I'll share the solution that works for me.

The main problem with not having autostart so far is only that PicCap and Hyperion/HDR don't start automatically, hence no LEDs.

What you only need is a device that is always on in your network - example: a raspberry Pi.

Generic solution

Install https://github.com/merdok/homebridge-webos-tv using npm -g install homebridge-webos-tv - I't s a plugin for homebridge that also has a nice CLI tool (/usr/bin/webostv) you can use.

I recently added support for sending raw luna-messages, we're going to use that.

Create a binary on your system with the following (example: /usr/local/bin/tv-autostart)

#!/bin/sh
TV_IP=192.168.0.40
TV_MAC=AA-BB-CC-DD-EE-FF
if ! ping $TV_IP; then 
  echo "TV is off"
  exit 1
fi
if curl -s "http://$TV_IP:8090/json-rpc?request=%7B%22command%22:%22serverinfo%22%7D"; then 
  echo "TV already rooted"
  exit 2
fi
echo "Calling autostart"
webostv luna-message $TV_IP $TV_MAC luna://org.webosbrew.hbchannel.service/autostart '{}'

And of course chmod +x /usr/local/bin/tv-autostart

Now, what you're going to do with this binary is really up to you.

Solution 0: Call this script in a CRON

Well, simply enough, setup a CRON that calls /usr/local/bin/tv-autostart every minute.

Solution 1: Use HomeBridge create a switch that you can use when you want to switch LEDs on/off

Since I don't always want the LEDs on (especially during daylight), I've setup a switch using in HomeKit so that I can just say "Hey Siri, switch on TV LEDs" or use the Homekit app in order to switch them on-off.

The script i'm using is a bit more complex than the one above, since it's also controlling HyperHDR status on/off - you can find it here and put it in /usr/local/bin/tv-hyperhdr

Then, install the plugin "homebridge-cmdswitch2" and add the following:

 {
    "platform": "cmdSwitch2",
    "name": "homebridge-cmdswitch2",
    "switches": [
        {
            "name": "TV LED",
            "on_cmd": "/usr/local/bin/tv-hyperhdr on",
            "off_cmd": "/usr/local/bin/tv-hyperhdr off",
            "state_cmd": "/usr/local/bin/tv-hyperhdr status",
            "polling": true,
            "interval": 30,
            "timeout": 15,
            "manufacturer": "HyperHDR"
        }
    ]
}

Now that you have this switch, you can leave it there to manually call it, or, for example, you can configure it to run when TV get switched on, if you also have the TV in HomeKit.

soeren-a commented 1 year ago

The luna://org.webosbrew.hbchannel.service/autostart '{}' call kills my Homebrew Channel app. After executing the command, I cannot install any apps from the Channel and the root status under"Settings" is shown as "pending". It is "fixed" again after a restart if the TV was completely shut down. But I can confirm that executing the command fixes the autostart and SSH issue for my TV.

kopiro commented 1 year ago

Hello - I can confirm you that this behaviour is "everything is locked" happened to me as well, but not because of the luna message you just sent.

It may be that the luna bus is a bit buggy with this webOS version, and messages don't get delivered - therefore, also the "install app" message is not delivered, or the "get root status" message is never delivered and is always shown as pending.

I'm not sure if this is a specific webOS issue or a problem with the homebrew service itself (with this version). - perhaps @Informatic knows more :)

soeren-a commented 1 year ago

As a workaround for anyone that uses the LG integration within Home Assistant: I created a script that executes the command suggested by @kopiro, which can be used in an automation (e.g. on TV start):

alias: Enable app autostart on rooted LG TV
sequence:
  - service: webostv.command
    data:
      entity_id: media_player.lg_tv
      command: system.notifications/createAlert
      payload:
        message: Executing HB Channel autostart...
        modal: false
        buttons:
          - label: OK
            focus: true
            buttonType: ok
            onClick: luna://org.webosbrew.hbchannel.service/autostart
            params: {}
        type: confirm
        isSysReq: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
    alias: Delay for Button click to close the alert toast
  - service: webostv.button
    data:
      entity_id: media_player.lg_tv
      button: ENTER
mode: single
icon: mdi:television-ambient-light
panic175 commented 1 year ago

My workaround also uses Home Assistant but with a custom component: https://github.com/panic175/webosbrew-autostart-helper

popy2k14 commented 1 year ago

@panic175 tried your custom integration, sadly it doesn't work. The first time the remote control Dialog was presented on the tv. I clicked yes and nothing happens. Also she i run the custom component service again.

When I'll open HBC autostart apps will be launched. So my setup works, except autostart .

Any hints i can debug this?

panic175 commented 1 year ago

@popy2k14 Do you see any errors from the custom component in your Home Assistant Logs?

popy2k14 commented 1 year ago

@panic175 sorry for hijacking your thread. I have webOS 6.3.1-411 (kisscurl-kinglake). In my case i had to uncheck all EULAs and retry (incl. reboot) until they are unchecked (two times in my case). Then enabled the TOP one and autostart is working again.

Just if anybody like me has this issue and needs this information. I am in conact with the https://gist.github.com/throwaway96/e811b0f7cc2a705a5a476a8dfa45e09f owner, so maybe this info get's also added there.

thx again

kitsuned commented 1 year ago

hi there!

I think I found a way:

luna-send -f -n 1 -m org.webosbrew.hbchannel.service luna://com.webos.service.activitymanager/create '{
 "activity": {
  "name": "org.webosbrew.hbchannel.service.autostart",
  "description": "who cares",
  "type": {
   "foreground": true,
   "persist": true, 
   "continuous": true
  },
  "trigger": {
   "method": "luna://com.webos.bootManager/getBootStatus",
   "params": {
    "subscribe": true
   },
   "where": {
    "prop": [
     "signals",
     "core-boot-done"
    ],
    "op": "=",
    "val": true
   }
  },
  "callback": {
   "method": "luna://org.webosbrew.hbchannel.service/autostart",
   "params": {}
  }
 },
 "replace": true,
 "start": true
}'

I haven't tested this on 4.4. I would be glad to receive any feedback!

Doridian commented 1 year ago

hi there!

I think I found a way:

luna-send -f -n 1 -a org.webosbrew.hbchannel.service luna://com.webos.service.activitymanager/create '{
......
}'

I haven't tested this on 4.4. I would be glad to receive any feedback!

On my webOS TV (version 4.4.2), this above worked perfectly, I could finally disable my HomeAssistant automation :D

kitsuned commented 1 year ago

On my webOS TV (version 4.4.2), this above worked perfectly, I could finally disable my HomeAssistant automation :D

that was quick! thank you for the feedback.

follow #143 👀

Chaoscontrol commented 11 months ago

As a workaround for anyone that uses the LG integration within Home Assistant: I created a script that executes the command suggested by @kopiro, which can be used in an automation (e.g. on TV start):

alias: Enable app autostart on rooted LG TV
sequence:
  - service: webostv.command
    data:
      entity_id: media_player.lg_tv
      command: system.notifications/createAlert
      payload:
        message: Executing HB Channel autostart...
        modal: false
        buttons:
          - label: OK
            focus: true
            buttonType: ok
            onClick: luna://org.webosbrew.hbchannel.service/autostart
            params: {}
        type: confirm
        isSysReq: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
    alias: Delay for Button click to close the alert toast
  - service: webostv.button
    data:
      entity_id: media_player.lg_tv
      button: ENTER
mode: single
icon: mdi:television-ambient-light

Massive thanks for this. It helped me find the syntax needed to run the PicCap service directly from Home Assistant, as it doesn't autorun in my webOS 3.4.0. Might be that the createAlert method doesn't exist in that version?

However, your script doesn't work for me. The button step works, but the toast alert doesn't appear at any time. Any idea why?

[21:14:25.594][INFO] com.webos.service.secondscreen.gateway SSG_PERM Failed to find permissions for ssap://system.notifications/createAlert: Error: method /createAlert not found in interface system.notifications {}

soeren-a commented 11 months ago

Hmm, yes, it seems that the method is not found on your OS. But the error message also indicates, that you do not have the right permissions to execute? Not sure what's the issue here. All available methods are listed here, but without OS version support information: https://github.com/bendavid/aiopylgtv/blob/master/aiopylgtv/endpoints.py

Chaoscontrol commented 11 months ago

@soeren-a Yeah, I have been checking that and testing all I can think of. But can't make it work. createToast works fine, but createAlert doesn't.

Isn't there any other way to send the command to start SSH from HA?

soeren-a commented 11 months ago

@soeren-a Yeah, I have been checking that and testing all I can think of. But can't make it work. createToast works fine, but createAlert doesn't.

Isn't there any other way to send the command to start SSH from HA?

Not that I'm aware of. As far as I know, a user interaction like a button click is needed to execute the call. Showing a toast with a button and click it was the easiest way to achieve that.

TulipVang commented 10 months ago

In my case, I've a running Homebrew + startup with the companion app I built myself and managed to manually run the startup.sh script and everything works correctly, but U guess we ned to find a new way to run services at startup.

I face same issue. Can you help me to manually run the startup.sh script please.

throwaway96 commented 10 months ago

@TulipVang

Opening recent versions of Homebrew Channel will execute startup.sh.

swiss6th commented 8 months ago

I haven't tested this on 4.4. I would be glad to receive any feedback!

@kitsuned, I have a C8 on 4.4.2, and this solved the issue for me as well. startup.sh is now running, and the autostart of PicCap and HyperHDR are both working now.

Dahman97 commented 8 months ago

I haven't tested this on 4.4. I would be glad to receive any feedback!

I would like to thank you for your solution as it worked like a charm, after reboot everything that is supposed to auto start runs as it should, including hyperhdr and picap.... WebOS V-4.4-x. thanks a lot dude! TV model from 2019 updated to last webOS available for its gen :)

dancingmadkefka commented 7 months ago

@TulipVang

Opening recent versions of Homebrew Channel will execute startup.sh.

Hey thanks a lot, I was struggling all day to try to ssh into my B8 running 4.4.2 and this advice helped. I ran the homebrew updater and when I rebooted it popped up with a message saying that "autostart.sh has been updated" or something. Once that happened, I was able to ssh into it. Also handy that the updater allows you to open an emergency telnet session".

rmp63526 commented 6 months ago

@kitsuned It also worked for my Oled TV, WebOs 4.4.2-11 Goldilocks - Gorongosa/ Softwareversion 05.50.15 I have only noticed that when I switch off the TV, wait 1 minute and then unplug it and switch it on again, it goes into failsafe mode the first time it starts. When I restart it, it works again.

kopiro commented 3 months ago

It looks like that https://github.com/webosbrew/webos-homebrew-channel/commit/804f947796b9e05f1f55f872f4fe1188a9b2cf05 fixed this - we can close this issue!

throwaway96 commented 3 months ago

It's not fixed on webOS <4.0.

kopiro commented 3 months ago

Sorry! :)

angyp commented 2 months ago

I would like to get this going on OLED65C7T-T Firmware version 06.10.30 webOS version 3.9.0 Used DejaVuln The only way I can get it to run is to open the homebrew app.

angyp commented 2 months ago

hi there!

I think I found a way:

luna-send -f -n 1 -m org.webosbrew.hbchannel.service luna://com.webos.service.activitymanager/create '{
 "activity": {
  "name": "org.webosbrew.hbchannel.service.autostart",
  "description": "who cares",
  "type": {
   "foreground": true,
   "persist": true, 
   "continuous": true
  },
  "trigger": {
   "method": "luna://com.webos.bootManager/getBootStatus",
   "params": {
    "subscribe": true
   },
   "where": {
    "prop": [
     "signals",
     "core-boot-done"
    ],
    "op": "=",
    "val": true
   }
  },
  "callback": {
   "method": "luna://org.webosbrew.hbchannel.service/autostart",
   "params": {}
  }
 },
 "replace": true,
 "start": true
}'

I haven't tested this on 4.4. I would be glad to receive any feedback!

How do I use this? Auto start doesn't work on my TV

lsahnicne commented 3 weeks ago

hi there!

I think I found a way:

luna-send -f -n 1 -m org.webosbrew.hbchannel.service luna://com.webos.service.activitymanager/create '{
 "activity": {
  "name": "org.webosbrew.hbchannel.service.autostart",
  "description": "who cares",
  "type": {
   "foreground": true,
   "persist": true, 
   "continuous": true
  },
  "trigger": {
   "method": "luna://com.webos.bootManager/getBootStatus",
   "params": {
    "subscribe": true
   },
   "where": {
    "prop": [
     "signals",
     "core-boot-done"
    ],
    "op": "=",
    "val": true
   }
  },
  "callback": {
   "method": "luna://org.webosbrew.hbchannel.service/autostart",
   "params": {}
  }
 },
 "replace": true,
 "start": true
}'

I haven't tested this on 4.4. I would be glad to receive any feedback!

It seems to take a few moments after turning the TV on to initialize (judging by lginputhook key binds activation), but ultimately works. Thanks! LG OLED C2 webOS 7.2.0-47 (mullet-marine) 03.21.45 Homebrew channel 0.6.3

How do I use this? Auto start doesn't work on my TV

SSH into TV and execute the code

angyp commented 3 weeks ago

I tried that and it didn't work on my OLED C7 so I thought I was doing it wrong. Seems no way to get autostart working on my TV. Everything starts working correctly after I open the Homebrew channel.