#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: lib/sde-binary/package.sh
|
|
# Copyright (C) 2007 - 2012 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
. lib/libsde.in
|
|
|
|
pkg_type=
|
|
pkg_name=
|
|
versioned=
|
|
root=
|
|
|
|
usage() {
|
|
cat <<EOT
|
|
Creates a binary package for a given package based on it's flist
|
|
|
|
Usage: ${0} --type <type> [--versioned] [--root <root>] [--output <output>] <package>
|
|
type package format (tar.gz,tar.bz2,tar.lzo,gem)
|
|
root location of the root of the sandbox
|
|
output folder to place the binary packages
|
|
package name of the package
|
|
|
|
--versioned use package version in the resulting file name
|
|
--nodevel do not package development files
|
|
EOT
|
|
}
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--versioned) versioned=1 ;;
|
|
--nodevel) nodevel=1 ;;
|
|
--type) pkg_type="$2"; shift ;;
|
|
--root) root="$2"; shift ;;
|
|
--output) output="$2"; shift ;;
|
|
--*) usage; exit 1 ;;
|
|
*) if [ "$pkg_name" ]; then
|
|
usage; exit 1
|
|
else
|
|
pkg_name="$1"
|
|
fi ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [ -z "$pkg_name" ]; then
|
|
usage; exit 1
|
|
elif [ ! -r "${root}/var/adm/packages/$pkg_name" ]; then
|
|
echo_error "package '$pkg_name' not found."
|
|
exit 2
|
|
elif [ "$versioned" ]; then
|
|
version=$( grep '^Package Name and Version:' "${root}/var/adm/packages/$pkg_name" | cut -f6 -d' ' )
|
|
if [ -z "$version" ]; then
|
|
echo_error "package '$pkg_name' is broken."
|
|
exit 2
|
|
fi
|
|
else
|
|
version=
|
|
fi
|
|
|
|
output="${output:-.}"
|
|
|
|
case "$pkg_type" in
|
|
tar.gz) compressor=gzip ;;
|
|
tar.bz2) compressor=bzip2 ;;
|
|
tar.lzo) compressor=lzop ;;
|
|
tar.lzma) compressor=lzma ;;
|
|
tar.xz) compressor=xz ;;
|
|
*) # external type
|
|
if [ -x "$SDEROOT/lib/sde-package/package-$pkg_type.sh" ]; then
|
|
exec $SDEROOT/lib/sde-package/package-$pkg_type.sh ${versioned:+--versioned} --root "${root}" \
|
|
--output "${output}" "${pkg_name}"
|
|
else
|
|
echo_error "packaging type '$pkg_type' not handled."
|
|
exit 3
|
|
fi
|
|
esac
|
|
|
|
echo_info "Creating binary package for '$pkg_name'"
|
|
mkdir -p "$output"
|
|
|
|
filename="$pkg_name${versioned:+-${version}}.$pkg_type"
|
|
flist="$root/var/adm/flists/$pkg_name"
|
|
|
|
tarfilename="$pkg_name${versioned:+-${version}}.tar"
|
|
|
|
tmpdir=$( mktemp -d "$SDEROOT/tmp/packaging.$pkg_name.XXXXXXXX" )
|
|
tmpflist="$tmpdir/var/adm/flists/$pkg_name"
|
|
tmpcksum="$tmpdir/var/adm/cksums/$pkg_name"
|
|
tmpmd5sum="$tmpdir/var/adm/md5sums/$pkg_name"
|
|
|
|
# creating backup of var/adm files
|
|
mkdir -p "$tmpdir"
|
|
|
|
for x in $( grep ' var/adm' "$flist" | cut -d' ' -f2- ); do
|
|
mkdir -p "$tmpdir/$(dirname $x)"
|
|
cp -a "$root/$x" "$tmpdir/$x"
|
|
done
|
|
|
|
# pattern to filter development files
|
|
if [ "$nodevel" ]; then
|
|
filterpattern="-e '/\.\(c\|h\|hpp\|hxx\|o\|a\|la\|m4\|pc\)$/d;'"
|
|
fi
|
|
|
|
if [ ! -z "$filterpattern" ]; then
|
|
eval "sed -i $filterpattern" "$tmpflist" "$tmpcksum" "$tmpmd5sum"
|
|
fi
|
|
|
|
# create uncompressed tar with the files from the sandbox but without var/adm
|
|
( grep -v ' var/adm' "$tmpflist" ) | cut -f2- -d' ' |
|
|
tar -C "$root" -cf "$output/$tarfilename.tmp" --no-recursion --files-from=-
|
|
errno=$?
|
|
|
|
# add adjusted var/adm files from tmpdir to the uncompressed tar
|
|
( grep ' var/adm' "$tmpflist" ) | cut -f2- -d' ' |
|
|
tar -C "$tmpdir" -rf "$output/$tarfilename.tmp" --no-recursion --files-from=-
|
|
errno=$?
|
|
|
|
# create the final compressed tar file
|
|
eval "$compressor --stdout $output/$tarfilename.tmp > $output/$filename.tmp"
|
|
errno=$?
|
|
|
|
if [ "$errno" != "0" ]; then
|
|
echo_error "failed to create '$output/$filename' (errno:$errno)"
|
|
rm -f "$output/$tarfilename.tmp"
|
|
rm -f "$output/$filename.tmp"
|
|
exit 4
|
|
else
|
|
rm -rf "$tmpdir"
|
|
rm -f "$output/$tarfilename.tmp"
|
|
mv "$output/$filename.tmp" "$output/$filename"
|
|
fi
|