relocatable.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 -e
  18. usage() {
  19. echo "
  20. Make a Hue installation relocatable. Run this in the installation
  21. directory created by 'make install', before you relocate it.
  22. Usage:
  23. $0
  24. "
  25. exit 1
  26. }
  27. if [ $# != 0 ] ; then
  28. usage
  29. fi
  30. find_os() {
  31. unameOut="$(uname -s)"
  32. case "${unameOut}" in
  33. Linux*) machine=Linux;;
  34. Darwin*) machine=Mac;;
  35. CYGWIN*) machine=Cygwin;;
  36. MINGW*) machine=MinGw;;
  37. *) machine="UNKNOWN:${unameOut}"
  38. esac
  39. echo ${machine}
  40. }
  41. find_home() {
  42. runningos=$(find_os)
  43. WORK_DIR=""
  44. if [[ ${runningos} == "Linux" ]]; then
  45. WORK_DIR=$(dirname "$(readlink -f "$0" || echo "$argv0")")
  46. elif [[ ${runningos} == "Mac" ]]; then
  47. WORK_DIR="$( cd "$( dirname "$argv0" )" && pwd )"
  48. else
  49. echo "Not Supported " $runningos
  50. exit 1
  51. fi
  52. echo ${WORK_DIR}
  53. }
  54. # We're in <hue_root>/tools
  55. CURR_DIR=$(find_home)
  56. if [[ $CURR_DIR == */hue ]]; then
  57. HUE_ROOT=$CURR_DIR
  58. elif [[ $CURR_DIR == */tools ]]; then
  59. HUE_ROOT=$(dirname $CURR_DIR)
  60. fi
  61. ENV_PYTHON="$HUE_ROOT/build/env/bin/python"
  62. VIRTUAL_BOOTSTRAP="$CURR_DIR/virtual-bootstrap/virtual-bootstrap.py"
  63. if [[ ! -e $ENV_PYTHON ]]; then
  64. echo "Is $ENV_PYTHON available?"
  65. echo "Failing to perform relocataion"
  66. exit 127
  67. fi
  68. if [[ ! -e $VIRTUAL_BOOTSTRAP ]]; then
  69. echo "Is $VIRTUAL_BOOTSTRAP available?"
  70. echo "Failing to perform relocataion"
  71. exit 127
  72. fi
  73. export PATH=$(dirname $ENV_PYTHON):$PATH
  74. PYVER=$($ENV_PYTHON -V 2>&1 | awk '{print $2}' | cut -d '.' -f 1,2)
  75. MIN_VERSION="3.8"
  76. # Step 1. Fix virtualenv
  77. if [[ $PYVER == $MIN_VERSION || $PYVER == $MIN_VERSION.* || $PYVER > $MIN_VERSION ]]; then
  78. echo "Python version is 3.8 or greater"
  79. pushd .
  80. cd $HUE_ROOT
  81. virtualenv-make-relocatable "build/env"
  82. $ENV_PYTHON $VIRTUAL_BOOTSTRAP --relocatable_pth "build/env"
  83. popd
  84. else
  85. echo "Python version is less than 3.8"
  86. if [ -e "$HUE_ROOT/tools/enable-python27.sh" ]; then
  87. source $HUE_ROOT/tools/enable-python27.sh
  88. fi
  89. $ENV_PYTHON $VIRTUAL_BOOTSTRAP --relocatable "$HUE_ROOT/build/env"
  90. fi
  91. # Step 1b. Fix any broken lib64 directory
  92. LIB64="$HUE_ROOT/build/env/lib64"
  93. if [ -L "$LIB64" -a ! -e "$LIB64" ] ; then
  94. rm "$LIB64"
  95. ln -s lib "$LIB64"
  96. fi
  97. # Step 2. Fix .ini symlinks for all apps (make them relative)
  98. for app in $HUE_ROOT/apps/* ; do
  99. if [ -d "$app/conf" ] ; then
  100. appname=$(basename $app)
  101. pushd "$HUE_ROOT/desktop/conf"
  102. ln -sfv ../../apps/$appname/conf/*.ini .
  103. popd
  104. fi
  105. done
  106. # Step 3. Clean up any old .pyc files
  107. find "$HUE_ROOT" . -name "*.pyc" -exec rm -f {} \;