blob: 48bf70158795fe161fe62af02c56eb3ef3050278 [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
8PYVER=@PYVER@
9PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/Current"
10
11# Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH.
12BSH="`basename "${SHELL}"`"
13case "${BSH}" in
14bash|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 ;;
21esac
22
23# Now ensure that our bin directory is on $P and before /usr/bin at that
24for elem in `echo $P | tr ':' ' '`
25do
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
32done
33
34echo "${PYTHON_ROOT}/bin is not on your PATH or at least not early enough"
35case "${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 ;;
47bash)
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 ;;
57esac
58
59# Create backup copy before patching
60if [ -f "${PR}" ]; then
61 cp -fp "${PR}" "${PR}.pysave"
62fi
63echo "" >> "${PR}"
64echo "# Setting PATH for MacPython ${PYVER}" >> "${PR}"
65echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}"
66echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}"
67echo 'export PATH' >> "${PR}"
68if [ `id -ur` = 0 ]; then
69 chown "${LOGNAME}" "${PR}"
70fi
71exit 0