File: check_docs.sh

package info (click to toggle)
streamlink 8.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,564 kB
  • sloc: python: 51,188; sh: 184; makefile: 152
file content (68 lines) | stat: -rwxr-xr-x 1,512 bytes parent folder | download | duplicates (5)
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
#!/bin/bash

set -e

RESULT=0

DOCBASE_DATA=$(/usr/sbin/install-docs -s python3-streamlink-doc)

check-file() {
	local TARGET_FILE="$1"
	echo -n "Checking file $TARGET_FILE"
	if ! [ -f "$TARGET_FILE" ]; then
		echo " MISSING"
		return 1
	else
		echo " OK"
	fi
	return 0
}

if [ -z "$DOCBASE_DATA" ]; then
	echo "Cannot read install-docs -s python3-streamlink-doc" >&2
	exit 1
fi

echo "Doc-base file content:"
echo "$DOCBASE_DATA"
echo "---------"

echo "Checking Files field"
DOC_FILES_WILDCARD=$(grep Files <<<"$DOCBASE_DATA" | sed 's/Files: //')
echo "Content of $DOC_FILES_WILDCARD:"
# no quotes intended: doc-base file use wildcards and we want them to be expanded
# shellcheck disable=SC2086
ls -l $DOC_FILES_WILDCARD
echo "---------"

# shellcheck disable=SC2206
DOC_FILES_COUNT=( $DOC_FILES_WILDCARD )
if ! [ -f "${DOC_FILES_COUNT[0]}" ]; then
	echo "$DOC_FILES_WILDCARD match no files" >&2
	exit 2
fi

echo "Checking files:"
INDEX_HTML_LOCATION=$(grep Index <<<"$DOCBASE_DATA" | sed 's/Index: //')

case $INDEX_HTML_LOCATION in /usr/share/doc/*)
	;;
*)
	echo "index.html must be in /usr/share/doc/ but is \"$INDEX_HTML_LOCATION\"" >&2
	exit 2
esac

check-file "$INDEX_HTML_LOCATION" || exit 3

HTML_BASE_DIR=$(dirname "$INDEX_HTML_LOCATION")

echo "Checking broken symlinks in $HTML_BASE_DIR"
BROKEN_SYMLINKS_COUNT=$(find "$HTML_BASE_DIR" -xtype l | tee /dev/stderr | wc -l)
if [ "$BROKEN_SYMLINKS_COUNT" -gt 0 ]; then
	echo "ERROR: There are broken symlinks"
	exit 4
else
	echo "OK"
fi

exit "$RESULT"