-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Random_Game.sh
59 lines (46 loc) · 1.62 KB
/
Random_Game.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
#!/bin/sh
#
# Script by Daniel Radtke <DanTheMan827>
#
source /etc/preinit
script_init
cachePath="/tmp/RandomGame-FileList"
lastLaunchArgsPath="/tmp/RandomGame-LaunchArguments"
lastCommandPath="/tmp/RandomGame-LastCommand"
script_gamecode="$(basename $(dirname $0))"
if (echo "$*" | grep -qEe "rollback-input-dir|load-state"); then
exec $(cat "$lastCommandPath") $@
fi
gameStorage="$rootfs$gamepath"
type findGameStorage && gameStorage="$(findGameStorage)"
if [ -f "$cachePath" ]; then
fileList="$(cat "$cachePath")"
else
fileList="$(find "$gameStorage" -name "*.desktop")"
echo "$fileList" > "$cachePath"
fi
fileList="$(echo "$fileList" | grep -vEe "$script_gamecode|CLV-S-[0-9]{5}")"
[ "$sftype" != "nes" ] && fileList="$(echo "$fileList" | grep -ve "^$gameStorage/nes/")"
while true
do
desktopFile="$(echo "$fileList" | head -$((${RANDOM} % `echo "$fileList" | wc -l` + 1)) | tail -1)"
grep "$desktopFile" -qEe "chmenu|^Random=false|/bin/hsqs |/bin/sh " || break
done
execLine="$(cat "$desktopFile" | grep -E '^Exec=')"
pathLine="$(cat "$desktopFile" | grep -E '^Path=')"
codeLine="$(cat "$desktopFile" | grep -E '^Code=')"
desktopFilePath="$(dirname "$desktopFile")"
desktopExec="${execLine##Exec=}"
desktopPath="${pathLine##Path=}"
desktopCode="${codeLine##Code=}"
desktopExec="$(echo "$desktopExec" | sed -e "s# \(/usr/share/games/\(nes/kachikachi/\)\?\|/var/games/\)$desktopCode/# $desktopFilePath/#")"
echo "$desktopExec"
pwd="$(pwd)"
mkdir -p "$desktopPath"
cd /
umount "$pwd" 2>/dev/null
mount_bind "$desktopPath" "$pwd"
cd "$pwd"
echo "$@" > "$lastLaunchArgsPath"
echo "$desktopExec" > "$lastCommandPath"
exec $desktopExec $@