1 | #!/bin/sh |
---|
2 | #- |
---|
3 | # Copyright (c) 2013-2014 Dag-Erling Smørgrav |
---|
4 | # All rights reserved. |
---|
5 | # |
---|
6 | # Redistribution and use in source and binary forms, with or without |
---|
7 | # modification, are permitted provided that the following conditions |
---|
8 | # are met: |
---|
9 | # 1. Redistributions of source code must retain the above copyright |
---|
10 | # notice, this list of conditions and the following disclaimer. |
---|
11 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | # notice, this list of conditions and the following disclaimer in the |
---|
13 | # documentation and/or other materials provided with the distribution. |
---|
14 | # 3. The name of the author may not be used to endorse or promote |
---|
15 | # products derived from this software without specific prior written |
---|
16 | # permission. |
---|
17 | # |
---|
18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
22 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
23 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
24 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
25 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
26 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
27 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
28 | # SUCH DAMAGE. |
---|
29 | # |
---|
30 | # $OpenPAM: mkpkgng.in 938 2017-04-30 21:34:42Z des $ |
---|
31 | # |
---|
32 | |
---|
33 | # Print an informational message |
---|
34 | info() { |
---|
35 | echo "mkpkgng: $@" |
---|
36 | } |
---|
37 | |
---|
38 | # Print an error message and exit |
---|
39 | error() { |
---|
40 | echo "mkpkgng: $@" 1>&2 |
---|
41 | exit 1 |
---|
42 | } |
---|
43 | |
---|
44 | # Ask a yes / no question |
---|
45 | yesno() { |
---|
46 | while :; do |
---|
47 | echo -n "mkpkgng: $@ (yes/no) " |
---|
48 | read answer |
---|
49 | case $answer in |
---|
50 | [Yy]|[Yy][Ee][Ss]) |
---|
51 | return 0 |
---|
52 | ;; |
---|
53 | [Nn]|[Nn][Oo]) |
---|
54 | return 1 |
---|
55 | ;; |
---|
56 | esac |
---|
57 | done |
---|
58 | } |
---|
59 | |
---|
60 | # |
---|
61 | # Locate source and build directory |
---|
62 | # |
---|
63 | srcdir="@abs_top_srcdir@" |
---|
64 | builddir="@abs_top_builddir@" |
---|
65 | cd "$srcdir" |
---|
66 | |
---|
67 | # |
---|
68 | # Determine pkgng version and ABI |
---|
69 | # |
---|
70 | pkgver=$(pkg -v) |
---|
71 | [ -n "$pkgver" ] || error "Unable to determine pkgng version." |
---|
72 | pkgabi=$(pkg config abi) |
---|
73 | [ -n "$pkgabi" ] || error "Unable to determine package ABI." |
---|
74 | |
---|
75 | # |
---|
76 | # Determine package name and version |
---|
77 | # |
---|
78 | package="@PACKAGE@" |
---|
79 | version="@PACKAGE_VERSION@" |
---|
80 | if ! expr "$version" : "[0-9]{1,}$" >/dev/null ; then |
---|
81 | svnversion="$(svnversion 2>&1)" |
---|
82 | svnversion=$(expr "$svnversion" : '\([0-9][0-9]*\)[A-Z]\{0,1\}$') |
---|
83 | if [ -n "$svnversion" ] ; then |
---|
84 | package="$package-$version" |
---|
85 | version="r$svnversion" |
---|
86 | fi |
---|
87 | fi |
---|
88 | |
---|
89 | # |
---|
90 | # Locate GNU make |
---|
91 | # |
---|
92 | if which gmake >/dev/null ; then |
---|
93 | make=gmake |
---|
94 | else |
---|
95 | make=make |
---|
96 | fi |
---|
97 | make="$make --no-print-directory --quiet V=0" |
---|
98 | |
---|
99 | # |
---|
100 | # Create temporary directory |
---|
101 | # |
---|
102 | info "Creating the temporary directory." |
---|
103 | tmproot=$(mktemp -d "${TMPDIR:-/tmp}/$package-$version.XXXXXX") |
---|
104 | [ -n "$tmproot" -a -d "$tmproot" ] || \ |
---|
105 | error "Unable to create the temporary directory." |
---|
106 | trap "exit 1" INT |
---|
107 | trap "info Deleting the temporary directory. ; rm -rf '$tmproot'" EXIT |
---|
108 | set -e |
---|
109 | |
---|
110 | # |
---|
111 | # Install into tmproot |
---|
112 | # |
---|
113 | info "Installing into the temporary directory." |
---|
114 | $make install DESTDIR="$tmproot" |
---|
115 | |
---|
116 | # |
---|
117 | # Compress man pages |
---|
118 | # |
---|
119 | find $tmproot -type d -name 'man[0-9]' | |
---|
120 | while read mandir ; do |
---|
121 | find $mandir -type f -name '*.[0-9]' | |
---|
122 | while read manpage ; do |
---|
123 | gzip "$manpage" |
---|
124 | done |
---|
125 | find $mandir -type l -name '*.[0-9]' | |
---|
126 | while read manlink ; do |
---|
127 | ln -s "$(readlink $manlink).gz" "$manlink.gz" |
---|
128 | done |
---|
129 | done |
---|
130 | |
---|
131 | # |
---|
132 | # Generate stub manifest |
---|
133 | # |
---|
134 | info "Generating the stub manifest." |
---|
135 | manifest="$tmproot/+MANIFEST" |
---|
136 | cat >"$manifest" <<EOF |
---|
137 | name: $package |
---|
138 | version: $version |
---|
139 | origin: local/$package |
---|
140 | comment: BSD-licensed PAM implementation |
---|
141 | arch: $pkgabi |
---|
142 | www: @PACKAGE_URL@ |
---|
143 | maintainer: @PACKAGE_BUGREPORT@ |
---|
144 | prefix: @prefix@ |
---|
145 | categories: [ local, security ] |
---|
146 | EOF |
---|
147 | cp "$srcdir/README" "$tmproot/+DESC" |
---|
148 | |
---|
149 | # |
---|
150 | # Generate file list |
---|
151 | # |
---|
152 | info "Generating the file list." |
---|
153 | ( |
---|
154 | echo "files: {" |
---|
155 | find -s "$tmproot@prefix@" -type f -or -type l | while read file ; do |
---|
156 | case $file in |
---|
157 | *.la) |
---|
158 | continue |
---|
159 | ;; |
---|
160 | esac |
---|
161 | mode=$(stat -f%p "$file" | cut -c 3-) |
---|
162 | file="${file#$tmproot}" |
---|
163 | echo " $file: { uname: root, gname: wheel, perm: $mode }" |
---|
164 | done |
---|
165 | echo "}" |
---|
166 | )>>"$manifest" |
---|
167 | |
---|
168 | # |
---|
169 | # Create the package |
---|
170 | # |
---|
171 | info "Creating the package." |
---|
172 | pkg create -r "$tmproot" -m "$tmproot" -o "$builddir" |
---|
173 | |
---|
174 | # |
---|
175 | # Done |
---|
176 | # |
---|
177 | info "Package created for $package-$version." |
---|