summaryrefslogtreecommitdiffstats
path: root/contrib/openpam/mkpkgng.in
blob: 31efc84a60267e7ba02941812b21e5c75357451b (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
#-
# Copyright (c) 2013 Dag-Erling Smørgrav
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote
#    products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id: mkpkgng.in 740 2013-09-07 13:03:20Z des $
#

# Print an informational message
info() {
	echo "mkpkgng: $@"
}

# Print an error message and exit
error() {
	echo "mkpkgng: $@" 1>&2
	exit 1
}

# Ask a yes / no question
yesno() {
        while :; do
                echo -n "mkpkgng: $@ (yes/no) "
                read answer
                case $answer in
                [Yy]|[Yy][Ee][Ss])
                        return 0
                        ;;
                [Nn]|[Nn][Oo])
                        return 1
                        ;;
                esac
        done
}

#
# Locate source and build directory
#
srcdir="@abs_top_srcdir@"
[ -f "$srcdir/include/security/openpam.h" ] || \
    error "Unable to locate source directory."
builddir="@abs_top_builddir@"
cd "$srcdir"

#
# Determine pkgng version and ABI
#
pkgver=$(pkg -vv | awk '$1 == "Version:" { print $2 }')
[ -n "$pkgver" ] || error "Unable to determine pkgng version."
pkgabi=$(pkg -vv | awk '$1 == "ABI:" { print $2 }')
[ -n "$pkgabi" ] || error "Unable to determine package ABI."

#
# Determine package name and version
#
package="@PACKAGE@"
version="@PACKAGE_VERSION@"
if ! expr "$version" : "[0-9]{1,}$" >/dev/null ; then
	svnversion="$(svnversion 2>&1)"
	svnversion=$(expr "$svnversion" : '\([0-9][0-9]*\)[A-Z]\{0,1\}$')
	if [ -n "$svnversion" ] ; then
		version="$version-r${svnversion}"
	fi
fi

#
# Locate GNU make
#
if which gmake >/dev/null ; then
	make=gmake
else
	make=make
fi
make="$make --no-print-directory --quiet V=0"

#
# Create temporary directory
#
info "Creating the temporary directory."
tmproot=$(mktemp -d "${TMPDIR:-/tmp}/$package-$version.XXXXXX")
[ -n "$tmproot" -a -d "$tmproot" ] || \
    error "Unable to create the temporary directory."
trap "exit 1" INT
trap "info Deleting the temporary directory. ; rm -rf '$tmproot'" EXIT
set -e

#
# Install into tmproot
#
info "Installing into the temporary directory."
$make install DESTDIR="$tmproot"

#
# Generate stub manifest
#
info "Generating the stub manifest."
manifest="$tmproot/+MANIFEST"
cat >"$manifest" <<EOF
name: $package
version: $version
origin: local/$package
comment: BSD-licensed PAM implementation
arch: $pkgabi
www: @PACKAGE_URL@
maintainer: @PACKAGE_BUGREPORT@
prefix: @prefix@
desc:
  OpenPAM is an open source PAM library that focuses on simplicity,
  correctness, and cleanliness.
  
  OpenPAM aims to gather the best features of Solaris PAM, XSSO and
  Linux-PAM, plus some innovations of its own.  In areas where these
  implementations disagree, OpenPAM tries to remain compatible with
  Solaris, at the expense of XSSO conformance and Linux-PAM
  compatibility.
categories: local, security
EOF

#
# Generate file list
#
info "Generating the file list."
(
	echo "files:"
	find -s "$tmproot" -type f | while read file ; do
		[ "$file" = "$manifest" ] && continue
		mode=$(stat -f%p "$file" | cut -c 3-)
		file="${file#$tmproot}"
		echo "  $file: { uname: root, gname: wheel, perm: $mode }"
	done
)>>"$manifest"

#
# Create the package
#
info "Creating the package."
pkg create -r "$tmproot" -m "$tmproot" -o "$builddir"

#
# Done
#
info "Package created for $package-$version."
OpenPOWER on IntegriCloud