-
-
Notifications
You must be signed in to change notification settings - Fork 921
/
patch_profile
81 lines (74 loc) · 1.73 KB
/
patch_profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
check_previous_patch() {
if grep -q 'Setting PATH for JRuby' "$1"
then return 1
fi
return 0
}
declare -x PR
# add current directory to the user's profile
if [ `id -ur` = 0 ]; then
# Run from the installer, do some trickery to fetch the information
# we need.
theShell="`finger $USER | grep Shell: | head -1 | awk '{ print $NF }'`"
else
theShell="${SHELL}"
fi
BSH="`basename "${theShell}"`"
case "${BSH}" in
*csh)
if [ -f "${HOME}/.tcshrc" ]; then
PR="${HOME}/.tcshrc"
else
PR="${HOME}/.cshrc"
fi
;;
bash)
if [ -e "${HOME}/.bash_profile" ]; then
PR="${HOME}/.bash_profile"
elif [ -e "${HOME}/.bash_login" ]; then
PR="${HOME}/.bash_login"
elif [ -e "${HOME}/.profile" ]; then
PR="${HOME}/.profile"
else
PR="${HOME}/.bash_profile"
fi
;;
*sh)
PR="${HOME}/.profile"
;;
esac
# Create backup copy before patching
patch_profile() {
if [ -f "${PR}" ]; then
cp -fp "${PR}" "${PR}.jrubysave"
fi
echo "" >> "${PR}"
echo "# Setting PATH for JRuby ${JRUBYVER}" >> "${PR}"
echo "# The orginal version is saved in `basename ${PR}`.jrubysave" >> "${PR}"
echo 'PATH="${PATH}:'"${JRUBY_CURRENT_PATH}/bin"'"' >> "${PR}"
echo 'export PATH' >> "${PR}"
if [ `id -ur` = 0 ]; then
chown "${USER}" "${PR}"
fi
}
try_patch_profile() {
check_previous_patch $PR
if [ $? -eq 0 ]
then
patch_profile
fi
}
try_revert_patch() {
check_previous_patch $PR
patched=$?
if [ $patched -eq 1 ]
then
if [ -f "${PR}.jrubysave" ]
then
cp -fp "${PR}.jrubysave" "${PR}"
else
sed -iE '/JRuby/,/export/d' ${PR}
fi
fi
}