blob: 5e82f331cfa32a83015a8216f1f3e71cfdc489bc [file] [log] [blame]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001#!/bin/sh
2
3echo "This script will update your shell profile when the 'bin' directory"
4echo "of python is not early enough of the PATH of your shell."
5echo "These changes will be effective only in shell windows that you open"
6echo "after running this script."
7
Thomas Wouters0e3f5912006-08-11 14:57:12 +00008PYVER=2.5
Thomas Wouters477c8d52006-05-27 19:21:47 +00009PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/Current"
10
Thomas Wouters0e3f5912006-08-11 14:57:12 +000011if [ `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
16else
17 theShell="${SHELL}"
18fi
19
Thomas Wouters477c8d52006-05-27 19:21:47 +000020# Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH.
Thomas Wouters0e3f5912006-08-11 14:57:12 +000021BSH="`basename "${theShell}"`"
Thomas Wouters477c8d52006-05-27 19:21:47 +000022case "${BSH}" in
23bash|ksh|sh|*csh)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000024 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 Wouters477c8d52006-05-27 19:21:47 +000029 ;;
30*)
31 echo "Sorry, I don't know how to patch $BSH shells"
32 exit 0
33 ;;
34esac
35
36# Now ensure that our bin directory is on $P and before /usr/bin at that
37for elem in `echo $P | tr ':' ' '`
38do
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
45done
46
47echo "${PYTHON_ROOT}/bin is not on your PATH or at least not early enough"
48case "${BSH}" in
49*csh)
Thomas Wouters89f507f2006-12-13 04:49:30 +000050 if [ -f "${HOME}/.tcshrc" ]; then
51 RC="${HOME}/.tcshrc"
52 else
53 RC="${HOME}/.cshrc"
Thomas Wouters477c8d52006-05-27 19:21:47 +000054 fi
Thomas Wouters89f507f2006-12-13 04:49:30 +000055 # Create backup copy before patching
56 if [ -f "${RC}" ]; then
57 cp -fp "${RC}" "${RC}.pysave"
58 fi
59 echo "" >> "${RC}"
60 echo "# Setting PATH for MacPython ${PYVER}" >> "${RC}"
61 echo "# The orginal version is saved in .cshrc.pysave" >> "${RC}"
62 echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${RC}"
Thomas Wouters0e3f5912006-08-11 14:57:12 +000063 if [ `id -ur` = 0 ]; then
Thomas Wouters89f507f2006-12-13 04:49:30 +000064 chown "${USER}" "${RC}"
Thomas Wouters0e3f5912006-08-11 14:57:12 +000065 fi
Thomas Wouters477c8d52006-05-27 19:21:47 +000066 exit 0
67 ;;
68bash)
Thomas Wouters0e3f5912006-08-11 14:57:12 +000069 if [ -e "${HOME}/.bash_profile" ]; then
70 PR="${HOME}/.bash_profile"
Thomas Wouters89f507f2006-12-13 04:49:30 +000071 elif [ -e "${HOME}/.bash_login" ]; then
72 PR="${HOME}/.bash_login"
Thomas Wouters0e3f5912006-08-11 14:57:12 +000073 elif [ -e "${HOME}/.profile" ]; then
Thomas Wouters477c8d52006-05-27 19:21:47 +000074 PR="${HOME}/.profile"
75 else
76 PR="${HOME}/.bash_profile"
77 fi
78 ;;
79*sh)
80 PR="${HOME}/.profile"
81 ;;
82esac
83
84# Create backup copy before patching
85if [ -f "${PR}" ]; then
86 cp -fp "${PR}" "${PR}.pysave"
87fi
88echo "" >> "${PR}"
89echo "# Setting PATH for MacPython ${PYVER}" >> "${PR}"
90echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}"
91echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}"
92echo 'export PATH' >> "${PR}"
93if [ `id -ur` = 0 ]; then
Thomas Wouters0e3f5912006-08-11 14:57:12 +000094 chown "${USER}" "${PR}"
Thomas Wouters477c8d52006-05-27 19:21:47 +000095fi
96exit 0