relocatable.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # Step 1. Fix virtualenv
  76. if [[ "$PYVER" == "3."[8-9]* || "$PYVER" == "3.10" ]]; then
  77. echo "Python version is 3.8 or greater"
  78. pushd .
  79. cd $HUE_ROOT
  80. virtualenv-make-relocatable "build/env"
  81. $ENV_PYTHON $VIRTUAL_BOOTSTRAP --relocatable_pth "build/env"
  82. popd
  83. fi
  84. # Step 1b. Fix any broken lib64 directory
  85. LIB64="$HUE_ROOT/build/env/lib64"
  86. if [ -L "$LIB64" -a ! -e "$LIB64" ] ; then
  87. rm "$LIB64"
  88. ln -s lib "$LIB64"
  89. fi
  90. # Step 2. Fix .ini symlinks for all apps (make them relative)
  91. for app in $HUE_ROOT/apps/* ; do
  92. if [ -d "$app/conf" ] ; then
  93. appname=$(basename $app)
  94. pushd "$HUE_ROOT/desktop/conf"
  95. ln -sfv ../../apps/$appname/conf/*.ini .
  96. popd
  97. fi
  98. done
  99. # Step 3. Clean up any old .pyc files
  100. find "$HUE_ROOT" . -name "*.pyc" -exec rm -f {} \;