/Mac/BuildScript/scripts/postflight.patch-profile

http://unladen-swallow.googlecode.com/ · Shell · 96 lines · 83 code · 7 blank · 6 comment · 9 complexity · f19fdbd6bb8cf2238f7359e0356cbd30 MD5 · raw file

  1. #!/bin/sh
  2. echo "This script will update your shell profile when the 'bin' directory"
  3. echo "of python is not early enough of the PATH of your shell."
  4. echo "These changes will be effective only in shell windows that you open"
  5. echo "after running this script."
  6. PYVER="@PYVER@"
  7. PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/@PYVER@"
  8. if [ `id -ur` = 0 ]; then
  9. # Run from the installer, do some trickery to fetch the information
  10. # we need.
  11. theShell="`finger $USER | grep Shell: | head -1 | awk '{ print $NF }'`"
  12. else
  13. theShell="${SHELL}"
  14. fi
  15. # Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH.
  16. BSH="`basename "${theShell}"`"
  17. case "${BSH}" in
  18. bash|ksh|sh|*csh)
  19. if [ `id -ur` = 0 ]; then
  20. P=`su - ${USER} -c 'echo A-X-4-X@@$PATH@@X-4-X-A' | grep 'A-X-4-X@@.*@@X-4-X-A' | sed -e 's/^A-X-4-X@@//g' -e 's/@@X-4-X-A$//g'`
  21. else
  22. P="`(exec -l ${theShell} -c 'echo $PATH')`"
  23. fi
  24. ;;
  25. *)
  26. echo "Sorry, I don't know how to patch $BSH shells"
  27. exit 0
  28. ;;
  29. esac
  30. # Now ensure that our bin directory is on $P and before /usr/bin at that
  31. for elem in `echo $P | tr ':' ' '`
  32. do
  33. if [ "${elem}" == "${PYTHON_ROOT}/bin" ]; then
  34. echo "All right, you're a python lover already"
  35. exit 0
  36. elif [ "${elem}" == "/usr/bin" ]; then
  37. break
  38. fi
  39. done
  40. echo "${PYTHON_ROOT}/bin is not on your PATH or at least not early enough"
  41. case "${BSH}" in
  42. *csh)
  43. if [ -f "${HOME}/.tcshrc" ]; then
  44. RC="${HOME}/.tcshrc"
  45. else
  46. RC="${HOME}/.cshrc"
  47. fi
  48. # Create backup copy before patching
  49. if [ -f "${RC}" ]; then
  50. cp -fp "${RC}" "${RC}.pysave"
  51. fi
  52. echo "" >> "${RC}"
  53. echo "# Setting PATH for MacPython ${PYVER}" >> "${RC}"
  54. echo "# The orginal version is saved in .cshrc.pysave" >> "${RC}"
  55. echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${RC}"
  56. if [ `id -ur` = 0 ]; then
  57. chown "${USER}" "${RC}"
  58. fi
  59. exit 0
  60. ;;
  61. bash)
  62. if [ -e "${HOME}/.bash_profile" ]; then
  63. PR="${HOME}/.bash_profile"
  64. elif [ -e "${HOME}/.bash_login" ]; then
  65. PR="${HOME}/.bash_login"
  66. elif [ -e "${HOME}/.profile" ]; then
  67. PR="${HOME}/.profile"
  68. else
  69. PR="${HOME}/.bash_profile"
  70. fi
  71. ;;
  72. *sh)
  73. PR="${HOME}/.profile"
  74. ;;
  75. esac
  76. # Create backup copy before patching
  77. if [ -f "${PR}" ]; then
  78. cp -fp "${PR}" "${PR}.pysave"
  79. fi
  80. echo "" >> "${PR}"
  81. echo "# Setting PATH for MacPython ${PYVER}" >> "${PR}"
  82. echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}"
  83. echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}"
  84. echo 'export PATH' >> "${PR}"
  85. if [ `id -ur` = 0 ]; then
  86. chown "${USER}" "${PR}"
  87. fi
  88. exit 0