relocatable.sh 3.1 KB

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