This script does not work in lakka


#1

This script works perfectly in raspbian and in ubuntu, but not in lakka:

#!/bin/bash

IFS=';'

cd /storage/.attract/romlists
rm Favorites.txt

touch Favorites.txt
chmod 777 Favorites.txt

ls *.tag > tagfiles
while read filename
do
  while read gamename
  do
    romlist=`echo ${filename} |cut -f1 -d '.'`
    cat "${romlist}.txt"|grep "^${gamename};" >> Favorites.txt
  done < "${filename}"
done < tagfiles

rm tagfiles
cat Favorites.txt |sort -u > tmp_favorites.txt
mv tmp_favorites.txt Favorites.txt

sleep 5

the reading of the data is correct, but the redirection >> does not do anything.

In putty ssh this comand runs:

cat "Atari2600.txt" |grep "Centipede (USA)" >> Favorites.txt

but the script does not.

Does anyone know why?


#2

How did you test this?

Can you show an example of your input files (*.tag) and what they contain?


#3

Thanks for your interest.

Two tag files:

MAME.tag, contains two name games, exactly:

mslug
dino

Atari 2600.tag, contains exactly:

Centipede (USA)


#4

${romlist} is not defined in the script as far as I can see so it does not know where to search for the romnames defined in the .tag files.


#5

Yes I agree. How is it working in the other OS’s then?


#6

Did you get this script from some kind of readymade distro? What is it supposed to be doing? Something using attractmode? I don’t see what this script should do in Lakka.


#7

It is a script that collects the favorite games from the * .tag files, searches for those games in the game lists and creates a new list of games with all the favorites.

And yes, it’s a script for Attract-Mode in Lakka. And I’m doing it from scratch, it’s nothing done before.

Lakka consumes very few resources and is ideal for Attract-Mode with RetroArch. It is somewhat complicated to do, but it gives very satisfactory results.

And another thing, adding:

echo ${romlist}
echo ${gamename}

to the script, under the “cat” you can check that it finds both the names of the romlists and the games. What it does not do is dump them to Favorites.txt

And the strangest thing is that in raspbian, the script works perfectly.

Copying the romlists to /storage folder, in lakka, you can check the operation of the script, by ssh.

Romlists folder (and the script “favorites.sh”):

