Lynx Browser Launch Script

I’m trying to write a script that will exit Kodi, launch Lynx and then restart Kodi after Lynx exits. I can get Kodi to exit, but it just sits at a black screen and Lynx never starts. I was hoping someone here may have some insight. My script is as follows:

#!/bin/bash

kodi-send --action="Notification(Lynx,Launching Lynx Web Browser,4000,/home/osmc/.kodi/addons/script.lynxlauncher/logo.png)"
sleep 2
sudo systemctl stop mediacenter
sleep 5
lynx http://www.google.com
sudo systemctl start mediacenter

Use my scripts and adapt them to launch your program. :wink:

Edit: The problem is, that kodi cannot start a program after it gets closed down.
You need to run the program detached from the kodi shell.

Another way of doing this is to write a script (in bash, python or whatever you fancy) that runs in the background, wakes up every 5 seconds (or whatever) and starts Kodi or Lynx alternately if neither is running. The logic would be something like:

kodi_started_last_time = false
do
    if neither kodi nor lynx is running (check using ps | grep)
    then
        if kodi_started_last_time
        then
            start lynx (detached)
            kodi_started_last_time = false
        else
            start kodi (detached)
            kodi_started_last_time = true
        fi
    fi
    sleep 5
repeat

Then, when you exit Kodi, Lynx starts; when you exit Lynx, Kodi starts, and so on.

This would limit you to one application though. And you will always need to have this running via autostart.

Thanks to both of you for your suggestions. I’ve now gotten Lynx to launch and present itself using the script below, but it creates three problems as a result:

  • Lynx is confined to a small square in the top left of the screen.
  • I can’t pass any variables to Lynx such as -center.
  • When Lynx is either quit or interrupted, everything freezes and input of any kind is not allowed.
#!/bin/bash

# display notification

kodi-send --action="Notification(Lynx,Launching Lynx Web Browser,4000,/home/osmc/.kodi/addons/script.lynxlauncher/logo.png)"

#clear the virtaul terminal 7 screen

sudo openvt -c 7 -s -f clear

# start lynx launch script on vitrual terminal 7 and detach it

sudo su osmc -c "nohup openvt -c 7 -f -s lynx >/dev/null 2>&1 &" &

# clear the screen again

sudo openvt -c 7 -s -f clear

# wait to make sure lynx is running detached from kodi

sleep 0.5

# stop kodi to reveal lynx

sudo su -c "systemctl stop mediacenter &" &

exit

Probably best not to do that.

You probably want

sudo systemctl start getty@tty1.service
chvt 1

instead.

Edit: don’t start Lynx after Kodi dies, as there is some Getty handling there in our watchdog. Best to have a systemd unit that stops Kodi (ExecStartPre), then starts Lynx, and then it will manage the application running in context better. Then you can also have only one command sudo systemctl start lynx for invocation.

That’s why you need the watchdogscript, that restarts kodi if lynx quits.

Also, you don’t seem to pass arguments to lynx in the script. Why not? It should work.

I think that you cannot invoke a script from kodi, that first kills kodi, then starts another program as it will die if kodi stops.
I did a lot of experiments on this when doing retrosmc and openvt seemed the only way as it runs the other script detached from the kodi tty before stopping kodi.

Not sure if that is true for systemd services though

You can make a systemd service
sudo systemctl start xyz

That systemd unit can stop the mediacenter unit, and start it again when it is stopped itself.

As pid1 will be controlling stopping and starting of applications, both Kodi and Lynx can die at any point as they are not dealing with it.

I really do appreciate all the input. It seems like I’ve disappeared, but I’m trying my hand at all the suggestions given. I’m learning a lot about all this as I go and I assumed it would come easier than it has. However, anything worth doing is worth learning. Once completed, this will be used to authenticate Wifi connections at hotels and the like, so it will definitely come in handy when traveling or spending any extended time at a hospital.

With all of your suggestions and the help of Joakim_Sandstrom, this addon is now fully operational. I didn’t ignore any of the ideas shared, it’s just that some are over my head at the moment. However, I am learning, so I hope that I might look at all this again in the future and see everything with greater clarity.

As I mentioned earlier, This will be used primarily to allow Wifi authentication at hotels and the like. Calling a hotel’s technical department can be unreliable at best and using a tethered connection from a phone presents it’s own share of problems for any extended period of time.

For anyone interested, the final scripts are below:

1.sh:

#!/bin/bash
kodi-send --action="Notification(Lynx,Launching Lynx Web Browser,4000,/home/osmc/.kodi/addons/script.lynxlauncher/logo.png)"
sleep 0.5
sudo openvt -c 7 -s -f clear
sudo su osmc -c "nohup openvt -c 7 -f -s /home/osmc/.kodi/addons/script.lynxlauncher/2.sh >/dev/null 2>&1 &" &
sudo su -c "systemctl stop mediacenter &" &
exit

2.sh:

#!/bin/bash
sleep 30
sudo openvt -c 7 -s -f -w -- su osmc -c "lynx -accept_all_cookies http://www.google.com"
sudo openvt -c 7 -s -f clear
sudo systemctl start mediacenter
exit

Thanks again to everyone for all the help.