mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-01-03 02:11:10 +00:00
WIP: CPE library.
This commit is contained in:
parent
cc8109c760
commit
526303caad
10 changed files with 593 additions and 0 deletions
|
@ -119,6 +119,7 @@ AC_CONFIG_FILES([
|
|||
include/cryb/Makefile
|
||||
lib/Makefile
|
||||
lib/core/Makefile
|
||||
lib/cpe/Makefile
|
||||
lib/digest/Makefile
|
||||
lib/enc/Makefile
|
||||
lib/hash/Makefile
|
||||
|
|
|
@ -6,6 +6,7 @@ cryb_HEADERS = \
|
|||
algorithm.h \
|
||||
attributes.h \
|
||||
bitwise.h \
|
||||
cpe.h \
|
||||
digest.h \
|
||||
hash.h \
|
||||
hmac.h \
|
||||
|
|
88
include/cryb/cpe.h
Normal file
88
include/cryb/cpe.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 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.
|
||||
*
|
||||
* $Cryb$
|
||||
*/
|
||||
|
||||
#ifndef CRYB_CPE_H_INCLUDED
|
||||
#define CRYB_CPE_H_INCLUDED
|
||||
|
||||
#define CPE22_VER 202
|
||||
#define CPE22_NATTR 7
|
||||
|
||||
#define CPE23_VER 203
|
||||
#define CPE23_NATTR 11
|
||||
|
||||
#define cpe_name cryb_cpe_name
|
||||
|
||||
enum cpe22_attributes {
|
||||
/* CPE 2.2 attributes */
|
||||
cpe22_part,
|
||||
cpe22_vendor,
|
||||
cpe22_product,
|
||||
cpe22_version,
|
||||
cpe22_update,
|
||||
cpe22_edition,
|
||||
cpe22_language,
|
||||
/* max */
|
||||
cpe22_nattr
|
||||
};
|
||||
|
||||
enum cpe23_attributes {
|
||||
/* CPE 2.2 attributes */
|
||||
cpe23_part = cpe22_part,
|
||||
cpe23_vendor = cpe22_vendor,
|
||||
cpe23_product = cpe22_product,
|
||||
cpe23_version = cpe22_version,
|
||||
cpe23_update = cpe22_update,
|
||||
cpe23_edition = cpe22_edition,
|
||||
cpe23_language = cpe22_language,
|
||||
/* CPE 2.3 extended attributes */
|
||||
cpe23_sw_edition,
|
||||
cpe23_target_sw,
|
||||
cpe23_target_hw,
|
||||
cpe23_other,
|
||||
/* max */
|
||||
cpe23_nattr
|
||||
};
|
||||
|
||||
struct cpe_name {
|
||||
int ver;
|
||||
int nattr;
|
||||
wchar_t *attr[];
|
||||
};
|
||||
|
||||
struct cpe_name *cpe_upgrade(const struct cpe_name *);
|
||||
struct cpe_name *cpe_from_string(const wchar_t *);
|
||||
wchar_t *cpe_to_string(const struct cpe_name *);
|
||||
struct cpe_name *cpe_from_string(const wchar_t *);
|
||||
wchar_t *cpe_to_string(const struct cpe_name *);
|
||||
struct cpe_name *cpe_from_string(const wchar_t *);
|
||||
wchar_t *cpe_to_string(const struct cpe_name *);
|
||||
|
||||
#endif
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
SUBDIRS = \
|
||||
core \
|
||||
cpe \
|
||||
digest \
|
||||
enc \
|
||||
hash \
|
||||
|
|
11
lib/cpe/Makefile.am
Normal file
11
lib/cpe/Makefile.am
Normal file
|
@ -0,0 +1,11 @@
|
|||
# $Cryb$
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
lib_LTLIBRARIES = libcryb-cpe.la
|
||||
|
||||
libcryb_cpe_la_SOURCES = \
|
||||
cpe.c \
|
||||
cpe_string.c \
|
||||
cpe_uri.c \
|
||||
cpe_wfn.c
|
158
lib/cpe/cpe.c
Normal file
158
lib/cpe/cpe.c
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 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.
|
||||
*
|
||||
* $Cryb$
|
||||
*/
|
||||
|
||||
#include "cryb/impl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <cryb/cpe.h>
|
||||
|
||||
/*
|
||||
* Free all memory allocated to a cpe structure.
|
||||
*/
|
||||
void
|
||||
cpe_destroy(struct cpe_name *cpe)
|
||||
{
|
||||
|
||||
if (cpe == NULL)
|
||||
return;
|
||||
for (int i = 0; i < cpe->nattr; ++i)
|
||||
free(cpe->attr[i]);
|
||||
free(cpe);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy one or more attributes from a source cpe structure to a
|
||||
* destination cpe structure. If an attribute in the source is NULL, the
|
||||
* corresponding attribute in the destination will be an empty string.
|
||||
*/
|
||||
static int
|
||||
cpe_copy_attr(struct cpe_name *dst, const struct cpe_name *src, int base, int nattr)
|
||||
{
|
||||
|
||||
if (base < 0 || nattr < 0 || base + nattr > src->nattr ||
|
||||
base + nattr > dst->nattr)
|
||||
return (-1);
|
||||
if (nattr == 0)
|
||||
nattr = src->nattr - base;
|
||||
for (int i = base; i < base + nattr; ++i) {
|
||||
if (src->attr[i] != NULL)
|
||||
dst->attr[i] = wcsdup(src->attr[i]);
|
||||
else
|
||||
dst->attr[i] = wcsdup(L"");
|
||||
if (dst->attr[i] == NULL)
|
||||
return (-1);
|
||||
}
|
||||
return (nattr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicate a cpe structure. Any attributes that are NULL in the source
|
||||
* will be empty strings in the destination.
|
||||
*/
|
||||
struct cpe_name *
|
||||
cpe_clone(const struct cpe_name *cpe)
|
||||
{
|
||||
struct cpe_name *ncpe;
|
||||
|
||||
ncpe = calloc(1, sizeof *ncpe +
|
||||
cpe->nattr * sizeof *ncpe->attr);
|
||||
if (ncpe == NULL)
|
||||
return (NULL);
|
||||
if (cpe_copy_attr(ncpe, cpe, 0, 0) < 0) {
|
||||
cpe_destroy(ncpe);
|
||||
return (NULL);
|
||||
}
|
||||
return (ncpe);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a new cpe structure.
|
||||
*/
|
||||
struct cpe_name *
|
||||
cpe_new(void)
|
||||
{
|
||||
struct cpe_name *ncpe;
|
||||
|
||||
if ((ncpe = calloc(1, sizeof *ncpe)) == NULL)
|
||||
return (NULL);
|
||||
ncpe->ver = CPE23_VER;
|
||||
ncpe->nattr = CPE23_NATTR;
|
||||
return (ncpe);
|
||||
}
|
||||
|
||||
/*
|
||||
* Upgrade a cpe 2.2 structure to the latest supported version.
|
||||
*/
|
||||
struct cpe_name *
|
||||
cpe_upgrade22(const struct cpe_name *cpe)
|
||||
{
|
||||
struct cpe_name *ncpe;
|
||||
|
||||
if ((ncpe = cpe_new()) == NULL)
|
||||
return (NULL);
|
||||
/* copy existing attributes */
|
||||
if (cpe_copy_attr(ncpe, cpe, 0, cpe22_nattr) < 0) {
|
||||
cpe_destroy(ncpe);
|
||||
return (NULL);
|
||||
}
|
||||
/* extended attributes? */
|
||||
if (ncpe->attr[cpe22_edition][0] == L'~') {
|
||||
/*
|
||||
* XXX pseudo-code:
|
||||
*
|
||||
* - Split into fields (return an error if there are more
|
||||
* than four)
|
||||
* - Assign these to sw_edition, target_sw, target_hw and
|
||||
* other, in that order.
|
||||
*/
|
||||
}
|
||||
return (ncpe);
|
||||
}
|
||||
|
||||
/*
|
||||
* Upgrade a cpe structure to the latest supported version.
|
||||
*/
|
||||
struct cpe_name *
|
||||
cpe_upgrade(const struct cpe_name *cpe)
|
||||
{
|
||||
|
||||
switch (cpe->ver) {
|
||||
case CPE22_VER:
|
||||
/* already latest */
|
||||
return (cpe_clone(cpe));
|
||||
case CPE23_VER:
|
||||
return (cpe_upgrade22(cpe));
|
||||
default:
|
||||
return (NULL);
|
||||
}
|
||||
}
|
52
lib/cpe/cpe_string.c
Normal file
52
lib/cpe/cpe_string.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 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.
|
||||
*
|
||||
* $Cryb$
|
||||
*/
|
||||
|
||||
#include "cryb/impl.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include <cryb/cpe.h>
|
||||
|
||||
struct cpe *
|
||||
cpe_unbind_fs(const wchar_t *str)
|
||||
{
|
||||
|
||||
(void)str;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
cpe_bind_to_fs(const struct cpe *cpe)
|
||||
{
|
||||
|
||||
(void)cpe;
|
||||
return (NULL);
|
||||
}
|
52
lib/cpe/cpe_uri.c
Normal file
52
lib/cpe/cpe_uri.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 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.
|
||||
*
|
||||
* $Cryb$
|
||||
*/
|
||||
|
||||
#include "cryb/impl.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include <cryb/cpe.h>
|
||||
|
||||
struct cpe *
|
||||
cpe_unbind_uri(const wchar_t *str)
|
||||
{
|
||||
|
||||
(void)str;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
cpe_bind_to_uri(const struct cpe *cpe)
|
||||
{
|
||||
|
||||
(void)cpe;
|
||||
return (NULL);
|
||||
}
|
52
lib/cpe/cpe_wfn.c
Normal file
52
lib/cpe/cpe_wfn.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*-
|
||||
* Copyright (c) 2014 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.
|
||||
*
|
||||
* $Cryb$
|
||||
*/
|
||||
|
||||
#include "cryb/impl.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include <cryb/cpe.h>
|
||||
|
||||
struct cpe *
|
||||
cpe_from_wfn(const wchar_t *str)
|
||||
{
|
||||
|
||||
(void)str;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
cpe_to_wfn(const struct cpe *cpe)
|
||||
{
|
||||
|
||||
(void)cpe;
|
||||
return (NULL);
|
||||
}
|
177
mkpkgng.in
Normal file
177
mkpkgng.in
Normal file
|
@ -0,0 +1,177 @@
|
|||
#!/bin/sh
|
||||
#-
|
||||
# Copyright (c) 2013-2014 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 787 2014-03-10 15:43:17Z 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 -v)
|
||||
[ -n "$pkgver" ] || error "Unable to determine pkgng version."
|
||||
pkgabi=$(pkg config abi)
|
||||
[ -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"
|
||||
|
||||
#
|
||||
# Compress man pages
|
||||
#
|
||||
find $tmproot -type d -name 'man[0-9]' |
|
||||
while read mandir ; do
|
||||
find $mandir -type f -name '*.[0-9]' |
|
||||
while read manpage ; do
|
||||
gzip "$manpage"
|
||||
done
|
||||
done
|
||||
|
||||
#
|
||||
# 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."
|
Loading…
Reference in a new issue