aboutsummaryrefslogtreecommitdiff
path: root/sbopkglint.d/90-terminfo.t.sh
blob: 9b0cc03da164b5dabe2db28b07e9cedb90298b97 (plain)
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
#!/bin/sh

# sbopkglint test, must be sourced by sbopkglint (not run standalone).

# PKG, PRGNAM, VERSION, ARCH are set by sbopkglint. also the current
# directory is the root of the installed package tree.

#######################################################################
# check contents of /usr/share/terminfo, if present.
#
# 0. /usr/share/terminfo may only contain directories (not files). This
#    gets checked in 05-basic_sanity, not here.
# 1. directories under /usr/share/terminfo must have one-character names,
#    /a-zA-Z0-9/.
# 2. directories under /usr/share/terminfo mode 0755.
# 3. /usr/share/terminfo/*/ must contain only files (no subdirs).
# 4. files must go in the subdir for the first letter of their name.
# 5. files must be valid compiled terminfo entries.
# 6. files must be mode 0644 or 0444.
# 7. all files and dirs must be owned by root:root.
#
# Note: although I've never seen it done, it's perfectly legit for a
# terminfo file to have a space in its name. So that's not checked
# for here.

if [ -d "usr/share/terminfo" ]; then
	find -L "usr/share/terminfo" -type f > .tfiles.$$
	# 1:
	find -L "usr/share/terminfo" -type d -mindepth 1 -name '??*' > .baddirs.$$
	# 3:
	find -L "usr/share/terminfo" -type d -mindepth 2 >> .baddirs.$$
	# 2:
	find -L "usr/share/terminfo" -type d -a \! -perm 755 > .badperms.$$
	# 6:
	find -L "usr/share/terminfo" -type f -a \! \( -perm 644 -o -perm 444 \) >> .badperms.$$
	# 7:
	find -L "usr/share/terminfo" \! -user root -o \! -group root >> .badperms.$$
	# 5:
	xargs -d "\n" file -L --mime-type < .tfiles.$$ | grep -v 'application/x-terminfo' > .badmime.$$
	# 4:
	egrep -v 'usr/share/terminfo/([a-zA-Z0-9])/\1[^/]*$' .tfiles.$$ > .wrongdirs.$$

	if [ -s .badperms.$$ ]; then
		warn "bad terminfo ownership (must be root:root) and/or permissions (755 for dirs, 644 or 444 for files):"
		sort -u .badperms.$$ | xargs -d "\n" ls -ld
	fi

	if [ -s .baddirs.$$ ]; then
		warn "invalid terminfo directory structure:"
		sort -u .baddirs.$$ | xargs -d "\n" ls -ld
	fi

	if [ -s .wrongdirs.$$ ]; then
		warn "terminfo entries in wrong dir(s):"
		xargs -d "\n" ls -l < .wrongdirs.$$
	fi

	if [ -s .badmime.$$ ]; then
		warn "/usr/share/terminfo has invalid terminfo file(s):"
		cat .badmime.$$
	fi

	rm -f .badperms.$$ .baddirs.$$ .tfiles.$$ .wrongdirs.$$ .badmime.$$
fi