OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.9 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-binary/package.sh
  6. # Copyright (C) 2007 - 2012 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. . lib/libsde.in
  16. pkg_type=
  17. pkg_name=
  18. versioned=
  19. root=
  20. usage() {
  21. cat <<EOT
  22. Creates a binary package for a given package based on it's flist
  23. Usage: ${0} --type <type> [--versioned] [--root <root>] [--output <output>] <package>
  24. type package format (tar.gz,tar.bz2,tar.lzo,gem)
  25. root location of the root of the sandbox
  26. output folder to place the binary packages
  27. package name of the package
  28. --versioned use package version in the resulting file name
  29. --nodevel do not package development files
  30. EOT
  31. }
  32. while [ $# -gt 0 ]; do
  33. case "$1" in
  34. --versioned) versioned=1 ;;
  35. --nodevel) nodevel=1 ;;
  36. --type) pkg_type="$2"; shift ;;
  37. --root) root="$2"; shift ;;
  38. --output) output="$2"; shift ;;
  39. --*) usage; exit 1 ;;
  40. *) if [ "$pkg_name" ]; then
  41. usage; exit 1
  42. else
  43. pkg_name="$1"
  44. fi ;;
  45. esac
  46. shift
  47. done
  48. if [ -z "$pkg_name" ]; then
  49. usage; exit 1
  50. elif [ ! -r "${root}/var/adm/packages/$pkg_name" ]; then
  51. echo_error "package '$pkg_name' not found."
  52. exit 2
  53. elif [ "$versioned" ]; then
  54. version=$( grep '^Package Name and Version:' "${root}/var/adm/packages/$pkg_name" | cut -f6 -d' ' )
  55. if [ -z "$version" ]; then
  56. echo_error "package '$pkg_name' is broken."
  57. exit 2
  58. fi
  59. else
  60. version=
  61. fi
  62. output="${output:-.}"
  63. case "$pkg_type" in
  64. tar.gz) compressor=gzip ;;
  65. tar.bz2) compressor=bzip2 ;;
  66. tar.lzo) compressor=lzop ;;
  67. tar.lzma) compressor=lzma ;;
  68. tar.xz) compressor=xz ;;
  69. *) # external type
  70. if [ -x "$SDEROOT/lib/sde-package/package-$pkg_type.sh" ]; then
  71. exec $SDEROOT/lib/sde-package/package-$pkg_type.sh ${versioned:+--versioned} --root "${root}" \
  72. --output "${output}" "${pkg_name}"
  73. else
  74. echo_error "packaging type '$pkg_type' not handled."
  75. exit 3
  76. fi
  77. esac
  78. echo_info "Creating binary package for '$pkg_name'"
  79. mkdir -p "$output"
  80. filename="$pkg_name${versioned:+-${version}}.$pkg_type"
  81. flist="$root/var/adm/flists/$pkg_name"
  82. tarfilename="$pkg_name${versioned:+-${version}}.tar"
  83. tmpdir=$( mktemp -d "$SDEROOT/tmp/packaging.$pkg_name.XXXXXXXX" )
  84. tmpflist="$tmpdir/var/adm/flists/$pkg_name"
  85. tmpcksum="$tmpdir/var/adm/cksums/$pkg_name"
  86. tmpmd5sum="$tmpdir/var/adm/md5sums/$pkg_name"
  87. # creating backup of var/adm files
  88. mkdir -p "$tmpdir"
  89. for x in $( grep ' var/adm' "$flist" | cut -d' ' -f2- ); do
  90. mkdir -p "$tmpdir/$(dirname $x)"
  91. cp -a "$root/$x" "$tmpdir/$x"
  92. done
  93. # pattern to filter development files
  94. if [ "$nodevel" ]; then
  95. filterpattern="-e '/\.\(c\|h\|hpp\|hxx\|o\|a\|la\|m4\|pc\)$/d;'"
  96. fi
  97. if [ ! -z "$filterpattern" ]; then
  98. eval "sed -i $filterpattern" "$tmpflist" "$tmpcksum" "$tmpmd5sum"
  99. fi
  100. # create uncompressed tar with the files from the sandbox but without var/adm
  101. ( grep -v ' var/adm' "$tmpflist" ) | cut -f2- -d' ' |
  102. tar -C "$root" -cf "$output/$tarfilename.tmp" --no-recursion --files-from=-
  103. errno=$?
  104. # add adjusted var/adm files from tmpdir to the uncompressed tar
  105. ( grep ' var/adm' "$tmpflist" ) | cut -f2- -d' ' |
  106. tar -C "$tmpdir" -rf "$output/$tarfilename.tmp" --no-recursion --files-from=-
  107. errno=$?
  108. # create the final compressed tar file
  109. eval "$compressor --stdout $output/$tarfilename.tmp > $output/$filename.tmp"
  110. errno=$?
  111. if [ "$errno" != "0" ]; then
  112. echo_error "failed to create '$output/$filename' (errno:$errno)"
  113. rm -f "$output/$tarfilename.tmp"
  114. rm -f "$output/$filename.tmp"
  115. exit 4
  116. else
  117. rm -rf "$tmpdir"
  118. rm -f "$output/$tarfilename.tmp"
  119. mv "$output/$filename.tmp" "$output/$filename"
  120. fi