• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/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/@PYVER@"
10
11if [ `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
20# Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH.
21BSH="`basename "${theShell}"`"
22case "${BSH}" in
23bash|ksh|sh|*csh|zsh|fish)
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
29	;;
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)
50	if [ -f "${HOME}/.tcshrc" ]; then
51		RC="${HOME}/.tcshrc"
52	else
53		RC="${HOME}/.cshrc"
54	fi
55	# 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 Python ${PYVER}" >> "${RC}"
61	echo "# The original version is saved in .cshrc.pysave" >> "${RC}"
62	echo "set path=(${PYTHON_ROOT}/bin "'$path'")" >> "${RC}"
63	if [ `id -ur` = 0 ]; then
64		chown "${USER}" "${RC}"
65	fi
66	exit 0
67	;;
68bash)
69	if [ -e "${HOME}/.bash_profile" ]; then
70		PR="${HOME}/.bash_profile"
71	elif [ -e "${HOME}/.bash_login" ]; then
72		PR="${HOME}/.bash_login"
73	elif [ -e "${HOME}/.profile" ]; then
74		PR="${HOME}/.profile"
75	else
76		PR="${HOME}/.bash_profile"
77	fi
78	;;
79fish)
80	CONFIG_DIR="${HOME}/.config/fish"
81	RC="${CONFIG_DIR}/config.fish"
82	mkdir -p "$CONFIG_DIR"
83	if [ -f "${RC}" ]; then
84		cp -fp "${RC}" "${RC}.pysave"
85	fi
86	echo "" >> "${RC}"
87	echo "# Setting PATH for Python ${PYVER}" >> "${RC}"
88	echo "# The original version is saved in ${RC}.pysave" >> "${RC}"
89	echo "set -x PATH \"${PYTHON_ROOT}/bin\" \"\$PATH\"" >> "${RC}"
90	if [ `id -ur` = 0 ]; then
91		chown "${USER}" "${RC}"
92	fi
93	exit 0
94	;;
95zsh)
96        PR="${HOME}/.zprofile"
97        ;;
98*sh)
99	PR="${HOME}/.profile"
100	;;
101esac
102
103# Create backup copy before patching
104if [ -f "${PR}" ]; then
105	cp -fp "${PR}" "${PR}.pysave"
106fi
107echo "" >> "${PR}"
108echo "# Setting PATH for Python ${PYVER}" >> "${PR}"
109echo "# The original version is saved in `basename ${PR}`.pysave" >> "${PR}"
110echo 'PATH="'"${PYTHON_ROOT}/bin"':${PATH}"' >> "${PR}"
111echo 'export PATH' >> "${PR}"
112if [ `id -ur` = 0 ]; then
113	chown "${USER}" "${PR}"
114fi
115exit 0
116