create_nagios_addon_rpm.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. cp -r ${BASEDIR}/../../../nagios-alerts/* ${MON_TAR_DIR}
  37. TAR_DEST="${BUILD_DIR}/${PKG_NAME}-$VERSION.tar.gz"
  38. cd ${BUILD_DIR};
  39. tar -zcf "${TAR_DEST}" "${PKG_NAME}-$VERSION/"
  40. RPM_BUILDDIR=${BUILD_DIR}/rpmbuild/
  41. mkdir -p ${RPM_BUILDDIR}
  42. mkdir -p ${RPM_BUILDDIR}/SOURCES/
  43. mkdir -p ${RPM_BUILDDIR}/BUILD/
  44. mkdir -p ${RPM_BUILDDIR}/SPECS/
  45. mkdir -p ${RPM_BUILDDIR}/RPMS/
  46. mkdir -p ${RPM_BUILDDIR}/SRPMS/
  47. cp -f ${BASEDIR}/${PKG_NAME}.spec ${RPM_BUILDDIR}/SPECS/
  48. cp -f ${TAR_DEST} ${RPM_BUILDDIR}/SOURCES/
  49. echo "${VERSION}" > ${RPM_BUILDDIR}/SOURCES/version.txt
  50. echo "${RELEASE}" > ${RPM_BUILDDIR}/SOURCES/release.txt
  51. cd ${RPM_BUILDDIR}
  52. cmd="rpmbuild --define \"_topdir ${RPM_BUILDDIR}\" \
  53. -bb ${RPM_BUILDDIR}/SPECS/${PKG_NAME}.spec"
  54. echo $cmd
  55. eval $cmd
  56. ret=$?
  57. if [[ "$ret" != "0" ]]; then
  58. echo "Error: rpmbuild failed, error=$ret"
  59. exit 1
  60. fi
  61. cd ${CUR_DIR}
  62. RPM_DEST=`find ${RPM_BUILDDIR}/RPMS/noarch -name ${PKG_NAME}-$VERSION-$RELEASE*.rpm`
  63. if [[ ! -f "${RPM_DEST}" ]]; then
  64. echo "Error: ${RPM_DEST} does not exist"
  65. exit 1
  66. fi
  67. exit 0