This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathpostinstall
executable file
·198 lines (155 loc) · 5.53 KB
/
postinstall
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
#
# Copyright 2010 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=$(pwd | awk -F/ '{print "/" $2 "/" $3 "/" $4}')
DEFAULT_PATH="$2"
TARGET_PATH="$3"
RESOURCES="$(pwd)/Resources"
BASETMPDIR="${TARGET_PATH}/tmp/"
OSX=$(sw_vers -productVersion | cut -d. -f1-2)
VERSION="2.5"
PYTHON_VERSION=$(egrep '[0-9].[0-9]' "${RESOURCES}/python_version")
PYTHON="/usr/bin/python${PYTHON_VERSION}"
INSTALL_DIR=/usr/local/munki/
VE_DIR=simian
BOMPATH=$(pkgutil --bom "${1}")
### 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
### find & test python
[[ ! -z "$PYTHON_VERSION" ]] || die "No python version specified in pkg"
[[ -x "$PYTHON" ]] || die "Python is not executable"
### create temp work directory
TMPDIR=$(mktemp -d ${BASETMPDIR}/postflightXXXXXX)
ORIGPWD="${PWD}"
trap "rm -rf ${TMPDIR}" EXIT
### find & test easy_install
EZ="/usr/bin/easy_install"
# 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==13.1.2 setuptools==18.6.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 [[ "${egg}" =~ "/simian_" ]]; then
echo === Skipping egg "${egg}" for now
else
echo === Installing egg "${egg}"
${VE_PYTHON} ${VE_EZ} -N "${egg}"
fi
done
### install simian_* specific eggs
##### install M2Crypto
# try to find an appropriate egg for this python and OS X version.
set ${RESOURCES}/simian_M2Crypto-*-py${PYTHON_VERSION}-macosx-${OSX}-*.egg
egg="$1"
if [[ -z "${egg}" || "${egg: -5:5}" = "*.egg" ]]; then
die "Cannot find M2Crypto egg for ${PYTHON_VERSION}"
fi
${VE_PYTHON} ${VE_EZ} -N "${egg}"
cd "$oldpwd"
### install main source package with setup.py
tar -zxf "${RESOURCES}/simian-${VERSION}.tar.gz" -C "${TMPDIR}"
cd "${TMPDIR}/simian-${VERSION}"
mkdir -p src/tests # fake out google test
${VE_PYTHON} setup.py install 2>&1
cd "${ORIGPWD}"
### fix sh-bang line for simianfacter
sed -i .bak "1c\\
#\!${VE_PYTHON}\\
" /usr/local/bin/simianfacter
rm -f /usr/local/bin/simianfacter.bak
### small file operations
z=$(lsbom "${BOMPATH}" | grep ssl/private_keys ; true)
if [[ ! -z "$z" ]]; then
chmod 750 /etc/simian/ssl/private_keys
fi
z=$(lsbom "${BOMPATH}" | grep "/etc/simian/.*\.cfg" ; true)
if [[ ! -z "$z" ]]; then
f="/etc/simian/settings.cfg"
if [ ! -f "${f}" -a -f "${f}+" ]; then
mv "${f}+" "${f}"
else
rm "${f}+"
fi
fi
z=$(lsbom "${BOMPATH}" | grep /Library/LaunchAgents/ ; true)
if [[ ! -z "$z" ]]; then
for f in /Library/Launch{Agents,Daemons}/com.googlecode.munki.*.plist; do
chown root:wheel "${f}"
chmod 644 "${f}"
done
fi
### install roots.pem
cp "$(pwd)/roots.pem" ${INSTALL_DIR}/${VE_DIR}/
### update munki configuration
echo Begin section: Harmless "configuration not found" messages may follow
server=$(${VE_PYTHON} -c "from simian import settings ; print '%s' % settings.SERVER_HOSTNAME")
defaults write /Library/Preferences/ManagedInstalls SoftwareRepoURL "https://${server}"
echo End section
### fix google_apputils permissions
find ${INSTALL_DIR}/simian/lib/python*/site-packages/google_apputils-*.egg -type f -print0 | xargs -0 chmod 644
find ${INSTALL_DIR}/simian/lib/python*/site-packages/google_apputils-*.egg -type d -print0 | xargs -0 chmod 755
### end
echo postflight END
rm -f "${LOGFILE}"