forked from openSUSE/twopence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instman.sh
executable file
·81 lines (65 loc) · 1.5 KB
/
instman.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Install a manpage and replace some place holders in the .TH header line
#
# Copyright (C) 2015 Olaf Kirch <okir@suse.de>
#
MANDIR=/usr/share/man
function usage {
echo "$@"
echo "Usage: $0 [-d destdir] [-n instname] [-p instprefix] [-z] manpage" >&2
exit 1
}
# Find the directory in which this script resides.
# The subst.sh script is expected to be in the same
# place.
utildir=${0%/*}
opt_compress=false
while getopts "d:n:p:v:z" arg; do
case $arg in
d) opt_destdir=$OPTARG;;
n) opt_instname=$OPTARG;;
p) opt_prefix=$OPTARG;;
z) opt_compress=true;;
*) usage "Unexpected option -$arg";;
esac
done
shift $(($OPTIND-1))
if [ $# -eq 0 ]; then
usage "Missing manual page argument"
fi
if [ $# -gt 1 -a -n "$opt_instname" ]; then
usage "Cannot install several manpages while using -n option"
fi
if $opt_compress; then
suffix=".gz"
else
suffix=""
fi
install_date=$(LANG=C date "+%B %Y")
for manpage; do
basename=${manpage##*/}
if [ -n "$opt_instname" ]; then
instname=$opt_instname
else
instname="${opt_prefix}${basename}"
fi
mancat=${instname#*.}
mancat=${mancat:0:1}
case $mancat in
1|2|3|4|5|6|7|8|9)
# echo category $mancat
: ;;
*)
echo "Unknown or unsupported manpage category" >&2
exit 1;;
esac
destdir="$opt_destdir$MANDIR/man${mancat}"
destfile="${destdir}/$instname"
echo "Installing $manpage as $destfile$suffix"
install -m 755 -d "$destdir"
install -m 644 "$manpage" "$destfile"
${utildir}/subst.sh $destfile
$opt_compress && gzip -9f "$destfile"
done
exit 0