Skip to content

Instantly share code, notes, and snippets.

@timsutton
Created January 19, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timsutton/320eae5c1c616feb3f9063ab9ec0c639 to your computer and use it in GitHub Desktop.
Save timsutton/320eae5c1c616feb3f9063ab9ec0c639 to your computer and use it in GitHub Desktop.
Simple Bash script that repackages and copies Unity 3d 5 packages to a Munki repo
#!/bin/bash -eu
# This script takes a directory containing flat packages. It expands
# them all, uses `xmlstarlet` to edit pkg-info 'version' attribute
# to the one given by VERSION, and flattens them back, saving them
# as "pkgname-VERSION.pkg"
# Use the Unity download assistant to download the packages in a VM
# to avoid actually installing them by accident on the machine, and
# then run this script. Currently we download:
# - Unity
# - Standard Assets
# - Example Project
# - Documentation
# - WebGL Build Support
#
# TODO: one outstanding issue is that if the name has dashes, like the WebGL or iOS (and possibly
# other) build targets components, Munki won't be able to process those items. Currently I'm
# manually stripping out the dashes from the name, i.e. UnityPro5_UnitySetupWebGLSupportforEditor5
# but we should be doing this as we build the munkiimport '--name' flag.
VERSION=5.5.0f3
MUNKI_SUBDIR=apps/Unity
# clean any existing pkgs in the cwd
rm -f ./*.pkg
pkgsdir="${1}"
tmpdir=$(mktemp -d)
for pkg in ${pkgsdir}/*.pkg; do
pkg_file_name=$(basename "${pkg}")
OLDIFS=$IFS
IFS=. components=(${pkg_file_name})
IFS=$OLDIFS
pkgutil --expand "${pkg}" "${tmpdir}/${pkg_file_name}"
echo "Expanded to ${tmpdir}/${pkg_file_name}"
pkginfo=$(find "${tmpdir}/${pkg_file_name}" -name "*PackageInfo*")
pkg_id=$(xmlstarlet sel -t -v "/pkg-info/@identifier" "${pkginfo}")
echo "Found package identifier $pkg_id"
xmlstarlet edit --inplace --update \
'/pkg-info/@version' \
--value "${VERSION}" \
"${pkginfo}"
dist="${tmpdir}/${pkg_file_name}/Distribution"
xmlstarlet edit --inplace --update \
'/installer-gui-script/pkg-ref[@id='\""${pkg_id}"\"' and @version="0"]/@version' \
--value "${VERSION}" \
"${dist}"
output_pkg_file="${components[0]}-${VERSION}.pkg"
pkgutil --flatten "${tmpdir}/${pkg_file_name}" "${output_pkg_file}"
rm -rf "${tmpdir:?}/${pkg_file_name}"
cmd="munkiimport --nointeractive --subdirectory ${MUNKI_SUBDIR} "
if [ "${components[0]}" == "Unity" ]; then
cmd="${cmd} --name UnityPro5 "
else
cmd="${cmd} --name UnityPro5_${components[0]} --update-for UnityPro5 "
fi
cmd="${cmd} ${output_pkg_file}"
echo "Running command: ${cmd}"
${cmd}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment