mirror of
https://github.com/munki/munki.git
synced 2026-04-30 17:29:21 -05:00
Refactring of munkilib/installer/core.py
This commit is contained in:
@@ -146,6 +146,61 @@ def item_prereqs_in_skipped_items(item, skipped_items):
|
||||
return matched_prereqs
|
||||
|
||||
|
||||
def requires_restart(item):
|
||||
'''Returns boolean to indicate if the item needs a restart'''
|
||||
return (item.get("RestartAction") == "RequireRestart" or
|
||||
item.get("RestartAction") == "RecommendRestart")
|
||||
|
||||
|
||||
def handle_apple_package_install(item, itempath):
|
||||
'''Process an Apple package for install. Returns retcode, needs_restart'''
|
||||
needs_restart = False
|
||||
suppress_bundle_relocation = item.get("suppress_bundle_relocation", False)
|
||||
display.display_debug1(
|
||||
"suppress_bundle_relocation: %s", suppress_bundle_relocation)
|
||||
if pkgutils.hasValidDiskImageExt(itempath):
|
||||
display.display_status_minor(
|
||||
"Mounting disk image %s" % item["installer_item"])
|
||||
mount_with_shadow = suppress_bundle_relocation
|
||||
# we need to mount the diskimage as read/write to be able to
|
||||
# modify the package to suppress bundle relocation
|
||||
mountpoints = dmgutils.mountdmg(itempath, use_shadow=mount_with_shadow)
|
||||
if mountpoints == []:
|
||||
display.display_error(
|
||||
"No filesystems mounted from %s", item["installer_item"])
|
||||
return (-99, False)
|
||||
if processes.stop_requested():
|
||||
dmgutils.unmountdmg(mountpoints[0])
|
||||
return (-99, False)
|
||||
|
||||
retcode = -99 # in case we find nothing to install
|
||||
needtorestart = False
|
||||
if pkgutils.hasValidInstallerItemExt(item.get('package_path', '')):
|
||||
# admin has specified the relative path of the pkg on the DMG
|
||||
# this is useful if there is more than one pkg on the DMG,
|
||||
# or the actual pkg is not at the root of the DMG
|
||||
fullpkgpath = os.path.join(mountpoints[0], item['package_path'])
|
||||
if os.path.exists(fullpkgpath):
|
||||
(retcode, needtorestart) = pkg.install(fullpkgpath, item)
|
||||
else:
|
||||
# no relative path to pkg on dmg, so just install all
|
||||
# pkgs found at the root of the first mountpoint
|
||||
# (hopefully there's only one)
|
||||
(retcode, needtorestart) = pkg.installall(mountpoints[0], item)
|
||||
needs_restart = needtorestart or requires_restart(item)
|
||||
dmgutils.unmountdmg(mountpoints[0])
|
||||
elif pkgutils.hasValidPackageExt(itempath):
|
||||
(retcode, needtorestart) = pkg.install(itempath, item)
|
||||
needs_restart = needtorestart or requires_restart(item)
|
||||
else:
|
||||
# we didn't find anything we know how to install
|
||||
munkilog.log(
|
||||
"Found nothing we know how to install in %s" % itempath)
|
||||
retcode = -99
|
||||
|
||||
return (retcode, needs_restart)
|
||||
|
||||
|
||||
def install_with_info(
|
||||
dirpath, installlist, only_unattended=False, applesus=False):
|
||||
"""
|
||||
@@ -219,108 +274,53 @@ def install_with_info(
|
||||
display.display_error(
|
||||
"Installer item %s was not found.", item["installer_item"])
|
||||
return restartflag, skipped_installs
|
||||
|
||||
# Adobe installs
|
||||
if installer_type.startswith("Adobe"):
|
||||
retcode = adobeutils.do_adobe_install(item)
|
||||
if retcode == 0:
|
||||
if (item.get("RestartAction") == "RequireRestart" or
|
||||
item.get("RestartAction") == "RecommendRestart"):
|
||||
restartflag = True
|
||||
if retcode == 0 and requires_restart(item):
|
||||
restartflag = True
|
||||
if retcode == 8:
|
||||
# Adobe Setup says restart needed.
|
||||
restartflag = True
|
||||
retcode = 0
|
||||
# copy_from_dmg install
|
||||
elif installer_type == "copy_from_dmg":
|
||||
retcode = dmg.copy_from_dmg(
|
||||
itempath, item.get('items_to_copy'))
|
||||
if retcode == 0:
|
||||
if (item.get("RestartAction") == "RequireRestart" or
|
||||
item.get("RestartAction") == "RecommendRestart"):
|
||||
restartflag = True
|
||||
retcode = dmg.copy_from_dmg(itempath, item.get('items_to_copy'))
|
||||
if retcode == 0 and requires_restart(item):
|
||||
restartflag = True
|
||||
# appdmg install (depercated)
|
||||
elif installer_type == "appdmg":
|
||||
display.display_warning(
|
||||
"install_type 'appdmg' is deprecated. Use 'copy_from_dmg'.")
|
||||
retcode = dmg.copy_app_from_dmg(itempath)
|
||||
# configuration profile install
|
||||
elif installer_type == 'profile':
|
||||
# profiles.install_profile returns True/False
|
||||
retcode = 0
|
||||
identifier = item.get('PayloadIdentifier')
|
||||
if not profiles.install_profile(itempath, identifier):
|
||||
retcode = -1
|
||||
elif installer_type == "nopkg": # Packageless install
|
||||
if (item.get("RestartAction") == "RequireRestart" or
|
||||
item.get("RestartAction") == "RecommendRestart"):
|
||||
restartflag = True
|
||||
# nopkg (Packageless) install
|
||||
elif installer_type == "nopkg":
|
||||
restartflag = requires_restart(item)
|
||||
# unknown installer_type
|
||||
elif installer_type != "":
|
||||
# we've encountered an installer type
|
||||
# we don't know how to handle
|
||||
display.display_error(
|
||||
"Unsupported install type: %s" % installer_type)
|
||||
retcode = -99
|
||||
# better be Apple installer package
|
||||
else:
|
||||
# better be Apple installer package
|
||||
suppress_bundle_relocation = item.get(
|
||||
"suppress_bundle_relocation", False)
|
||||
display.display_debug1(
|
||||
"suppress_bundle_relocation: %s",
|
||||
suppress_bundle_relocation)
|
||||
if pkgutils.hasValidDiskImageExt(itempath):
|
||||
display.display_status_minor(
|
||||
"Mounting disk image %s" % item["installer_item"])
|
||||
mount_with_shadow = suppress_bundle_relocation
|
||||
# we need to mount the diskimage as read/write to
|
||||
# be able to modify the package to suppress bundle
|
||||
# relocation
|
||||
mountpoints = dmgutils.mountdmg(
|
||||
itempath, use_shadow=mount_with_shadow)
|
||||
if mountpoints == []:
|
||||
display.display_error(
|
||||
"No filesystems mounted from %s",
|
||||
item["installer_item"])
|
||||
return restartflag, skipped_installs
|
||||
if processes.stop_requested():
|
||||
dmgutils.unmountdmg(mountpoints[0])
|
||||
return restartflag, skipped_installs
|
||||
(retcode, need_to_restart) = handle_apple_package_install(
|
||||
item, itempath)
|
||||
if need_to_restart:
|
||||
restartflag = True
|
||||
|
||||
retcode = -99 # in case we find nothing to install
|
||||
needtorestart = False
|
||||
if pkgutils.hasValidInstallerItemExt(
|
||||
item.get('package_path', '')):
|
||||
# admin has specified the relative path of the pkg
|
||||
# on the DMG
|
||||
# this is useful if there is more than one pkg on
|
||||
# the DMG, or the actual pkg is not at the root
|
||||
# of the DMG
|
||||
fullpkgpath = os.path.join(
|
||||
mountpoints[0], item['package_path'])
|
||||
if os.path.exists(fullpkgpath):
|
||||
(retcode, needtorestart) = pkg.install(
|
||||
fullpkgpath, item)
|
||||
else:
|
||||
# no relative path to pkg on dmg, so just install all
|
||||
# pkgs found at the root of the first mountpoint
|
||||
# (hopefully there's only one)
|
||||
(retcode, needtorestart) = pkg.installall(
|
||||
mountpoints[0], item)
|
||||
if (needtorestart or
|
||||
item.get("RestartAction") == "RequireRestart" or
|
||||
item.get("RestartAction") == "RecommendRestart"):
|
||||
restartflag = True
|
||||
dmgutils.unmountdmg(mountpoints[0])
|
||||
elif pkgutils.hasValidPackageExt(itempath):
|
||||
(retcode, needtorestart) = pkg.install(itempath, item)
|
||||
if (needtorestart or
|
||||
item.get("RestartAction") == "RequireRestart" or
|
||||
item.get("RestartAction") == "RecommendRestart"):
|
||||
restartflag = True
|
||||
|
||||
else:
|
||||
# we didn't find anything we know how to install
|
||||
munkilog.log(
|
||||
"Found nothing we know how to install in %s"
|
||||
% itempath)
|
||||
retcode = -99
|
||||
if processes.stop_requested():
|
||||
return restartflag, skipped_installs
|
||||
|
||||
# install succeeded. Do we have a postinstall_script?
|
||||
if retcode == 0 and 'postinstall_script' in item:
|
||||
# only run embedded postinstall script if the install did not
|
||||
# return a failure code
|
||||
@@ -417,16 +417,14 @@ def install_with_info(
|
||||
itempath = os.path.join(dirpath, current_installer_item)
|
||||
if os.path.exists(itempath):
|
||||
if os.path.isdir(itempath):
|
||||
retcode = subprocess.call(
|
||||
["/bin/rm", "-rf", itempath])
|
||||
retcode = subprocess.call(["/bin/rm", "-rf", itempath])
|
||||
else:
|
||||
# flat pkg or dmg
|
||||
retcode = subprocess.call(["/bin/rm", itempath])
|
||||
if pkgutils.hasValidDiskImageExt(itempath):
|
||||
shadowfile = os.path.join(itempath, ".shadow")
|
||||
if os.path.exists(shadowfile):
|
||||
retcode = subprocess.call(
|
||||
["/bin/rm", shadowfile])
|
||||
retcode = subprocess.call(["/bin/rm", shadowfile])
|
||||
|
||||
return (restartflag, skipped_installs)
|
||||
|
||||
@@ -511,14 +509,13 @@ def process_removals(removallist, only_unattended=False):
|
||||
uninstallmethod = item['uninstall_method']
|
||||
if uninstallmethod == "removepackages":
|
||||
if 'packages' in item:
|
||||
if item.get('RestartAction') == "RequireRestart":
|
||||
restart_flag = True
|
||||
restart_flag = requires_restart(item)
|
||||
retcode = rmpkgs.removepackages(item['packages'],
|
||||
forcedeletebundles=True)
|
||||
if retcode:
|
||||
if retcode == -128:
|
||||
message = ("Uninstall of %s was "
|
||||
"cancelled." % display_name)
|
||||
message = (
|
||||
"Uninstall of %s was cancelled." % display_name)
|
||||
else:
|
||||
message = "Uninstall of %s failed." % display_name
|
||||
display.display_error(message)
|
||||
@@ -533,6 +530,7 @@ def process_removals(removallist, only_unattended=False):
|
||||
retcode = remove_copied_items(item.get('items_to_remove'))
|
||||
|
||||
elif uninstallmethod == "remove_app":
|
||||
# deprecated with appdmg!
|
||||
remove_app_info = item.get('remove_app_info', None)
|
||||
if remove_app_info:
|
||||
path_to_remove = remove_app_info['path']
|
||||
@@ -559,20 +557,19 @@ def process_removals(removallist, only_unattended=False):
|
||||
else:
|
||||
display.display_error(
|
||||
"Profile removal info missing from %s", display_name)
|
||||
|
||||
elif uninstallmethod == 'uninstall_script':
|
||||
retcode = scriptutils.run_embedded_script(
|
||||
'uninstall_script', item)
|
||||
if (retcode == 0 and
|
||||
item.get('RestartAction') == "RequireRestart"):
|
||||
if retcode == 0 and requires_restart(item):
|
||||
restart_flag = True
|
||||
|
||||
elif os.path.exists(uninstallmethod) and \
|
||||
os.access(uninstallmethod, os.X_OK):
|
||||
elif (os.path.exists(uninstallmethod) and
|
||||
os.access(uninstallmethod, os.X_OK)):
|
||||
# it's a script or program to uninstall
|
||||
retcode = scriptutils.run_script(
|
||||
display_name, uninstallmethod, 'uninstall script')
|
||||
if (retcode == 0 and
|
||||
item.get('RestartAction') == "RequireRestart"):
|
||||
if retcode == 0 and requires_restart(item):
|
||||
restart_flag = True
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user