File: play.it

package info (click to toggle)
play.it 2.11.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye, buster, sid
  • size: 2,740 kB
  • sloc: sh: 35,147; makefile: 52
file content (126 lines) | stat: -rwxr-xr-x 2,836 bytes parent folder | download
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
#!/bin/sh -e

set -o errexit

INPUT_FILE="$1"

LIB_ONLY=true

: "${XDG_DATA_HOME:="$HOME/.local/share"}"

if [ -z "$PLAYIT_LIB2" ]; then
	for path in\
		"$PWD"\
		"$(dirname "$0")/play.it-2/lib"\
		"$XDG_DATA_HOME/play.it"\
		'/usr/local/share/games/play.it'\
		'/usr/local/share/play.it'\
		'/usr/share/games/play.it'\
		'/usr/share/play.it'
	do
		if [ -e "$path/libplayit2.sh" ]; then
			PLAYIT_LIB2="$path/libplayit2.sh"
			break
		fi
	done
fi
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=play.it-2/lib/libplayit2.sh
. "$PLAYIT_LIB2"

if [ "$#" = 0 ]; then
	help
	exit 0
fi

if [ ! -f "$INPUT_FILE" ]; then
	print_error
	case "${LANG%_*}" in
		('fr')
			# shellcheck disable=SC1112
			string='%s n’est pas un fichier valide\n'
		;;
		('en'|*)
			string='%s is not a valid file\n'
		;;
	esac
	# shellcheck disable=SC2059
	printf "$string" "$INPUT_FILE"
	exit 1
fi

# Locate script by file name
FILE_NAME="${INPUT_FILE##*/}"
case "${LANG%_*}" in
	('fr')
		# shellcheck disable=SC1112
		string='Recherche d’un script par nom de fichier pour le fichier %s\n'
	;;
	('en'|*)
		string='Looking for a script by file name for file %s\n'
	;;
esac
# shellcheck disable=SC2059
printf "$string" "$FILE_NAME"
SCRIPT="$(find\
	"$(dirname "$0")/play.it-2/games"\
	"$XDG_DATA_HOME/play.it"\
	'/usr/local/share/games/play.it'\
	'/usr/local/share/play.it'\
	'/usr/share/games/play.it'\
	'/usr/share/play.it'\
	! -path '*/prefixes/*' -type f -name '*.sh' -exec\
	grep --regexp="ARCHIVE_.\\+='$FILE_NAME'" --files-with-matches '{}' + 2>/dev/null | head --lines=1)"

# Locate script by file MD5 checksum
if [ -z "$SCRIPT" ]; then
	case "${LANG%_*}" in
		('fr')
			# shellcheck disable=SC1112
			string='Recherche d’un script par somme de contrôle MD5 pour le fichier %s\n'
		;;
		('en'|*)
			string='Looking for a script by MD5 hash sum for file %s\n'
		;;
	esac
	# shellcheck disable=SC2059
	printf "$string" "$FILE_NAME"
	check_deps 'md5sum'
	FILE_MD5="$(md5sum "$INPUT_FILE" | cut --delimiter=' ' --fields=1)"
	SCRIPT="$(find\
		"$(dirname "$0")/play.it-2/games"\
		"$XDG_DATA_HOME/play.it"\
		'/usr/local/share/games/play.it'\
		'/usr/local/share/play.it'\
		'/usr/share/games/play.it'\
		'/usr/share/play.it'\
		! -path '*/prefixes/*' -type f -name '*.sh' -exec\
		grep --regexp="$FILE_MD5" --files-with-matches '{}' + 2>/dev/null | head --lines=1)"
	SCRIPT_OPTIONS='--checksum=none'
fi

if [ -z "$SCRIPT" ]; then
	print_error
	case "${LANG%_*}" in
		('fr')
			string='Impossible de trouver un script pour le fichier %s\n'
		;;
		('en'|*)
			string='Could not find script for file %s\n'
		;;
	esac
	# shellcheck disable=SC2059
	printf "$string" "$FILE_NAME"
	exit 1
fi

export PLAYIT_LIB2

shift 1
"$SCRIPT" "$INPUT_FILE" $SCRIPT_OPTIONS "$@"

exit 0