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.

102 lines
2.6 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 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. EOT
  30. }
  31. while [ $# -gt 0 ]; do
  32. case "$1" in
  33. --versioned) versioned=1 ;;
  34. --type) pkg_type="$2"; shift ;;
  35. --root) root="$2"; shift ;;
  36. --output) output="$2"; shift ;;
  37. --*) usage; exit 1 ;;
  38. *) if [ "$pkg_name" ]; then
  39. usage; exit 1
  40. else
  41. pkg_name="$1"
  42. fi ;;
  43. esac
  44. shift
  45. done
  46. if [ -z "$pkg_name" ]; then
  47. usage; exit 1
  48. elif [ ! -r "${root}/var/adm/packages/$pkg_name" ]; then
  49. echo_error "package '$pkg_name' not found."
  50. exit 2
  51. elif [ "$versioned" ]; then
  52. version=$( grep '^Package Name and Version:' "${root}/var/adm/packages/$pkg_name" | cut -f6 -d' ' )
  53. if [ -z "$version" ]; then
  54. echo_error "package '$pkg_name' is broken."
  55. exit 2
  56. fi
  57. else
  58. version=
  59. fi
  60. output="${output:-.}"
  61. case "$pkg_type" in
  62. tar.gz) compressor=gzip ;;
  63. tar.bz2) compressor=bzip2 ;;
  64. tar.lzo) compressor=lzop ;;
  65. *) # external type
  66. if [ -x "$SDEROOT/lib/sde-package/package-$pkg_type.sh" ]; then
  67. exec $SDEROOT/lib/sde-package/package-$pkg_type.sh ${versioned:+--versioned} --root "${root}" \
  68. --output "${output}" "${pkg_name}"
  69. else
  70. echo_error "packaging type '$pkg_type' not handled."
  71. exit 3
  72. fi
  73. esac
  74. echo_info "Creating binary package for '$pkg_name'"
  75. mkdir -p "$output"
  76. filename="$pkg_name${versioned:+-${version}}.$pkg_type"
  77. flist="$root/var/adm/flists/$pkg_name"
  78. ( grep ' var/adm' "$flist"
  79. grep -v ' var/adm' "$flist" ) | cut -f2- -d' ' |
  80. tar -C "$root" -cf- --no-recursion --files-from=- |
  81. $compressor > "$output/$filename.tmp"
  82. errno=$?
  83. if [ "$errno" != "0" ]; then
  84. echo_error "failed to create '$output/$filename' (errno:$errno)"
  85. rm -f "$output/$filename.tmp"
  86. exit 4
  87. else
  88. mv "$output/$filename"{.tmp,}
  89. fi