···16#
17# See comments on each function for more details.
1819-# installManPage <path> [...<path>]
20#
21# Each argument is checked for its man section suffix and installed into the appropriate
22# share/man/man<n>/ directory. The function returns an error if any paths don't have the man
23# section suffix (with optional .gz compression).
0000024installManPage() {
25- local path
26- for path in "$@"; do
27- if test -z "$path"; then
00000000000000000000000028 nixErrorLog "${FUNCNAME[0]}: path cannot be empty"
29 return 1
30 fi
31- nixInfoLog "${FUNCNAME[0]}: installing $path"
32- local basename
33- basename=$(stripHash "$path") # use stripHash in case it's a nix store path
000000000034 local trimmed=${basename%.gz} # don't get fooled by compressed manpages
35 local suffix=${trimmed##*.}
36 if test -z "$suffix" -o "$suffix" = "$trimmed"; then
37- nixErrorLog "${FUNCNAME[0]}: path missing manpage section suffix: $path"
38 return 1
39 fi
0040 local outRoot
41 if test "$suffix" = 3; then
42 outRoot=${!outputDevman:?}
43 else
44 outRoot=${!outputMan:?}
45 fi
46- local outPath="${outRoot}/share/man/man$suffix/$basename"
47- install -D --mode=644 --no-target-directory "$path" "$outPath"
0000000000048 done
49}
50
···16#
17# See comments on each function for more details.
1819+# installManPage [--name <path>] <path> [...<path>]
20#
21# Each argument is checked for its man section suffix and installed into the appropriate
22# share/man/man<n>/ directory. The function returns an error if any paths don't have the man
23# section suffix (with optional .gz compression).
24+#
25+# Optionally accepts pipes as input, which when provided require the `--name` argument to
26+# name the output file.
27+#
28+# installManPage --name foobar.1 <($out/bin/foobar --manpage)
29installManPage() {
30+ local arg name='' continueParsing=1
31+ while { arg=$1; shift; }; do
32+ if (( continueParsing )); then
33+ case "$arg" in
34+ --name)
35+ name=$1
36+ shift || {
37+ nixErrorLog "${FUNCNAME[0]}: --name flag expected an argument"
38+ return 1
39+ }
40+ continue;;
41+ --name=*)
42+ # Treat `--name=foo` that same as `--name foo`
43+ name=${arg#--name=}
44+ continue;;
45+ --)
46+ continueParsing=0
47+ continue;;
48+ esac
49+ fi
50+51+ nixInfoLog "${FUNCNAME[0]}: installing $arg${name:+ as $name}"
52+ local basename
53+54+ # Check if path is empty
55+ if test -z "$arg"; then
56+ # It is an empty string
57 nixErrorLog "${FUNCNAME[0]}: path cannot be empty"
58 return 1
59 fi
60+61+ if test -n "$name"; then
62+ # Provided name. Required for pipes, optional for paths
63+ basename=$name
64+ elif test -p "$arg"; then
65+ # Named pipe requires a file name
66+ nixErrorLog "${FUNCNAME[0]}: named pipe requires --name argument"
67+ else
68+ # Normal file without a name
69+ basename=$(stripHash "$arg") # use stripHash in case it's a nix store path
70+ fi
71+72+ # Check that it is well-formed
73 local trimmed=${basename%.gz} # don't get fooled by compressed manpages
74 local suffix=${trimmed##*.}
75 if test -z "$suffix" -o "$suffix" = "$trimmed"; then
76+ nixErrorLog "${FUNCNAME[0]}: path missing manpage section suffix: $arg"
77 return 1
78 fi
79+80+ # Create the out-path
81 local outRoot
82 if test "$suffix" = 3; then
83 outRoot=${!outputDevman:?}
84 else
85 outRoot=${!outputMan:?}
86 fi
87+ local outPath="${outRoot}/share/man/man$suffix/"
88+ nixInfoLog "${FUNCNAME[0]}: installing to $outPath"
89+90+ # Install
91+ if test -p "$arg"; then
92+ # install doesn't work with pipes on Darwin
93+ mkdir -p "$outPath" && cat "$arg" > "$outPath/$basename"
94+ else
95+ install -D --mode=644 --no-target-directory -- "$arg" "$outPath/$basename"
96+ fi
97+98+ # Reset the name for the next page
99+ name=
100 done
101}
102