blob: a66b8c787ac9cc4f36dce2c911135cc2df336e0a [file] [log] [blame]
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +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
Ronald Oussoren799868e2009-03-04 21:07:19 +00008PYVER="@PYVER@"
9PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/@PYVER@"
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000010
Ronald Oussoren0f53bb12006-08-01 20:30:31 +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
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000020# Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH.
Ronald Oussoren0f53bb12006-08-01 20:30:31 +000021BSH="`basename "${theShell}"`"
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000022case "${BSH}" in
Ronald Oussorenec2fe002010-09-28 14:01:49 +000023bash|ksh|sh|*csh|zsh)
Ronald Oussoren0f53bb12006-08-01 20:30:31 +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
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +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
Ronald Oussoren39346192009-11-19 17:42:51 +000039 if [ "${elem}" = "${PYTHON_ROOT}/bin" ]; then
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000040 echo "All right, you're a python lover already"
41 exit 0
Ronald Oussoren39346192009-11-19 17:42:51 +000042 elif [ "${elem}" = "/usr/bin" ]; then
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000043 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)
Ronald Oussorenb80b6e12006-10-08 18:18:26 +000050 if [ -f "${HOME}/.tcshrc" ]; then
51 RC="${HOME}/.tcshrc"
52 else
53 RC="${HOME}/.cshrc"
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000054 fi
Ronald Oussorenb80b6e12006-10-08 18:18:26 +000055 # Create backup copy before patching
56 if [ -f "${RC}" ]; then
57 cp -fp "${RC}" "${RC}.pysave"
58 fi
59 echo "" >> "${RC}"
Ronald Oussorencc00a262009-05-19 19:29:24 +000060 echo "# Setting PATH for Python ${PYVER}" >> "${RC}"
Ronald Oussorenb80b6e12006-10-08 18:18:26 +000061 echo "# The orginal version is saved in .cshrc.pysave" >> "${RC}"
62 echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${RC}"
Ronald Oussoren0f53bb12006-08-01 20:30:31 +000063 if [ `id -ur` = 0 ]; then
Ronald Oussorenb80b6e12006-10-08 18:18:26 +000064 chown "${USER}" "${RC}"
Ronald Oussoren0f53bb12006-08-01 20:30:31 +000065 fi
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000066 exit 0
67 ;;
68bash)
Ronald Oussoren0f53bb12006-08-01 20:30:31 +000069 if [ -e "${HOME}/.bash_profile" ]; then
70 PR="${HOME}/.bash_profile"
Ronald Oussorenb80b6e12006-10-08 18:18:26 +000071 elif [ -e "${HOME}/.bash_login" ]; then
72 PR="${HOME}/.bash_login"
Ronald Oussoren0f53bb12006-08-01 20:30:31 +000073 elif [ -e "${HOME}/.profile" ]; then
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000074 PR="${HOME}/.profile"
75 else
76 PR="${HOME}/.bash_profile"
77 fi
78 ;;
Ronald Oussorenec2fe002010-09-28 14:01:49 +000079zsh)
80 PR="${HOME}/.zprofile"
81 ;;
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000082*sh)
83 PR="${HOME}/.profile"
84 ;;
85esac
86
87# Create backup copy before patching
88if [ -f "${PR}" ]; then
89 cp -fp "${PR}" "${PR}.pysave"
90fi
91echo "" >> "${PR}"
Ronald Oussorencc00a262009-05-19 19:29:24 +000092echo "# Setting PATH for Python ${PYVER}" >> "${PR}"
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000093echo "# The orginal version is saved in `basename ${PR}`.pysave" >> "${PR}"
94echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}"
95echo 'export PATH' >> "${PR}"
96if [ `id -ur` = 0 ]; then
Ronald Oussoren0f53bb12006-08-01 20:30:31 +000097 chown "${USER}" "${PR}"
Ronald Oussoren0e5b70d2006-06-07 18:58:42 +000098fi
99exit 0