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