Better handle the case where installing the Install macOS distribution fails.

This commit is contained in:
Greg Neagle 2018-04-02 15:10:52 -07:00
parent 08edce08e7
commit 50ecea40cf

View File

@ -119,12 +119,15 @@ def unmountdmg(mountpoint):
def install_product(dist_path, target_vol): 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] cmd = ['/usr/sbin/installer', '-pkg', dist_path, '-target', target_vol]
try: try:
subprocess.check_call(cmd) subprocess.check_call(cmd)
return True
except subprocess.CalledProcessError, err: except subprocess.CalledProcessError, err:
print >> sys.stderr, err print >> sys.stderr, err
return False
class ReplicationError(Exception): class ReplicationError(Exception):
@ -396,9 +399,13 @@ def main():
mountpoint = mountdmg(sparse_diskimage_path) mountpoint = mountdmg(sparse_diskimage_path)
if mountpoint: if mountpoint:
# install the product to the mounted sparseimage volume # install the product to the mounted sparseimage volume
install_product( success = install_product(
product_info[product_id]['DistributionPath'], product_info[product_id]['DistributionPath'],
mountpoint) mountpoint)
if not success:
print >> sys.stderr, 'Product installation failed.'
unmountdmg(mountpoint)
exit(-1)
print 'Product downloaded and installed to %s' % sparse_diskimage_path print 'Product downloaded and installed to %s' % sparse_diskimage_path
if not args.compress: if not args.compress:
unmountdmg(mountpoint) unmountdmg(mountpoint)