-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
doc
executable file
·83 lines (72 loc) · 2.01 KB
/
doc
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
#!/bin/bash
#
# Show Debian changelog and other package documents.
#
# VERSION :0.1.1
# DATE :2016-12-13
# URL :https://github.com/szepeviktor/debian-server-tools
# AUTHOR :Viktor Szépe <viktor@szepe.net>
# LICENSE :The MIT License (MIT)
# BASH-VERSION :4.2+
# LOCATION :/usr/local/bin/doc
set -e
declare OPT
declare SUFFIX
declare PKG
declare FILENAME="changelog"
declare DEBIAN=".Debian"
while getopts :urnh OPT; do
case "$OPT" in
u)
DEBIAN=""
;;
r)
FILENAME="README"
;;
n)
FILENAME="NEWS"
;;
# You may add other files here like TODO or copyright
h)
cat <<"EOF"
Usage: doc [OPTION]... [PACKAGE]
Display package documentation for a Debian package.
doc package Show Debian changelog
doc -u package Show upstream changelog
doc -r package Show Debian readme
doc -ur package Show upstream readme
doc -n package Show Debian news
doc -un package Show upstream news
doc -h Display this help and exit
EOF
exit 0
;;
?)
echo "Invalid option (${OPT})" 1>&2
exit 2
;;
esac
done
shift "$((OPTIND - 1))"
# Incorrect number of arguments
test $# -eq 1
# Last option must be the package name
PKG="$1"
# Incorrect package name
test -n "$PKG"
# Check documentation exists for the package
test -d "/usr/share/doc/${PKG}"
# changelog.gz or changelog or changelog.md.gz or changelog.md
for SUFFIX in .gz "" .md.gz .md; do
if [ -f "/usr/share/doc/${PKG}/${FILENAME}${DEBIAN}${SUFFIX}" ]; then
# File is found, show its content in the default pager
if [ "${SUFFIX%.gz}" != "$SUFFIX" ]; then
zcat "/usr/share/doc/${PKG}/${FILENAME}${DEBIAN}${SUFFIX}" | pager
else
pager "/usr/share/doc/${PKG}/${FILENAME}${DEBIAN}${SUFFIX}"
fi
exit 0
fi
done
echo "File not found /usr/share/doc/${PKG}/${FILENAME}${DEBIAN}[.md][.gz]" 1>&2
exit 3