forked from google/cauliflowervest
/
postflight
executable file
·162 lines (130 loc) · 4.88 KB
/
postflight
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
#
# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Install postflight script
#
# Note: this script ends up running from the directory that the installer
# was invoked from, e.g. maybe / from the GUI, or a /Volumes/blah if
# invoked from CLI
set -e
set -x
function die() {
echo ERROR "$@" >&2
exit 1
}
export PATH="$PATH:/usr/bin"
PKG="$1"
DEFAULT_PATH="$2"
TARGET_PATH="$3"
RESOURCES="${PKG}/Contents/Resources"
BASETMPDIR="${TARGET_PATH}/tmp/"
OSX=$(sw_vers -productVersion | cut -d. -f1-2)
VERSION="0.10.2"
PACKAGE_DEPS="setuptools python-dateutil>=1.4,<2 pyyaml google_apputils"
PYTHON_VERSION=$(egrep '[0-9].[0-9]' "${PKG}/Contents/Resources/python_version")
PYTHON="python${PYTHON_VERSION}"
INSTALL_DIR=/usr/local/cauliflowervest/
VE_DIR=cv
### set up sane logging
d=$(date '+%Y%m%d%H%M')
LOGFILE="${BASETMPDIR}/postflight.${d}.$$.log"
exec 1> "${LOGFILE}"
exec 2>&1
echo postflight BEGIN
### create temp work directory
TMPDIR=$(mktemp -d ${BASETMPDIR}/postflightXXXXXX)
ORIGPWD="${PWD}"
trap "rm -rf ${TMPDIR}" EXIT
### find & test easy_install
# this can be somewhat difficult because the version of easy_install
# appropriate for our PYTHON_VERSION and setuptools version might be in
# /usr/local/bin or /usr/bin.
EZ="/usr/bin/easy_install"
# the version in /usr/local/bin might be for a newer python with a newer
# dependency on setuptools. try running it to see if it is willing to run.
if [[ -f /usr/local/bin/easy_install ]]; then
if [[ -x /usr/local/bin/easy_install ]]; then
${PYTHON} /usr/local/bin/easy_install --help 2>/dev/null && \
EZ="/usr/local/bin/easy_install"
fi
fi
# easy_install might point the user to easy_install-VERSION instead and fail.
# look around for a specific version.
if [[ "$EZ" = "/usr/bin/easy_install" ]]; then
if [[ -x "/usr/bin/easy_install-${PYTHON_VERSION}" ]]; then
EZ="/usr/bin/easy_install-${PYTHON_VERSION}"
fi
fi
[[ -x "${EZ}" ]] || die "Cannot execute easy_install ${EZ}"
### install virtualenv
${PYTHON} ${EZ} -U virtualenv==1.10.1
### find & test newly installed virtualenv
VIRTUALENV=$(PATH=/usr/bin:/usr/local/bin type -p virtualenv)
[[ -x "${VIRTUALENV}" ]] || die "Cannot execute or find virtualenv"
### create install directory and run virtualenv to create INSTALL_DIR/VE_DIR
oldpwd="$PWD"
mkdir -p "${INSTALL_DIR}"
cd "${INSTALL_DIR}"
### create a distutils __init__.py if it does not exist
### otherwise virtualenv fails.
distutils_path=$(${PYTHON} -c \
'import sys; import distutils; print distutils.__path__[0]')
[[ -d "${distutils_path}" ]] || die "Cannot find distutils"
if [[ ! -f "${distutils_path}/__init__.py" ]]; then
${PYTHON} -c \
'import distutils ; \
print "__version__ = \"%s\"" % distutils.__version__ ; \
print "__revision__ = \"%s\"" % distutils.__revision__' > \
${distutils_path}/__init__.tmp$$
rm -f ${distutils_path}/__init__.py
mv -f ${distutils_path}/__init__.tmp$$ ${distutils_path}/__init__.py
fi
# Supply our own install_name_tool first in the PATH so machines without
# the SDK can perform this step.
env PATH="${RESOURCES}/vep:${PATH}" ${PYTHON} ${VIRTUALENV} ${VE_DIR}
VE_PYTHON=${INSTALL_DIR}/${VE_DIR}/bin/python
VE_EZ=${INSTALL_DIR}/${VE_DIR}/bin/easy_install
### install supplied eggs
for egg in ${RESOURCES}/*.egg ; do
if [ -r "${egg}" ]; then
echo === Installing egg "${egg}"
${VE_PYTHON} ${VE_EZ} -N "${egg}"
fi
done
### install dependencies
# setuptools does not like to upgrade some packages automatically
# when running setup.py below, e.g. python-dateutil from 1.2 to 1.4.
# so, just upgrade them all in advance. :(
for package in ${PACKAGE_DEPS}; do
${VE_PYTHON} ${VE_EZ} -U "${package}"
done
### install roots.pem
cp "${RESOURCES}/roots.pem" "${INSTALL_DIR}/"
### install main source package
tar -zxf "${RESOURCES}/cauliflowervest-${VERSION}.tar.gz" -C "${TMPDIR}"
cd "${TMPDIR}/cauliflowervest-${VERSION}"
mkdir -p src/tests # fake out google test
${VE_PYTHON} setup.py install 2>&1
cd "${ORIGPWD}"
### fix google_apputils permissions
find ${INSTALL_DIR}/cv/lib/python*/site-packages/google_apputils-*.egg -type f -print0 | xargs -0 chmod 644
find ${INSTALL_DIR}/cv/lib/python*/site-packages/google_apputils-*.egg -type d -print0 | xargs -0 chmod 755
### fix httplib2 permissions
chmod 0644 ${INSTALL_DIR}/cv/lib/python*/site-packages/httplib2*/httplib2/cacerts.txt
### END, remove our debug log
exec 1> /dev/null
exec 2>&1
rm -f "${LOGFILE}"