From 13c4ec41a2578950f78542209a48b1b52607fc7a Mon Sep 17 00:00:00 2001 From: MagerValp Date: Tue, 25 Oct 2011 20:53:18 +0200 Subject: [PATCH] import --- README | 8 ++++++ flatten_dist.py | 61 +++++++++++++++++++++++++++++++++++++++ repackage_ilife11.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 README create mode 100755 flatten_dist.py create mode 100755 repackage_ilife11.sh diff --git a/README b/README new file mode 100644 index 0000000..eb43643 --- /dev/null +++ b/README @@ -0,0 +1,8 @@ +iLife '11 repackaging script +============================ + +This creates a flat package suitable for deployment with InstaDMG, DeployStudio, Absolute Manage, and other management tools. To use it, mount an iLife '11 installer disc and run: + + ./repackage_ilife11.sh "/Volumes/iLife '11 Install DVD" + +It'll run and hopefully create a 3 GB flat package with today's datestamp. diff --git a/flatten_dist.py b/flatten_dist.py new file mode 100755 index 0000000..8c10c03 --- /dev/null +++ b/flatten_dist.py @@ -0,0 +1,61 @@ +#!/usr/bin/python + + +import sys +import optparse +from xml.etree import ElementTree + + +def flatten_pkg_path(path): + path = path.rpartition("/")[2] + return "#" + path + + +def flatten_pkg_refs(dist): + packages = dict() + + for pkgref in dist.findall("choice/pkg-ref"): + pkg_id = pkgref.get("id") + pkg_auth = pkgref.get("auth") + pkg_path = pkgref.text + packages[pkg_id] = { + "auth": "Root" if pkg_auth == "root" else pkg_auth, + "pkg": flatten_pkg_path(pkg_path) + } + del pkgref.attrib["auth"] + del pkgref.text + + for pkgref in dist.findall("pkg-ref"): + pkg_id = pkgref.get("id") + pkgref.set("auth", packages[pkg_id]["auth"]) + pkgref.text = packages[pkg_id]["pkg"] + + return dist + + +def main(argv): + p = optparse.OptionParser() + p.set_usage("""Usage: %prog [options]""") + p.add_option("-v", "--verbose", action="store_true", + help="Verbose output.") + options, argv = p.parse_args(argv) + if len(argv) != 2: + print >>sys.stderr, p.get_usage() + return 1 + + dist_path = argv[1] + + with open(dist_path) as f: + dist = ElementTree.parse(f) + + flatten_pkg_refs(dist) + + with open(dist_path, "w") as f: + dist.write(f, encoding="utf-8") + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + diff --git a/repackage_ilife11.sh b/repackage_ilife11.sh new file mode 100755 index 0000000..6a9e627 --- /dev/null +++ b/repackage_ilife11.sh @@ -0,0 +1,68 @@ +#!/bin/bash + + +SRCVOL="$1" +if [ ! -d "$SRCVOL" ]; then + echo "Usage: "`basename "$0"`" /Volumes/iLife\\ \\'11\\ Install\\ DVD" + exit 1 +fi + +PKGSRC="${SRCVOL%/}/Installer/Packages" +PKGNAME=`date +"iLife11-%Y%m%d.pkg"` + + +echo "* Checking media" + +if [ ! -f "$PKGSRC/iLife.pkg" ]; then + echo "'$SRCVOL' is not an iLife '11 installer DVD" + exit 1 +fi + + +echo "* Expanding iLife base package" + +rm -rf iLife_pkg +pkgutil --expand "$PKGSRC/iLife.pkg" iLife_pkg +if [ $? -ne 0 ]; then + echo "Package expansion failed!" + exit 1 +fi + + +echo "* Modifying Distribution" + +./flatten_dist.py iLife_pkg/Distribution +if [ $? -ne 0 ]; then + echo "Distribution modification failed!" + exit 1 +fi + + +echo "* Expanding sub-packages" + +for pkg in "$PKGSRC"/*.pkg; do + pkgname=`basename "$pkg"` + if [ "$pkgname" != iLife.pkg ]; then + echo "Expanding $pkgname..." + pkgutil --expand "$pkg" "iLife_pkg/$pkgname" + if [ $? -ne 0 ]; then + echo "Package expansion failed!" + exit 1 + fi + fi +done + + +echo "* Flattening packge" + +pkgutil --flatten iLife_pkg "$PKGNAME" +if [ $? -ne 0 ]; then + echo "Flattening failed!" + exit 1 +fi + +open -R "$PKGNAME" +rm -rf iLife_pkg + + +echo "* Done"