rpm.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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"/v"$VERSION".tar.gz
  39. rpmbuild -bb rpm/rpm.spec \
  40. --define "NAME $PACKAGE" \
  41. --define "VERSION $VERSION" \
  42. --define "_sourcedir $RPM_SOURCE_DIR" \
  43. --define "_builddir $RPM_BUILD_DIR" \
  44. --define "_rpmdir $RPM_SOURCE_DIR"
  45. # We put the output in a directory based on what system we've built for
  46. destdir=rpm-unknown
  47. if [ -r /etc/issue ]
  48. then
  49. grep "Red Hat.*release 7" /etc/issue >/dev/null 2>&1 && destdir=rh7
  50. grep "Red Hat.*release 8" /etc/issue >/dev/null 2>&1 && destdir=rh8
  51. grep "Red Hat.*release 9" /etc/issue >/dev/null 2>&1 && destdir=rh9
  52. if grep Fedora /etc/issue >/dev/null; then
  53. destdir=fc`grep Fedora /etc/issue | cut -d' ' -f 4`;
  54. fi
  55. fi
  56. rm -rf "$destdir"
  57. mkdir -p "$destdir"
  58. # We want to get not only the main package but devel etc, hence the middle *
  59. mv "$RPM_SOURCE_DIR"/*/"${PACKAGE}"-*"${VERSION}"*.rpm "$destdir"
  60. echo
  61. echo "The rpm package file(s) are located in $PWD/$destdir"