Debian Codegraph @

Mac/BuildScript/scripts/postflight.patch-profile

raw
1 #!/bin/sh
2
3 PYVER=@PYVER@
4 PYTHON_ROOT="/Library/Frameworks/Python.framework/Versions/@PYVER@"
5
6
7 # Run from the installer, do some trickery to fetch the information
8 # we need.
9 theShell="`finger $USER | grep Shell: | head -1 | awk '{ print $NF }'`"
10
11 # Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH.
12 BSH="`basename "${theShell}"`"
13 case "${BSH}" in
14 bash|ksh|sh|*csh|zsh|fish)
15 true
16 ;;
17 *)
18 exit 0
19 ;;
20 esac
21
22 case "${BSH}" in
23 *csh)
24 if [ -f "${HOME}/.tcshrc" ]; then
25 RC="${HOME}/.tcshrc"
26 else
27 RC="${HOME}/.cshrc"
28 fi
29
30 # Drop privileges while writing files.
31 su -m ${USER} <<EOFC
32 # Create backup copy before patching
33 if [ -f "${RC}" ]; then
34 cp -fp "${RC}" "${RC}.pysave"
35 fi
36 echo "" >> "${RC}"
37 echo "# Setting PATH for Python ${PYVER}" >> "${RC}"
38 echo "# The original version is saved in .cshrc.pysave" >> "${RC}"
39 echo "set path=(${PYTHON_ROOT}/bin "'\$path'")" >> "${RC}"
40 EOFC
41
42 if [ `id -ur` = 0 ]; then
43 chown -h "${USER}" "${RC}"
44 fi
45 exit 0
46 ;;
47 bash)
48 if [ -e "${HOME}/.bash_profile" ]; then
49 PR="${HOME}/.bash_profile"
50 elif [ -e "${HOME}/.bash_login" ]; then
51 PR="${HOME}/.bash_login"
52 elif [ -e "${HOME}/.profile" ]; then
53 PR="${HOME}/.profile"
54 else
55 PR="${HOME}/.bash_profile"
56 fi
57 ;;
58 fish)
59 CONFIG_DIR="${HOME}/.config/fish/conf.d/"
60 RC="${CONFIG_DIR}/python-${PYVER}.fish"
61
62 # Drop privileges while writing files.
63 su -m ${USER} <<EOFF
64 mkdir -p "$CONFIG_DIR"
65 if [ -f "${RC}" ]; then
66 cp -fp "${RC}" "${RC}.pysave"
67 fi
68 echo "# Setting PATH for Python ${PYVER}" > "${RC}"
69 if [ -f "${RC}.pysave" ]; then
70 echo "# The original version is saved in ${RC}.pysave" >> "${RC}"
71 fi
72 echo "fish_add_path -g \"${PYTHON_ROOT}/bin\"" >> "${RC}"
73 EOFF
74
75 if [ `id -ur` = 0 ]; then
76 chown -h "${USER}" "${RC}"
77 fi
78 exit 0
79 ;;
80 zsh)
81 PR="${HOME}/.zprofile"
82 ;;
83 *sh)
84 PR="${HOME}/.profile"
85 ;;
86 esac
87
88 # Drop privileges while writing files.
89 su -m ${USER} <<EOFS
90 # Create backup copy before patching
91 if [ -f "${PR}" ]; then
92 cp -fp "${PR}" "${PR}.pysave"
93 fi
94 echo "" >> "${PR}"
95 echo "# Setting PATH for Python ${PYVER}" >> "${PR}"
96 echo "# The original version is saved in `basename ${PR}`.pysave" >> "${PR}"
97 echo 'PATH="'"${PYTHON_ROOT}/bin"':\${PATH}"' >> "${PR}"
98 echo 'export PATH' >> "${PR}"
99 EOFS
100
101 if [ `id -ur` = 0 ]; then
102 chown -h "${USER}" "${PR}"
103 fi
104 exit 0