create_nagios_addon_rpm.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. #
  3. #/*
  4. # * Licensed to the Apache Software Foundation (ASF) under one
  5. # * or more contributor license agreements. See the NOTICE file
  6. # * distributed with this work for additional information
  7. # * regarding copyright ownership. The ASF licenses this file
  8. # * to you under the Apache License, Version 2.0 (the
  9. # * "License"); you may not use this file except in compliance
  10. # * with the License. You may obtain a copy of the License at
  11. # *
  12. # * http://www.apache.org/licenses/LICENSE-2.0
  13. # *
  14. # * Unless required by applicable law or agreed to in writing, software
  15. # * distributed under the License is distributed on an "AS IS" BASIS,
  16. # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # * See the License for the specific language governing permissions and
  18. # * limitations under the License.
  19. # */
  20. CUR_DIR=`pwd`
  21. BASEDIR="$( cd "$( dirname "$0" )" && pwd )"
  22. if [[ -z "${BUILD_DIR}" ]]; then
  23. BUILD_DIR="${BASEDIR}/build/"
  24. fi
  25. if [[ -z "${VERSION}" ]]; then
  26. VERSION=${VERSION:-1.2.2}
  27. fi
  28. if [[ -z "${RELEASE}" ]]; then
  29. RELEASE=${RELEASE:-1}
  30. fi
  31. #rm -rf ${BUILD_DIR}/*
  32. PKG_NAME="hdp_mon_nagios_addons"
  33. MON_TAR_DIR="${BUILD_DIR}/${PKG_NAME}-$VERSION/"
  34. mkdir -p "${MON_TAR_DIR}"
  35. cp -r ${BASEDIR}/../../src/addOns/nagios/* ${MON_TAR_DIR}
  36. TAR_DEST="${BUILD_DIR}/${PKG_NAME}-$VERSION.tar.gz"
  37. cd ${BUILD_DIR};
  38. tar -zcf "${TAR_DEST}" "${PKG_NAME}-$VERSION/"
  39. RPM_BUILDDIR=${BUILD_DIR}/rpmbuild/
  40. mkdir -p ${RPM_BUILDDIR}
  41. mkdir -p ${RPM_BUILDDIR}/SOURCES/
  42. mkdir -p ${RPM_BUILDDIR}/BUILD/
  43. mkdir -p ${RPM_BUILDDIR}/SPECS/
  44. mkdir -p ${RPM_BUILDDIR}/RPMS/
  45. mkdir -p ${RPM_BUILDDIR}/SRPMS/
  46. cp -f ${BASEDIR}/${PKG_NAME}.spec ${RPM_BUILDDIR}/SPECS/
  47. cp -f ${TAR_DEST} ${RPM_BUILDDIR}/SOURCES/
  48. echo "${VERSION}" > ${RPM_BUILDDIR}/SOURCES/version.txt
  49. echo "${RELEASE}" > ${RPM_BUILDDIR}/SOURCES/release.txt
  50. cd ${RPM_BUILDDIR}
  51. cmd="rpmbuild --define \"_topdir ${RPM_BUILDDIR}\" \
  52. -bb ${RPM_BUILDDIR}/SPECS/${PKG_NAME}.spec"
  53. echo $cmd
  54. eval $cmd
  55. ret=$?
  56. if [[ "$ret" != "0" ]]; then
  57. echo "Error: rpmbuild failed, error=$ret"
  58. exit 1
  59. fi
  60. cd ${CUR_DIR}
  61. RPM_DEST=`find ${RPM_BUILDDIR}/RPMS/noarch -name ${PKG_NAME}-$VERSION-$RELEASE*.rpm`
  62. if [[ ! -f "${RPM_DEST}" ]]; then
  63. echo "Error: ${RPM_DEST} does not exist"
  64. exit 1
  65. fi
  66. exit 0