-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLakkaTOR.sh
138 lines (131 loc) · 4.13 KB
/
LakkaTOR.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
URL_LAKKA='http://www/.lakka.tv/'
URL_LAKKA_DOC='http://www.lakka.tv/doc/home'
URL_LAKKA_THUMBNAILS='http://thumbnailpacks.libretro.com/'
OUTPUT_FILE='thumbnailpacks.libretro.com.html'
ROMS_PATH='/storage/roms/downloads/'
THUMBNAILS_PATH='/storage/thumbnails/'
PLAYLISTS_PATH='/storage/playlists/'
function usage
{
echo 'Usage :'
echo -e '\t./LakkaTOR.bash <cmd>'
echo -e '\t-h, --help : use to get help.'
echo -e '\t--setup : use to setup the system.'
echo -e '\t--scan : use to automatically add games to playlists.\n'
echo -e '\t[WARNING] For the moment, the script only allows zip files. All games must be compressed to zip format'
echo -e '\tand downloaded to the corresponding folder (e.g : download Super Mario World.zip from https://romsmania.cc/roms/super-nintendo'
echo -e '\tand save the file into /storage/roms/downloads/Nintendo - Super Nintendo Entertainment System/ folder).'
echo -e '\tFor more informations, follow these urls :'
echo -e "\t - $URL_LAKKA"
echo -e "\t - $URL_LAKKA_DOC"
}
function getThumbnailPackNames
{
wget -q "$1" -O "$OUTPUT_FILE"
if [ -e "$OUTPUT_FILE" ]
then
thumbnailPackNames=$(grep -Eo '>(.+\.zip)<' < "$OUTPUT_FILE" | sed -e 's/>//' -e 's/<//' -e 's/ /_/g')
if [ -n "$thumbnailPackNames" ]
then
echo "$thumbnailPackNames"
else
exit 0
fi
else
exit 0
fi
}
function setup
{
for t in $1
do
th="${t//_/ }"
roms_dir="$ROMS_PATH${th%.zip}"
if [ ! -e "$roms_dir" ]
then
echo "[-] create directory $roms_dir"
mkdir "$roms_dir"
echo "[+] create directory $roms_dir done"
else
echo "[i] directory $roms_dir already exist"
fi
playlist_file="$PLAYLISTS_PATH${th%.zip}.lpl"
if [ ! -e "$playlist_file" ]
then
echo "[-] create file $playlist_file"
touch "$playlist_file"
echo "[+] create file $playlist_file done"
else
echo "[i] file $playlist_file already exist"
fi
thumbnail_dir="$THUMBNAILS_PATH${th%.zip}"
if [ -e "$thumbnail_dir" ]
then
echo "[i] $thumbnail_dir already exist"
else
url_thumbnail_pack="$URL_LAKKA_THUMBNAILS$th"
thumbnail_pack="$THUMBNAILS_PATH$th"
echo "[-] download $url_thumbnail_pack in $THUMBNAILS_PATH"
wget -q "$url_thumbnail_pack" -O "$thumbnail_pack"
echo "[+] download $url_thumbnail_pack in $THUMBNAILS_PATH done"
if [ -e "$thumbnail_pack" ]
then
echo "[-] unpack $thumbnail_pack"
unzip -q "$thumbnail_pack" -d "$THUMBNAILS_PATH"
if [ $? -eq 0 ]
then
echo "[+] unpack $thumbnail_pack done"
echo "[-] remove $thumbnail_pack"
rm -f "$thumbnail_pack"
if [ $? -eq 0 ]
then
echo "[+] remove $thumbnail_pack done"
else
echo "[i] remove $thumbnail_pack failed"
fi
else
echo "[i] unpack $thumbnail_pack failed"
fi
else
echo "[i] $thumbnail_pack not found"
fi
fi
done
}
function addGamesToPlaylists
{
folders=$(ls "$ROMS_PATH" | sed "s/ /_/g") # must use find "$ROMS_PATH" -type d but for our usefulness, it is OK.
for folder in $folders
do
folder="${folder//_/ }"
files=$(ls "$ROMS_PATH$folder" | sed "s/ /_/g") # must use find "$ROMS_PATH$folder" -type f, don't forget to change folder with folder="$(basename "$folder")"
playlist_name="$folder.lpl"
for file in $files
do
file="${file//_/ }"
playlist_path="$PLAYLISTS_PATH$folder.lpl"
zip_path="$ROMS_PATH$folder/$file"
count=$(grep -c "$file" "$playlist_path")
if [ $count -lt 1 ]
then
echo "[-] add $file to $playlist_path"
rom=$(unzip -Z -1 "$zip_path")
{ echo "$zip_path#$rom"; echo "${file%.zip}"; echo "DETECT"; echo "DETECT"; echo "DETECT"; echo "$playlist_name"; } >> "$playlist_path"
echo "[+] add $file in $playlist_path succeeded"
else
echo "[i] $file already exist in $playlist_path"
fi
done
done
}
if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]
then
usage
else
case "$1" in
'--setup') thumbnail_pack_names=$(getThumbnailPackNames "$URL_LAKKA_THUMBNAILS") && setup "$thumbnail_pack_names";;
'--scan') addGamesToPlaylists;;
*) usage;;
esac
fi