Ronald Oussoren | 0e5b70d | 2006-06-07 18:58:42 +0000 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | echo "This script will update your shell profile when the 'bin' directory" |
| 4 | echo "of python is not early enough of the PATH of your shell." |
| 5 | echo "These changes will be effective only in shell windows that you open" |
| 6 | echo "after running this script." |
| 7 | |
| 8 | PYVER=@PYVER@ |
| 9 | PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/Current" |
| 10 | |
| 11 | # Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH. |
| 12 | BSH="`basename "${SHELL}"`" |
| 13 | case "${BSH}" in |
| 14 | bash|ksh|sh|*csh) |
| 15 | P="`${SHELL} -c 'echo $PATH'`" |
| 16 | ;; |
| 17 | *) |
| 18 | echo "Sorry, I don't know how to patch $BSH shells" |
| 19 | exit 0 |
| 20 | ;; |
| 21 | esac |
| 22 | |
| 23 | # Now ensure that our bin directory is on $P and before /usr/bin at that |
| 24 | for elem in `echo $P | tr ':' ' '` |
| 25 | do |
| 26 | if [ "${elem}" == "${PYTHON_ROOT}/bin" ]; then |
| 27 | echo "All right, you're a python lover already" |
| 28 | exit 0 |
| 29 | elif [ "${elem}" == "/usr/bin" ]; then |
| 30 | break |
| 31 | fi |
| 32 | done |
| 33 | |
| 34 | echo "${PYTHON_ROOT}/bin is not on your PATH or at least not early enough" |
| 35 | case "${BSH}" in |
| 36 | *csh) |
| 37 | # Create backup copy before patching |
| 38 | if [ -f "${HOME}/.cshrc" ]; then |
| 39 | cp -fp "${HOME}/.cshrc" "${HOME}/.cshrc.pysave" |
| 40 | fi |
| 41 | echo "" >> "${HOME}/.cshrc" |
| 42 | echo "# Setting PATH for MacPython ${PYVER}" >> "${HOME}/.cshrc" |
| 43 | echo "# The orginal version is saved in .cshrc.pysave" >> "${HOME}/.cshrc" |
| 44 | echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${HOME}/.cshrc" |
| 45 | exit 0 |
| 46 | ;; |
| 47 | bash) |
| 48 | if [ -e "${HOME}/.profile" ]; then |
| 49 | PR="${HOME}/.profile" |
| 50 | else |
| 51 | PR="${HOME}/.bash_profile" |
| 52 | fi |
| 53 | ;; |
| 54 | *sh) |
| 55 | PR="${HOME}/.profile" |
| 56 | ;; |
| 57 | esac |
| 58 | |
| 59 | # Create backup copy before patching |
| 60 | if [ -f "${PR}" ]; then |
| 61 | cp -fp "${PR}" "${PR}.pysave" |
| 62 | fi |
| 63 | echo "" >> "${PR}" |
| 64 | echo "# Setting PATH for MacPython ${PYVER}" >> "${PR}" |
| 65 | echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}" |
| 66 | echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}" |
| 67 | echo 'export PATH' >> "${PR}" |
| 68 | if [ `id -ur` = 0 ]; then |
| 69 | chown "${LOGNAME}" "${PR}" |
| 70 | fi |
| 71 | exit 0 |