-
Notifications
You must be signed in to change notification settings - Fork 3
/
postflight-globus-clients
executable file
·148 lines (135 loc) · 6.6 KB
/
postflight-globus-clients
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# -*- coding: utf-8; mode: shell-script-mode; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=sh:et:sw=4:ts=4:sts=4
#
# Copyright (c) 2012 Stichting FOM
# Copyright (c) 2008-2012 The MacPorts Project
# Copyright (c) 2002-2007 Juan Manuel Palacios <[email protected]>, The MacPorts Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of The MacPorts Project nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# postflight
# This script is a stripped-down version of the MacPorts postflight script.
# It updates the user's defaultt PATH and MANPATH so the Globus Client tools
# can be used right away.
#set -x
# Script identification
VERSION=1.0
# Abstraction variables:
PREFIX=/opt/globus
BINPATH=${PREFIX}/bin
SBINPATH=${PREFIX}/sbin
MANPAGES=${PREFIX}/share/man
DSCL=/usr/bin/dscl
TIMESTAMP=$(date +"%Y-%m-%d_at_%H:%M:%S")
BACKUP_SUFFIX=macports-saved_${TIMESTAMP}
OUR_STRING="Globus Clients addition on ${TIMESTAMP}"
# Through this command we write an environment variable to an appropriate shell configuration file,
# backing up the original only if it exists and if it doesn't contain the ${OUR_STRING} identification string,
# which hints that we've already tweaked it and therefore already backed it up.
function write_setting () {
if [[ -f "${HOME}/.${CONF_FILE}" ]] && ! grep "${OUR_STRING}" "${HOME}/.${CONF_FILE}" > /dev/null; then
echo "Backing up your ${HOME}/.${CONF_FILE} shell confguration file as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX} before adapting it for MacPorts."
/bin/cp -fp "${HOME}/.${CONF_FILE}" "${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}" || {
echo "An attempt to backup your original configuration file failed! Please set your MacPorts compatible environment manually."
exit 1
}
echo -e "\n##\n# Your previous ${HOME}/.${CONF_FILE} file was backed up as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}\n##" >> "${HOME}/.${CONF_FILE}"
fi
echo -e "\n# ${OUR_STRING}: adding an appropriate ${1} variable for use with MacPorts." >> "${HOME}/.${CONF_FILE}"
echo "${ENV_COMMAND} ${1}${ASSIGN}${2}" >> "${HOME}/.${CONF_FILE}"
echo -e "# Finished adapting your ${1} environment variable for use with MacPorts.\n" >> "${HOME}/.${CONF_FILE}"
chown ${USER} "${HOME}/.${CONF_FILE}" || echo "Warning: unable to adapt permissions on your ${HOME}/.${CONF_FILE} shell configuration file!"
echo "An appropriate ${1} variable has been added to your shell environment by the MacPorts installer."
}
echo "The Globus Toolkit Clients package, postflight script version ${VERSION}: checking the shell environment for user \"${USER}\"."
# Determine the user's shell, in order to choose an appropriate configuration file we'll be tweaking.
# Exit nicely if the shell is any other than bash or tcsh, as that's considered non-standard.
USHELL=$(${DSCL} . -read /Users/${USER} shell | awk -F'/' '{print $NF}') || {
echo "An attempt to determine your shell name failed! Please set your MacPorts compatible environment manually."
update_macports
exit 1
}
case "${USHELL}" in
tcsh)
echo "Detected the tcsh shell."
LOGIN_FLAG=""
ENV_COMMAND="setenv"
ASSIGN=" "
if [[ -f "${HOME}/.tcshrc" ]]; then
CONF_FILE=tcshrc
elif [[ -f "${HOME}/.cshrc" ]]; then
CONF_FILE=cshrc
else
CONF_FILE=tcshrc
fi
;;
bash)
echo "Detected the bash shell."
LOGIN_FLAG="-l"
ENV_COMMAND="export"
ASSIGN="="
if [[ -f "${HOME}/.bash_profile" ]]; then
CONF_FILE=bash_profile
elif [[ -f "${HOME}/.bash_login" ]]; then
CONF_FILE=bash_login
else
CONF_FILE=profile
fi
;;
*)
echo "Unknown shell ($USHELL)! Please set your Globus client environment manually."
exit 0
;;
esac
# Adding our setting to the PATH variable if not already there:
if ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv PATH" | grep ${PREFIX} > /dev/null; then
echo "Your shell already has the right PATH environment variable for use with MacPorts!"
else
write_setting PATH "${BINPATH}:${SBINPATH}:\$PATH"
fi
# We gather the path into a variable of our own for faster operation:
ORIGINAL_MANPATH="$(${SHELL} ${LOGIN_FLAG} -c "/usr/bin/printenv MANPATH")"
# Adding our setting to the MANPATH variable only if it exists:
if ! ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep MANPATH" > /dev/null || \
# and following that, if it's not empty:
[[ -z "${ORIGINAL_MANPATH}" ]] || \
# or if it doesn't already contain our path:
echo "${ORIGINAL_MANPATH}" | grep ${MANPAGES} > /dev/null || \
# or if there's no empty component somewhere in the middle of it:
echo "${ORIGINAL_MANPATH}" | grep :: > /dev/null || \
# or at the start of it:
[[ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ]] || \
# or at the end of it:
[[ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]]; then
echo "Your shell already has the right MANPATH environment variable for use with Globus Clients!"
else
write_setting MANPATH "${MANPAGES}:\$MANPATH"
fi
if ! ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep GLOBUS_LOCATION" ; then
write_setting GLOBUS_LOCATION ${PREFIX}
fi
echo "Globus Clients successfully installed."
exit 0