get_hue_version.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. set -x
  18. TMP_DIR=/tmp/$(basename "$0" | awk -F\. '{print $1}')
  19. HUE_VERSION=$1
  20. if [[ -d /opt/cloudera/parcels/CDH/lib/hue-${HUE_VERSION} ]]
  21. then
  22. echo "This version already downloaded"
  23. exit 1
  24. fi
  25. HUE_MAJOR=$(echo ${HUE_VERSION} | cut -f1 -d.)
  26. OS_CDH_VERSION=$(basename $(hadoop version | grep "\.jar" | awk '{print $6}') | awk -Fcdh '{print $2}' | awk -F\. '{print $1}')
  27. OS_EL_VERSION="el$(lsb_release -rs | cut -f1 -d.)"
  28. HUE_VERSION_TEST=
  29. if [[ ${HUE_MAJOR} -eq 5 ]]
  30. then
  31. HUE_VERSION_TEST=$(echo ${HUE_VERSION} | grep "^[0-9]\.[0-9][0-9]\.[0-9]$")
  32. ARCHIVE_BASE_URL=https://archive.cloudera.com/cdh${HUE_MAJOR}/parcels/${HUE_VERSION}/
  33. elif [[ ${HUE_MAJOR} -eq 6 ]]
  34. then
  35. HUE_VERSION_TEST=$(echo ${HUE_VERSION} | grep "^[0-9]\.[0-9]\.[0-9]$")
  36. ARCHIVE_BASE_URL=https://archive.cloudera.com/cdh${HUE_MAJOR}/${HUE_VERSION}/parcels/
  37. elif [[ ${HUE_MAJOR} -eq 7 ]]
  38. then
  39. HUE_VERSION_TEST=$(echo ${HUE_VERSION} | grep "^[0-9]\.[0-9]\.[0-9]$")
  40. ARCHIVE_BASE_URL=https://archive.cloudera.com/cdh${HUE_MAJOR}/${HUE_VERSION}/parcels/
  41. else
  42. echo "Major version was ${HUE_MAJOR} this script only works on major version 5, 6, 7"
  43. exit 1
  44. fi
  45. if [[ -z ${HUE_VERSION_TEST} ]]
  46. then
  47. echo "Invalid Hue version, example of good 5.16.0 or 6.3.2"
  48. exit 1
  49. fi
  50. if [[ ! -f /etc/redhat-release ]]
  51. then
  52. echo "This is not RedHat, Oracle Linux or CentOS, this script only works on those OS's"
  53. exit 1
  54. fi
  55. PARCEL_NAME=$(curl -s ${ARCHIVE_BASE_URL} | grep "${OS_EL_VERSION}.parcel<" | sed "s/.*href=\"//g" | sed "s/\">.*//g")
  56. if [[ ! -z ${PARCEL_NAME} ]]
  57. then
  58. PARCEL_DIR_NAME=$(echo ${PARCEL_NAME} | sed "s/\-${OS_EL_VERSION}.*//g")
  59. mkdir -p ${TMP_DIR}
  60. cd ${TMP_DIR} && wget ${ARCHIVE_BASE_URL}/${PARCEL_NAME}
  61. cd ${TMP_DIR} && tar xvf ${PARCEL_NAME}
  62. if [[ ! -d /opt/cloudera/parcels/CDH/lib/hue-${HUE_VERSION} ]]
  63. then
  64. cd ${TMP_DIR} && mv ${PARCEL_DIR_NAME}/lib/hue /opt/cloudera/parcels/CDH/lib/hue-${HUE_VERSION}
  65. fi
  66. else
  67. echo "${HUE_VERSION} does not exist"
  68. fi
  69. cd && rm -Rf ${TMP_DIR}