rpm.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh -e
  2. # Run this from the 'packages' directory, just under rootdir
  3. # We can only build rpm packages, if the rpm build tools are installed
  4. if [ \! -x /usr/bin/rpmbuild ]
  5. then
  6. echo "Cannot find /usr/bin/rpmbuild. Not building an rpm." 1>&2
  7. exit 0
  8. fi
  9. # Check the commandline flags
  10. PACKAGE="$1"
  11. VERSION="$2"
  12. fullname="${PACKAGE}-${VERSION}"
  13. archive=../$fullname.tar.gz
  14. if [ -z "$1" -o -z "$2" ]
  15. then
  16. echo "Usage: $0 <package name> <package version>" 1>&2
  17. exit 0
  18. fi
  19. # Double-check we're in the packages directory, just under rootdir
  20. if [ \! -r ../Makefile -a \! -r ../INSTALL ]
  21. then
  22. echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2
  23. echo "Also, you must run \"make dist\" before running this script." 1>&2
  24. exit 0
  25. fi
  26. if [ \! -r "$archive" ]
  27. then
  28. echo "Cannot find $archive. Run \"make dist\" first." 1>&2
  29. exit 0
  30. fi
  31. # Create the directory where the input lives, and where the output should live
  32. RPM_SOURCE_DIR="/tmp/rpmsource-$fullname"
  33. RPM_BUILD_DIR="/tmp/rpmbuild-$fullname"
  34. trap 'rm -rf $RPM_SOURCE_DIR $RPM_BUILD_DIR; exit $?' EXIT SIGHUP SIGINT SIGTERM
  35. rm -rf "$RPM_SOURCE_DIR" "$RPM_BUILD_DIR"
  36. mkdir "$RPM_SOURCE_DIR"
  37. mkdir "$RPM_BUILD_DIR"
  38. cp "$archive" "$RPM_SOURCE_DIR"
  39. # rpmbuild -- as far as I can tell -- asks the OS what CPU it has.
  40. # This may differ from what kind of binaries gcc produces. dpkg
  41. # does a better job of this, so if we can run 'dpkg --print-architecture'
  42. # to get the build CPU, we use that in preference of the rpmbuild
  43. # default.
  44. target=`dpkg --print-architecture 2>/dev/null || echo ""`
  45. if [ -n "$target" ]
  46. then
  47. target=" --target $target"
  48. fi
  49. rpmbuild -bb rpm/rpm.spec $target \
  50. --define "NAME $PACKAGE" \
  51. --define "VERSION $VERSION" \
  52. --define "_sourcedir $RPM_SOURCE_DIR" \
  53. --define "_builddir $RPM_BUILD_DIR" \
  54. --define "_rpmdir $RPM_SOURCE_DIR"
  55. # We put the output in a directory based on what system we've built for
  56. destdir=rpm-unknown
  57. if [ -r /etc/issue ]
  58. then
  59. grep "Red Hat.*release 7" /etc/issue >/dev/null 2>&1 && destdir=rh7
  60. grep "Red Hat.*release 8" /etc/issue >/dev/null 2>&1 && destdir=rh8
  61. grep "Red Hat.*release 9" /etc/issue >/dev/null 2>&1 && destdir=rh9
  62. grep "Fedora Core.*release 1" /etc/issue >/dev/null 2>&1 && destdir=fc1
  63. grep "Fedora Core.*release 2" /etc/issue >/dev/null 2>&1 && destdir=fc2
  64. grep "Fedora Core.*release 3" /etc/issue >/dev/null 2>&1 && destdir=fc3
  65. fi
  66. rm -rf "$destdir"
  67. mkdir -p "$destdir"
  68. # We want to get not only the main package but devel etc, hence the middle *
  69. mv "$RPM_SOURCE_DIR"/*/"${PACKAGE}"-*"${VERSION}"*.rpm "$destdir"
  70. echo
  71. echo "The rpm package file(s) are located in $PWD/$destdir"