PDA

View Full Version : Script help



Darmeth
24-06-17, 19:30
Putting together an auto-grab script for e2 settings. It works, but a couple of issues. I welcome any help and suggestions please.

1. Runs fine via telnet but no changes are seen on the box. I've "stepped through" on telnet and files are definately being delivered.
2. Various errors when uploaded to /usr/scripts (thought it was to go in /usr/scrpt but when added there, it does not appear on the menu Vix > Script Runner??)

Just ran from the box and it managed to clear my tuner setting! Nice! :eek:




#!/bin/sh
# Darmeth 24-June-2017
# Version 1.0
rm -f -r /etc/enigma2/blacklist /etc/enigma2/lamedb /etc/enigma2/satellites.xml
rm -f -r /etc/tuxbox/satellites.xml /etc/enigma2/whitelist /etc/enigma2/*.tv /etc/enigma2/*.radio
rm -f -r /etc/enigma2/cables.xml /etc/enigma2/terrestrial.xml
wget 'http://www.darmeth.com/downloads/Darmeth_Motor_NA_45E-30W.rar' -O '/tmp/Darmeth_Motor_NA_45E-30W.rar' > /dev/null
unrar e -o+ '/tmp/Darmeth_Motor_NA_45E-30W.rar' '/etc/enigma2/'
mv -f /etc/enigma2/satellites.xml /etc/tuxbox
rm -rf /tmp/Darmeth_Motor_NA_45E-30W.rar > /dev/null
wget -qO - hxxp://127.0.0.1/web/servicelistreload?mode=0
sleep 3
#wget -O /dev/null -q http://127.0.0.1/web/powerstate?newstate=3
echo 'Darmeth Motor No Adult 45E-30W - UPDATED'
exit 0

abu baniaz
24-06-17, 19:40
usr/scripts not usr/script

Your tuner config is not working maybe because there is an issue with the satellites.xml file. You should consider leaving it out of operations as the one in image gets updated regularly on updates.
If you decide to use it, leave it in etc/enigma2/


I don't think we have unrar in image. gzip is there.

abu baniaz
24-06-17, 19:51
You should use "unzip"

PS. You have a PM.

Darmeth
24-06-17, 22:54
Thanks abu baniaz. Modified a bit and using unzip but getting an error:

"zip flags 1 and 8 are not supported"

You're 100% correct on unrar not in image; I installed using command "opkg install unrar"

abu baniaz
25-06-17, 00:18
Try this until someone suggests something better. You may need to alter the way you pack/compress the files.



#!/bin/sh
# Darmeth 25-June-2017
# Version 1.1

echo 'Removing old services'
rm -rf /etc/enigma2/blacklist
rm -rf /etc/enigma2/whitelist
rm -rf /etc/enigma2/*.tv
rm -rf /etc/enigma2/*.radio
rm -rf /etc/enigma2/lamedb
sleep 1
echo 'obtaining new files'
wget http://www.darmeth.com/downloads/Darmeth_Motor_NA_45E-30W.zip -O /tmp/Darmeth_Motor_NA_45E-30W.zip > /dev/null
echo 'updating files....'
unzip -o /tmp/Darmeth_Motor_NA_45E-30W.zip -d /etc/enigma2 > /dev/null
wget -qO - http://127.0.0.1/web/servicelistreload?mode=0 > /dev/null
echo 'removing temp files....'
rm -rf /tmp/Darmeth_Motor_NA_45E-30W.zip > /dev/null
sleep 3
echo 'Darmeth Motor No Adult 45E-30W - UPDATED'
exit 0

birdman
25-06-17, 01:22
rm -f -r /etc/enigma2/blacklist /etc/enigma2/lamedb /etc/enigma2/satellites.xml
rm -f -r /etc/tuxbox/satellites.xml /etc/enigma2/whitelist /etc/enigma2/*.tv /etc/enigma2/*.radio
rm -f -r /etc/enigma2/cables.xml /etc/enigma2/terrestrial.xml
Why are you recursively (-r) deleting files? It leads the reader to believe these should be directories.

And given that he (now) zip file contains all of these entries anyway, why bother deleting them at all? Just give the -o option to unzip to overwrite those that already exist.

Darmeth
25-06-17, 08:56
Thanks all but still no joy with unzip. Modified code below. FTP'd to /usr/scripts and chmod to 755 and tried 777. I'm stopping on the unzip with "zip flags 1 and 8 are not supported". Re-tried with unrar and it works, with files extracting. I'm suspecting now something is amiss with BusyBox.



echo 'PLEASE WAIT WHILE BOUQUETS ARE UPDATED'
sleep 3
echo $LINE
wget http://www.darmeth.com/downloads/Darmeth_Motor_45E-30W.zip -O /tmp/darmeth.zip > /dev/null
echo 'DOWNLOAD COMPLETE'
echo $LINE
echo 'UNPACKING BOUQUETS'
sleep 1
unzip -o /tmp/darmeth.zip -d /etc/enigma2 > /dev/null
wget -qO - http://127.0.0.1/web/servicelistreload?mode=0 > /dev/null
sleep 1
echo 'CLEANING /tmp FOLDER'
rm -rf /tmp/darmeth.zip > /dev/null
sleep 1
echo $LINE
echo 'RELOADING SERVICES - PLEASE WAIT'
wget -qO - http://127.0.0.1/web/servicelistreload?mode=1 > /dev/null
wget -qO - http://127.0.0.1/web/servicelistreload?mode=2 > /dev/null
echo $LINE
echo 'DARMETH BOUQUETS UPDATED'
echo $LINE
exit 0

birdman
25-06-17, 13:02
Thanks all but still no joy with unzip. Modified code below. FTP'd to /usr/scripts and chmod to 755 and tried 777. I'm stopping on the unzip with "zip flags 1 and 8 are not supported". Re-tried with unrar and it works, with files extracting. I'm suspecting now something is amiss with BusyBox.The problem is in the zip file, so an issue with how it was created. [EDIT: probably something to do with the compression options]
I get the same message for the download file.
But if I unpack it on a Linux Mint system and create a new zip file, then copy that to the OpenVix box, all is OK.

Now sure what $LINE was meant to be set to above, but here's a slightly simper version, with the locations parameterized at the top (easier to change).


#!/bin/sh
# Darmeth 24-June-2017
# Version 1.0

src_uri="http://www.darmeth.com/downloads/Darmeth_Motor_45E-30W.zip"
rld_uri="http://127.0.0.1/web/servicelistreload"

echo 'PLEASE WAIT WHILE BOUQUETS ARE UPDATED'
sleep 3
echo
wget -qO /tmp/darmeth.zip ${src_uri}
echo 'DOWNLOAD COMPLETE'
echo
echo 'UNPACKING BOUQUETS'
sleep 1
unzip -qo /tmp/darmeth.zip -d /etc/enigma2
wget -qO /dev/null "${rld_uri}?mode=0"
sleep 1
echo 'CLEANING /tmp FOLDER'
rm -f /tmp/darmeth.zip
sleep 1
echo
echo 'RELOADING SERVICES - PLEASE WAIT'
wget -qO /dev/null "${rld_uri}?mode=1"
wget -qO /dev/null "${rld_uri}?mode=2"
echo
echo 'DARMETH BOUQUETS UPDATED'
echo
exit 0

abu baniaz
25-06-17, 13:21
Please try with the zip file I attached above.

Darmeth
25-06-17, 15:52
Ok, getting there! Re-zipped properly and tested my script and birdman's. Files are extracted correctly to /etc/enigma2

BUT...no change to my services. This file has had all the Sports Active channels removed from 28.2E as a test. After script run, they are still present.
What are _bak & _org files? They are present on my box - could they be the issue?
In addition to the regular lamebd, I also suddenly have a lamedb5.

abu baniaz
25-06-17, 15:55
the bak files were created by your settings editor.

don't worry about lamedb5, it is meant to be the new format of lamedb, but there is reluctance to accept it.

birdman
26-06-17, 00:16
don't worry about lamedb5, it is meant to be the new format of lamedb, but there is reluctance to accept it.Really? It's a far more logical representation of the (same) data. Much simpler to parse.

birdman
26-06-17, 00:17
What are _bak & _org files? They are present on my box - could they be the issue?No. If you don't want them don't include them when you create the zip file.

birdman
26-06-17, 00:24
BUT...no change to my services. This file has had all the Sports Active channels removed from 28.2E as a test. After script run, they are still present..Given that mode=1 reloads lamedb and mode=2 reloads User Bouquets, why do you (first) do a mode=0, which does both of the mode=1 and mode=2 jobs?

However, if you look at the debug logs it should show the reload happening.
Whether that would forget existing channels I can't say,....

abu baniaz
26-06-17, 00:57
The script in post 5 worked fine for me. Perhaps you can tweak that? My tests had the download and delete lines commented out. I manually transferred the attached zip file to /tmp.

Darmeth
26-06-17, 14:45
echo 'PLEASE WAIT WHILE BOUQUETS ARE UPDATED'
wget http://www.darmeth.com/downloads/Darmeth_Motor_45E-30W.zip -O /tmp/Darmeth_Motor_45E-30W.zip > /dev/null
rm -rf /etc/enigma2/lamedb5 > /dev/null
unzip -o /tmp/Darmeth_Motor_45E-30W.zip -d /etc/enigma2 > /dev/null
wget -qO - http://127.0.0.1/web/servicelistreload?mode=0 > /dev/null
echo 'CLEANING /tmp FOLDER'
rm -rf /tmp/Darmeth_Motor_45E-30W.zip > /dev/null
echo 'DARMETH BOUQUETS UPDATED'
exit 0


A couple of observations:

1. sleep 1 or sleep 1s not accepted when running from the box. Return says 'Sleep: Invalid number '1'
2. Init 3/4 not accepted when running from the box and behaves as if I’ve typed in: Init —help.
3. Did edit via Dreamboxedit and no changes seen in bouquets until pressing the 'Restart Enigma2' button. (This has always been the case BTW)

I’ve run the script from both the box and via Telnet and have seen the bouquet files update in /etc/enigma2. Init/restart/reboot has no effect on loading the new settings! FTP’d files from abu baniaz to /tmp and tried that; same effect.

I’m on technomate twin-4k running 5.0.020

So…why does this work for you guys but not me?! :-)

ccs
26-06-17, 16:53
sleep 1 works for me, as does init 3 or init 4 (I assume that is what you mean by 3/4).

Looks like you are not creating a Linux file when modifying the script?

Darmeth
26-06-17, 17:28
Adding here, please have a look. Thanks, ccs

54063

ccs
26-06-17, 19:09
I can't see any unwanted characters in the file, but the last line is missing a LF at the end, which may matter, but I'm not sure.

All the sleeps are sleep 4, have you changed them or is this a different file?

Darmeth
26-06-17, 19:25
Different file I sent (changed the sleep when I was running via Telnet. Script definately works and runs with no issues!!

The only issue I have is why my settings don't update.

Darmeth
26-06-17, 22:53
@ccs - thanks dude! Your comment about "not creating a Linux file" solved the issue. I forgot rule 101 - always transfer script files via FTP using BINARY mode. I feel like a dunce!:cool:

Sleep works / init 4 / init 3 works / settings updated...finally!

Thank you all for your patience and kind assistance.

birdman
26-06-17, 23:28
@ccs - thanks dude! Your comment about "not creating a Linux file" solved the issue. I forgot rule 101 - always transfer script files via FTP using BINARY mode. I feel like a dunce!:cool:But a script file is an ASCII file, so you could also create it as a DOS file and transfer in ASCII mode.
The actual rule is to transfer in the correct mode.


Sleep works / init 4 / init 3 works / settings updated...finally!But the init command will also abort any recording in progress at the time.

Darmeth
26-06-17, 23:47
Cheers Birdman. Long day! Was thinking 'always ASCII, never Binary' and typed that pile of garbage! Should read:

always never transfer script files via FTP using BINARY mode.

Darmeth
27-06-17, 18:46
Double-checking on previous post...ACSII technically is correct, as it is a text file, BUT, the lack of return carriage causes issues. SH files should definitely be FTP'd in BINARY mode if no '\n' is specified. I've retested using both ASCII and BINARY - ASCII file gives errors when script is run. BINARY mode works with no errors. ASCII will work if return carriage is specified in the script (which I did not on original).

birdman
27-06-17, 23:02
Double-checking on previous post...ACSII technically is correct, as it is a text file, BUT, the lack of return carriage causes issues. SH files should definitely be FTP'd in BINARY mode if no '\n' is specified.They should be transferred as binary iff you have created then as Unix text file.
If you've created them as Windows/DOS text files you'll need to use ASCII.

(I don't have the issue as I'd create them on a Linux system if I didn't create them on the box itself in the first place).