diff --git a/lib/sde-package/package-gem.sh b/lib/sde-package/package-gem.sh new file mode 100644 index 0000000..6c2db09 --- /dev/null +++ b/lib/sde-package/package-gem.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: lib/sde-package/package-gem.sh +# Copyright (C) 2007 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_name= +versioned= +root= + +usage() { +cat <] [--output ] + 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 +EOT +} + +while [ $# -gt 0 ]; do + case "$1" in + --versioned) versioned=1 ;; + --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:-.}" +filename="${pkg_name}${versioned:+-${version}}" + +if $SDEROOT/lib/sde-package/package.sh --type "tar.bz2" ${versioned:+--versioned} --root "${root}" \ + --output "${output}" "${pkg_name}"; then + echo_status "Converting into GEM format ..." + + mine -C "${root}/var/adm" "$output/$filename.tar.bz2" "$pkg_name" \ + "$output/$filename.gem.tmp" + errno=$? + if [ "$?" != 0 ]; then + echo_error "Failed to create '$output/$filename.gem'" + rm -f "$output/$filename.gem.tmp" + else + mv "$output/$filename.gem{.tmp,}" + fi + + echo_status "Removing temporary ${filename}tar.bz2 file" + rm -f "$output/$filename.tar.bz2" + + exit $errno +fi diff --git a/lib/sde-package/package.sh b/lib/sde-package/package.sh new file mode 100755 index 0000000..f0ff698 --- /dev/null +++ b/lib/sde-package/package.sh @@ -0,0 +1,102 @@ +#!/bin/sh +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: lib/sde-package/package.sh +# Copyright (C) 2007 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 < [--versioned] [--root ] [--output ] + 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 +EOT +} + +while [ $# -gt 0 ]; do + case "$1" in + --versioned) versioned=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 "$type" in + tar.gz) compressor=gzip ;; + tar.bz2) compressor=bzip2 ;; + tar.lzo) compressor=lzop ;; + *) # external type + if [ -x "$SDEROOT/lib/sde-package/package-$type.sh" ]; then + exec $SDEROOT/lib/sde-package/package-$type.sh ${versioned:+--versioned} --root "${root}" \ + --output "${output}" "${pkg_name}" + else + echo_error "packaging type '$type' not handled." + exit 3 + fi +esac + +echo_info "Creating binary package for '$pkg_name' ..." +mkdir -p "$output" + +filename="$pkg_name${versioned:+-${version}}.$type" +flist="$root/var/adm/flists/$pkg_name" + +( grep ' var/adm' "$flist" + grep -v ' var/adm' "$flist" ) | cut -f2- -d' ' | + tar -C "$root" -cf- --no-recursion --files-from=- | + $compressor > "$output/$filename.tmp" +errno=$? + +if [ "$errno" != "0" ]; then + echo_error "failed to create '$output/$filename' (errno:$errno)" + rm -f "$output/$filename.tmp" + exit 4 +else + mv "$output/$filename{.tmp,}" +fi