(https://drive.google.com/open?id=13-LUJMbHDMuFzq62A8mS3jT1P8JHdasA)

To favorites.sh will have to give execution permissions.

I would be grateful if any solution or idea that you give me was accompanied by the corresponding code, since I am not an expert in linux scripts. For example, in your answer:

${romlist} is not defined in the scrip

I do not know what you want to tell me or what the script would lack.

It lacks some declaration of variables?


#8

Try changing cat “${romlist}.txt”|grep “^${gamename};” >> Favorites.txt in the script to just cat “${romlist}.txt” | grep “${gamename}” >> Favorites.txt


#9

Thanks, but nothing has changed, still do not dump the data to Favorites.txt


#10

Try this one instead:

#!/bin/bash

IFS=';'

cd /storage/.attract/romlists
rm Favorites.txt

touch Favorites.txt
chmod 777 Favorites.txt

for TAGFILE in *.tag; do
  ROMLIST="$(echo $TAGFILE|cut -f1 -d '.').txt"
  while read GAMENAME; do
    grep "$gamename" "$ROMLIST" >> Favorites.txt
  done < "$TAGFILE"
done

cat Favorites.txt |sort -u > tmp_favorites.txt
mv tmp_favorites.txt Favorites.txt

sleep 5

This one works for me on MacOS on my work computer and on my server/HTPC running Ubuntu 18.04.


#11

Thanks, but this script puts ALL the games in the txt file into Favorites.txt, not just the games that are in the tag files.

I have changed this line :

grep "$gamename" "$ROMLIST" >> Favorites.txt

for this:

grep "$GAMENAME" "$ROMLIST" >> Favorites.txt

And now do not copy anything

The problem, I think it is that the grep does not find the GAMENAME in the ROMLIST, because if we execute this line:

grep -v "$GAMENAME" "$ROMLIST" >> Favorites.txt

Copy all the ROMLIST lines in Favorites.txt

The -v grep option is to show the lines not found, right?


#12

Man, sorry about that. Did not notice that all got added…

Weird though as the individual commands work, but in the script they fail somehow.

I will try to rewrite it some other way and hopefully get it running properly.


#13

This one works correctly for me now in MacOS and Ubuntu:

#!/bin/bash

IFS=';'

cd /storage/.attract/romlists
rm Favorites.txt

touch Favorites.txt
chmod 777 Favorites.txt

for tagfile in *.tag; do
  romlist="$(echo $tagfile|cut -f1 -d '.')"
  while read line; do
    title="${line/$'\r'/}"
    grep "${title};" "${romlist}.txt" >> Favorites.txt
  done < "${tagfile}"  
done

cat Favorites.txt |sort -u > tmp_favorites.txt
mv tmp_favorites.txt Favorites.txt

sleep 5

Hope this will work for you as well on Lakka.

PS. The Neo Geo games that you have in the tag-file is not added to the favourites because you don’t have a matching romlist for Neo Geo.


#14

Thanks for your help, my failure of the Neo Geo … I’m sorry. I’m going to try and tell you …

I’ve already tried and, unfortunately, still does not dump anything in Favorites.txt

With this code:

for tagfile in *.tag; do
  romlist="$(echo $tagfile|cut -f1 -d '.')"
  while read line; do
    title="${line/$'\r'/}"
    grep "^${title};" "${romlist}.txt" #>> Favorites.txt
	echo "${line/$'\r'/}"
	echo "^${title};"
	echo "${romlist}.txt"
	echo "${tagfile}"
  done < "${tagfile}"  
done

This is the outpun screen:

Centipede (USA)
;Centipede (USA)
Atari 2600.txt
Atari 2600.tag
Chip's Challenge
;Chip's Challenge
Atari Lynx.txt
Atari Lynx.tag
dino
;dino
MAME.txt
MAME.tag
mslug
;mslug
MAME.txt
MAME.tag
Castlevania - The Adventure
;Castlevania - The Adventure
Nintendo Game Boy.txt
Nintendo Game Boy.tag
Contra III - The Alien Wars (USA)
;Contra III - The Alien Wars (USA)
Nintendo SNES.txt
Nintendo SNES.tag
mslug4
;mslug4
SNK Neo Geo AES.txt
SNK Neo Geo AES.tag
mslug5
;mslug5
SNK Neo Geo AES.txt
SNK Neo Geo AES.tag
Doom (Japan, USA)
;Doom (Japan, USA)
Sega 32X.txt
Sega 32X.tag
Chakan
;Chakan
Sega Game Gear.txt
Sega Game Gear.tag

#15

For help, this is the original script where I got the code:

https://drive.google.com/open?id=16htNp-r2NFNStBrU98Cw4gZaobuwbLcE

But Lakka does not support infobox.


#16

I saw on your output that the grep command is searching for “;Chakan” when it should be “Chakan;”. I have no idea why this would be as that is not happening in my tests over here.

I will test it on my RPi Lakka when I get home later tonight,.


#18

Thanks for your help.

This code:

    #!/bin/bash

    rm Favorites.txt

    touch Favorites.txt
    chmod 777 Favorites.txt

    for tagfile in *.tag; do
      romlist="$(echo $tagfile|cut -f1 -d '.')"
      while read line; do
        title="${line/$'\r'/}"
        grep "^${title};" "${romlist}.txt" >> Favorites.txt
        echo "${tagfile}"
        echo "${title}"
        echo "${romlist}.txt"
      done < "${tagfile}"
    done

    wc -l Favorites.txt

runs perfectly in raspberry pi with raspbian, and not run in Lakka… this is amazing…


#19

I do not think that’s that, search looks good, what happens is that when doing the echo ${title} “^” or “;” are not necessary. But I’m not too sure about this either.

The issue may be that in raspbian echo $BASH gives /bin/bash and in Lakka it gives /bin/sh.

And an ls -l /bin/sh gives a redirection to busybox… and from there, i’m already lost…


#20

Busybox is apparently a lightweight replacement for sh, the shell, that runs the scripts. Most modern linux based systems use the newer replacement for shell called bash, that have some extended functionality that makes your script work.

Unfortunately Lakka is built using the lightweight version of sh from busybox and is missing functionality that is needed for the script to run.

I lack the skill of detecting what to change in the script to make it run on the simpler sh version that is available in Lakka so I have to give up on helping you.


#21

Thank you very much for the help, I will continue to try it myself.

We were wrong. Your script runs perfectly in libreelec… with busybox… It must be a problem of Lakka.