mozz100 / tohora

A web UI for balenaDash
GNU General Public License v3.0
24 stars 7 forks source link

Passing the URL to a script #5

Closed rahul-thakoor closed 5 years ago

rahul-thakoor commented 5 years ago

Hey there! Thank you so much for this awesome tool.

I am trying to use it in combination with a bash script. The idea is to pass the URL to the script which then starts chromium.

It calls the script: Running '/home/chromium/launch.sh https://akirodic.com/p/jellyfish/' but, the script cannot find the argument. I think it should be called like this /home/chromium/launch.sh "<URL>". Any idea how I can solve this? Thanks

mozz100 commented 5 years ago

Hi Rahul

Good to hear of someone else using Tohora and balenaDash.

So I'm trying to understand you here. You're writing a script and you want to access the parameters (the URL)? I think inside your script you want to be using $1. See https://www.lifewire.com/pass-arguments-to-bash-script-2200571

Then, to pass the URL to tohora running on your balenaDash device, use curl. You'll need to make a POST request using -d and some data.

Does that help to point you on the right direction?

mozz100 commented 5 years ago

Here's an example curl command for when you get on to that part:

curl -d "url=http://example.com/your-url-here/" http://address.of.your.device:8080/launch/
rahul-thakoor commented 5 years ago

hey Richard Yes I am doing that but $1 is always empty for some reason :(

mozz100 commented 5 years ago

It sounds like your problem is in the realm of scripting, not tohora related. I'm keen to help you use tohora but I'm, well, I'm not an expert on bash/shell scripts. You might have better luck elsewhere trying to get the $1 issue solved. One approach I would suggest: break it down. Can you write a script that simply echos the first parameter back, like this?

$ cd /tmp
$ cat > myscript.sh
#!/bin/sh
echo $1
$ chmod +x myscript.sh
$ ./myscript.sh 'hello, world'
hello, world
rahul-thakoor commented 5 years ago

Thanks for getting back promptly Richard. Indeed, I already tested something like that. The thing is when I call it directly it works but when tohora calls the script with the URL it doesn't

Anyway, I will try to find a way. Thanks. Will keep you posted

mozz100 commented 5 years ago

Wait, I think I understand you now: so you're starting tohora and passing something other than WPELauncher? That ought to work, I think, if you start tohora like this: tohora 80 your_script.sh

Although I've never tested it that way. Possibly the way tohora starts a subprocess doesn't create a shell or something. (code is in https://github.com/mozz100/tohora/blob/master/subprocess/subprocess.go)

What do the logs say (the output of tohora)?

rahul-thakoor commented 5 years ago

I think that's the issue. I just checked, and I am getting this: fork/exec /home/chromium/launch.sh: permission denied

mozz100 commented 5 years ago

permission denied - you did make your script executable, right? chmod +x or similar

Please share your whole script and the exact steps you are following to obtain that message. Even then I'm not sure I'll be able to help, I'm afraid.

rahul-thakoor commented 5 years ago

It seems to work by adding - (make login shell) when starting chromium from the script

Thanks a lot, Richard! That was helpful

rahul-thakoor commented 5 years ago

I was doing this:

echo "chromium --kiosk --app=$1  --window-size=$WINDOW_SIZE --start-fullscreen" >> /home/chromium/xstart.sh

su -c 'startx /home/chromium/xstart.sh -- -nocursor' chromium

I changed the last line to : su -c 'startx /home/chromium/xstart.sh -- -nocursor' - chromium

Not entirely sure if that's what was causing the issue tbh. But it doesn't seem to be related to tohora, so im closing this. Sorry for the noise Richard