forked from gmarnin/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_python_framework_pkgs.zsh
More file actions
executable file
·166 lines (149 loc) · 5.26 KB
/
Copy pathbuild_python_framework_pkgs.zsh
File metadata and controls
executable file
·166 lines (149 loc) · 5.26 KB
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
#!/bin/zsh
#
# Build script for Python 3 frameworks
# Adaptd from https://github.com/munki/munki/blob/Munki3dev/code/tools/build_python_framework.sh
# IMPORTANT
# Run this with your current directory being the path where this script is located
# Harcoded versions
PYTHON_VERSION=3.8.3
RP_SHA="8bce58e91895978da6f238c1d2e1de3559ea4643"
MP_SHA="71c57fcfdf43692adcd41fa7305be08f66bae3e5"
# Sanity Checks
## Type Check
if [ -n "$1" ]; then
if [[ "$1" == 'minimal' ]]; then
TYPE=$1
elif [[ "$1" == "no_customization" ]]; then
TYPE=$1
elif [[ "$1" == "opionated" ]]; then
TYPE=$1
elif [[ "$1" == 'recommended' ]]; then
TYPE=$1
else
echo "Specified positional argument other than opionated or recommended. Using minimal workflow"
TYPE='minimal'
fi
else
echo "runner.zsh"
echo ""
echo " Configures Relocatable Python"
echo " Options:"
echo " minimal"
echo " Identical to the original relocatable python code"
echo ""
echo " no_customization"
echo " A python framework without any customizations"
echo ""
echo " recommended"
echo " A python framework with libraries for commonly used tools like autopkg and munki"
echo ""
echo " opionated"
echo " A python framework with libraries for as many macadmin tools as possible"
exit 1
fi
## Root Check
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "This tool requires elevated access to run"
exit 1
fi
# Variables
DATE=$(/bin/date -u "+%m%d%Y%H%M%S")
TOOLSDIR=$(dirname $0)
OUTPUTSDIR="$TOOLSDIR/outputs"
CONSOLEUSER=$(/usr/bin/stat -f "%Su" /dev/console)
FRAMEWORKDIR="/Library/SystemFrameworks"
RP_BINDIR="/tmp/relocatable-python"
RP_ZIP="/tmp/relocatable-python.zip"
MP_BINDIR="/tmp/munki-pkg"
MP_ZIP="/tmp/munki-pkg.zip"
echo "Creating Python Framework - $TYPE"
# Create framework path if not present
if [ ! -d "${FRAMEWORKDIR}" ]; then
/usr/bin/sudo /bin/mkdir -p "${FRAMEWORKDIR}"
fi
# remove existing library Python.framework if present
if [ -d "${FRAMEWORKDIR}/Python.framework" ]; then
/usr/bin/sudo /bin/rm -rf "${FRAMEWORKDIR}/Python.framework"
fi
# Download specific version of relocatable-python
echo "Downloading relocatable-python tool from github..."
if [ -f "${RP_ZIP}" ]; then
/usr/bin/sudo /bin/rm -rf ${RP_ZIP}
fi
/usr/bin/curl https://github.com/gregneagle/relocatable-python/archive/${RP_SHA}.zip -L -o ${RP_ZIP}
if [ -d ${RP_BINDIR} ]; then
/usr/bin/sudo /bin/rm -rf ${RP_BINDIR}
fi
/usr/bin/unzip ${RP_ZIP} -d ${RP_BINDIR}
DL_RESULT="$?"
if [ "${DL_RESULT}" != "0" ]; then
echo "Error downloading relocatable-python tool: ${DL_RESULT}" 1>&2
exit 1
fi
# remove existing Python package folder
if [ -d "$TOOLSDIR/$TYPE" ]; then
/bin/rm -rf "$TOOLSDIR/$TYPE"
/bin/mkdir -p "$TOOLSDIR/$TYPE/payload/${FRAMEWORKDIR}"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$TOOLSDIR/$TYPE"
else
/bin/mkdir -p "$TOOLSDIR/$TYPE/payload/${FRAMEWORKDIR}"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$TOOLSDIR/$TYPE"
fi
# build the framework
RP_EXTRACT_BINDIR="${RP_BINDIR}/relocatable-python-${RP_SHA}"
/usr/bin/sudo "${RP_EXTRACT_BINDIR}/make_relocatable_python_framework.py" \
--python-version "${PYTHON_VERSION}" \
--pip-requirements "${TOOLSDIR}/requirements_${TYPE}.txt" \
--destination "${FRAMEWORKDIR}"
RP_RESULT="$?"
if [ "${RP_RESULT}" != "0" ]; then
echo "Error running relocatable-python tool: ${RP_RESULT}" 1>&2
exit 1
fi
# move the framework to the Python package folder
echo "Moving Python.framework to payload folder"
/usr/bin/sudo /bin/mv "${FRAMEWORKDIR}/Python.framework" "$TOOLSDIR/$TYPE/payload/${FRAMEWORKDIR}/Python3.framework"
# take ownership of the payload folder
echo "Taking ownership of the Payload directory"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$TOOLSDIR/$TYPE"
# Download specific version of munki-pkg
echo "Downloading munki-pkg tool from github..."
if [ -f "${MP_ZIP}" ]; then
/usr/bin/sudo /bin/rm -rf ${MP_ZIP}
fi
/usr/bin/curl https://github.com/munki/munki-pkg/archive/${MP_SHA}.zip -L -o ${MP_ZIP}
if [ -d ${MP_BINDIR} ]; then
/usr/bin/sudo /bin/rm -rf ${MP_BINDIR}
fi
/usr/bin/unzip ${MP_ZIP} -d ${MP_BINDIR}
DL_RESULT="$?"
if [ "${DL_RESULT}" != "0" ]; then
echo "Error downloading munki-pkg tool: ${DL_RESULT}" 1>&2
exit 1
fi
# Create outputs folder
/bin/mkdir -p "$TOOLSDIR/outputs"
# Create the json file for munki-pkg
/bin/cat << JSONFILE > "$TOOLSDIR/$TYPE/build-info.json"
{
"ownership": "recommended",
"suppress_bundle_relocation": true,
"identifier": "org.macadmins.python.$TYPE",
"postinstall_action": "none",
"distribution_style": true,
"version": "$PYTHON_VERSION.$DATE",
"name": "python_$TYPE-$PYTHON_VERSION.$DATE.pkg",
"install_location": "/"
}
JSONFILE
# Create the pkg
"${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$TOOLSDIR/$TYPE"
# Zip the framework
ZIPFILE="Python3.framework_$TYPE-$PYTHON_VERSION.$DATE.zip"
/usr/bin/ditto -c -k --sequesterRsrc "$TOOLSDIR/$TYPE/payload/${FRAMEWORKDIR}/" ${ZIPFILE}
# Move all of the output files
/bin/mv ${ZIPFILE} "$OUTPUTSDIR"
/bin/mv "$TOOLSDIR/$TYPE/build/python_$TYPE-$PYTHON_VERSION.$DATE.pkg" "$OUTPUTSDIR"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$OUTPUTSDIR"
# Cleanup
/usr/bin/sudo /bin/rm -rf "$TOOLSDIR/$TYPE"