From 50ecea40cf01bc9657645bbc4b7cf806779c57ab Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Mon, 2 Apr 2018 15:10:52 -0700 Subject: [PATCH] Better handle the case where installing the Install macOS distribution fails. --- installinstallmacos.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/installinstallmacos.py b/installinstallmacos.py index 5eadec1..7c5f217 100755 --- a/installinstallmacos.py +++ b/installinstallmacos.py @@ -119,12 +119,15 @@ def unmountdmg(mountpoint): def install_product(dist_path, target_vol): - '''Install a product to a target volume''' + '''Install a product to a target volume. + Returns a boolean to indicate success or failure.''' cmd = ['/usr/sbin/installer', '-pkg', dist_path, '-target', target_vol] try: subprocess.check_call(cmd) + return True except subprocess.CalledProcessError, err: print >> sys.stderr, err + return False class ReplicationError(Exception): @@ -396,9 +399,13 @@ def main(): mountpoint = mountdmg(sparse_diskimage_path) if mountpoint: # install the product to the mounted sparseimage volume - install_product( + success = install_product( product_info[product_id]['DistributionPath'], mountpoint) + if not success: + print >> sys.stderr, 'Product installation failed.' + unmountdmg(mountpoint) + exit(-1) print 'Product downloaded and installed to %s' % sparse_diskimage_path if not args.compress: unmountdmg(mountpoint)