relocatable.sh 3.2 KB

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