1255365Sdes#!/bin/sh 2255365Sdes#- 3348980Sdes# Copyright (c) 2013-2014 Dag-Erling Sm��rgrav 4255365Sdes# All rights reserved. 5255365Sdes# 6255365Sdes# Redistribution and use in source and binary forms, with or without 7255365Sdes# modification, are permitted provided that the following conditions 8255365Sdes# are met: 9255365Sdes# 1. Redistributions of source code must retain the above copyright 10255365Sdes# notice, this list of conditions and the following disclaimer. 11255365Sdes# 2. Redistributions in binary form must reproduce the above copyright 12255365Sdes# notice, this list of conditions and the following disclaimer in the 13255365Sdes# documentation and/or other materials provided with the distribution. 14255365Sdes# 3. The name of the author may not be used to endorse or promote 15255365Sdes# products derived from this software without specific prior written 16255365Sdes# permission. 17255365Sdes# 18255365Sdes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19255365Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20255365Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21255365Sdes# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22255365Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23255365Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24255365Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25255365Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26255365Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27255365Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28255365Sdes# SUCH DAMAGE. 29255365Sdes# 30348980Sdes# $OpenPAM: mkpkgng.in 938 2017-04-30 21:34:42Z des $ 31255365Sdes# 32255365Sdes 33255365Sdes# Print an informational message 34255365Sdesinfo() { 35255365Sdes echo "mkpkgng: $@" 36255365Sdes} 37255365Sdes 38255365Sdes# Print an error message and exit 39255365Sdeserror() { 40255365Sdes echo "mkpkgng: $@" 1>&2 41255365Sdes exit 1 42255365Sdes} 43255365Sdes 44255365Sdes# Ask a yes / no question 45255365Sdesyesno() { 46255365Sdes while :; do 47255365Sdes echo -n "mkpkgng: $@ (yes/no) " 48255365Sdes read answer 49255365Sdes case $answer in 50255365Sdes [Yy]|[Yy][Ee][Ss]) 51255365Sdes return 0 52255365Sdes ;; 53255365Sdes [Nn]|[Nn][Oo]) 54255365Sdes return 1 55255365Sdes ;; 56255365Sdes esac 57255365Sdes done 58255365Sdes} 59255365Sdes 60255365Sdes# 61255365Sdes# Locate source and build directory 62255365Sdes# 63255365Sdessrcdir="@abs_top_srcdir@" 64255365Sdesbuilddir="@abs_top_builddir@" 65255365Sdescd "$srcdir" 66255365Sdes 67255365Sdes# 68255365Sdes# Determine pkgng version and ABI 69255365Sdes# 70271624Sdespkgver=$(pkg -v) 71255365Sdes[ -n "$pkgver" ] || error "Unable to determine pkgng version." 72271624Sdespkgabi=$(pkg config abi) 73255365Sdes[ -n "$pkgabi" ] || error "Unable to determine package ABI." 74255365Sdes 75255365Sdes# 76255365Sdes# Determine package name and version 77255365Sdes# 78255365Sdespackage="@PACKAGE@" 79255365Sdesversion="@PACKAGE_VERSION@" 80255365Sdesif ! expr "$version" : "[0-9]{1,}$" >/dev/null ; then 81255365Sdes svnversion="$(svnversion 2>&1)" 82255365Sdes svnversion=$(expr "$svnversion" : '\([0-9][0-9]*\)[A-Z]\{0,1\}$') 83255365Sdes if [ -n "$svnversion" ] ; then 84348980Sdes package="$package-$version" 85348980Sdes version="r$svnversion" 86255365Sdes fi 87255365Sdesfi 88255365Sdes 89255365Sdes# 90255365Sdes# Locate GNU make 91255365Sdes# 92255365Sdesif which gmake >/dev/null ; then 93255365Sdes make=gmake 94255365Sdeselse 95255365Sdes make=make 96255365Sdesfi 97255365Sdesmake="$make --no-print-directory --quiet V=0" 98255365Sdes 99255365Sdes# 100255365Sdes# Create temporary directory 101255365Sdes# 102255365Sdesinfo "Creating the temporary directory." 103255365Sdestmproot=$(mktemp -d "${TMPDIR:-/tmp}/$package-$version.XXXXXX") 104255365Sdes[ -n "$tmproot" -a -d "$tmproot" ] || \ 105255365Sdes error "Unable to create the temporary directory." 106255365Sdestrap "exit 1" INT 107255365Sdestrap "info Deleting the temporary directory. ; rm -rf '$tmproot'" EXIT 108255365Sdesset -e 109255365Sdes 110255365Sdes# 111255365Sdes# Install into tmproot 112255365Sdes# 113255365Sdesinfo "Installing into the temporary directory." 114255365Sdes$make install DESTDIR="$tmproot" 115255365Sdes 116255365Sdes# 117348980Sdes# Compress man pages 118348980Sdes# 119348980Sdesfind $tmproot -type d -name 'man[0-9]' | 120348980Sdeswhile read mandir ; do 121348980Sdes find $mandir -type f -name '*.[0-9]' | 122348980Sdes while read manpage ; do 123348980Sdes gzip "$manpage" 124348980Sdes done 125348980Sdes find $mandir -type l -name '*.[0-9]' | 126348980Sdes while read manlink ; do 127348980Sdes ln -s "$(readlink $manlink).gz" "$manlink.gz" 128348980Sdes done 129348980Sdesdone 130348980Sdes 131348980Sdes# 132255365Sdes# Generate stub manifest 133255365Sdes# 134255365Sdesinfo "Generating the stub manifest." 135255365Sdesmanifest="$tmproot/+MANIFEST" 136255365Sdescat >"$manifest" <<EOF 137255365Sdesname: $package 138255365Sdesversion: $version 139255365Sdesorigin: local/$package 140255365Sdescomment: BSD-licensed PAM implementation 141255365Sdesarch: $pkgabi 142255365Sdeswww: @PACKAGE_URL@ 143255365Sdesmaintainer: @PACKAGE_BUGREPORT@ 144255365Sdesprefix: @prefix@ 145348980Sdescategories: [ local, security ] 146255365SdesEOF 147348980Sdescp "$srcdir/README" "$tmproot/+DESC" 148255365Sdes 149255365Sdes# 150255365Sdes# Generate file list 151255365Sdes# 152255365Sdesinfo "Generating the file list." 153255365Sdes( 154348980Sdes echo "files: {" 155348980Sdes find -s "$tmproot@prefix@" -type f -or -type l | while read file ; do 156348980Sdes case $file in 157348980Sdes *.la) 158348980Sdes continue 159348980Sdes ;; 160348980Sdes esac 161255365Sdes mode=$(stat -f%p "$file" | cut -c 3-) 162255365Sdes file="${file#$tmproot}" 163255365Sdes echo " $file: { uname: root, gname: wheel, perm: $mode }" 164255365Sdes done 165348980Sdes echo "}" 166255365Sdes)>>"$manifest" 167255365Sdes 168255365Sdes# 169255365Sdes# Create the package 170255365Sdes# 171255365Sdesinfo "Creating the package." 172255365Sdespkg create -r "$tmproot" -m "$tmproot" -o "$builddir" 173255365Sdes 174255365Sdes# 175255365Sdes# Done 176255365Sdes# 177255365Sdesinfo "Package created for $package-$version." 178