mirror of
https://github.com/munki/munki.git
synced 2026-04-30 09:19:31 -05:00
Add cleanup scripts (#1025)
* Run cleanup scripts if they're there * Cleanup script, add to build script * okay * I'm all shelled out * Comment for future greg
This commit is contained in:
@@ -218,6 +218,24 @@ def runScript(script, display_name, runtype):
|
||||
display.display_warning(unicode_or_str(err))
|
||||
return result
|
||||
|
||||
def cleanup(runtype):
|
||||
"""
|
||||
If there are executables inside the cleanup directory, run them and remove them if successful
|
||||
"""
|
||||
cleanupdir = os.path.join(os.path.realpath(os.path.dirname(sys.argv[0])), 'cleanup')
|
||||
if not os.path.isdir(cleanupdir):
|
||||
# path doesn't exist or isn't a directory
|
||||
return
|
||||
|
||||
# get only filenames (and not directory names) from cleanupdir
|
||||
(_, _, filenames) = next(os.walk(cleanupdir))
|
||||
for filename in filenames:
|
||||
script_path = os.path.join(cleanupdir, filename)
|
||||
result = runScript(script_path, 'cleanup', runtype)
|
||||
if not result:
|
||||
# no output is a good thing
|
||||
os.remove(script_path)
|
||||
|
||||
|
||||
def doInstallTasks(do_apple_updates, only_unattended=False):
|
||||
"""Perform our installation/removal tasks.
|
||||
@@ -824,6 +842,9 @@ def main():
|
||||
# Set environment variable for verbosity
|
||||
os.environ['MUNKI_VERBOSITY_LEVEL'] = str(options.verbose)
|
||||
|
||||
# Run cleanup scripts if required
|
||||
cleanup(runtype)
|
||||
|
||||
if options.installonly:
|
||||
# we're only installing, not checking, so we should copy
|
||||
# some report values from the prior run
|
||||
@@ -1156,7 +1177,7 @@ def main():
|
||||
time.sleep(2)
|
||||
startLogoutHelper()
|
||||
elif osutils.getconsoleuser() == u'loginwindow':
|
||||
# someone is logged in, but we're sitting at the loginwindow
|
||||
# someone is logged in, but we're sitting at the loginwindow
|
||||
# due to to fast user switching so do nothing
|
||||
munkilog.log('Skipping user notification because we are at the'
|
||||
'loginwindow.')
|
||||
|
||||
@@ -52,7 +52,7 @@ Usage: $(basename "$0") [-i id] [-r root] [-o dir] [-c package] [-s cert]
|
||||
daemons without requiring a restart. Such a package is not
|
||||
suited for upgrade installs or install via Munki itself.
|
||||
-c plist Build a configuration package using the preferences defined in a
|
||||
plist file.
|
||||
plist file.
|
||||
-s cert_cn Sign distribution package with a Developer ID Installer
|
||||
certificate from keychain. Provide the certificate's Common
|
||||
Name. Ex: "Developer ID Installer: Munki (U8PN57A5N2)"
|
||||
@@ -422,6 +422,11 @@ mkdir -m 750 -p "$COREROOT/Library/Managed Installs/Cache"
|
||||
mkdir -m 750 -p "$COREROOT/Library/Managed Installs/catalogs"
|
||||
mkdir -m 755 -p "$COREROOT/Library/Managed Installs/manifests"
|
||||
|
||||
# copy in core cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/core_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/core_cleanup_scripts/" "$COREROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo core "$PKGTMP/info" norestart
|
||||
|
||||
@@ -454,6 +459,11 @@ echo "/usr/local/munki" > "$ADMINROOT/private/etc/paths.d/munki"
|
||||
chmod -R 755 "$ADMINROOT/private"
|
||||
chmod 644 "$ADMINROOT/private/etc/paths.d/munki"
|
||||
|
||||
# copy in admin cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/admin_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/admin_cleanup_scripts/" "$ADMINROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo admin "$PKGTMP/info" norestart
|
||||
|
||||
@@ -492,6 +502,11 @@ if [ "$APPSIGNINGCERT" != "" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# copy in app cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/app_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/app_cleanup_scripts/" "$APPROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo app "$PKGTMP/info" norestart
|
||||
|
||||
@@ -518,6 +533,12 @@ RESTARTFLAG=restart
|
||||
if [ "$MDMSTYLE" == "YES" ] ; then
|
||||
RESTARTFLAG=norestart
|
||||
fi
|
||||
|
||||
# copy in launchd cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/launchd_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/launchd_cleanup_scripts/" "$LAUNCHDROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
makeinfo launchd "$PKGTMP/info" "$RESTARTFLAG"
|
||||
|
||||
|
||||
@@ -551,6 +572,12 @@ done
|
||||
# Set permissions.
|
||||
chmod -R go-w "$APPUSAGEROOT/usr/local/munki"
|
||||
chmod +x "$APPUSAGEROOT/usr/local/munki"
|
||||
|
||||
# copy in app_usage cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/app_usage_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/app_usage_cleanup_scripts/" "$APPUSAGEROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo app_usage "$PKGTMP/info" norestart
|
||||
|
||||
@@ -570,9 +597,16 @@ chmod -R 755 "$PYTHONROOT/usr"
|
||||
cp -R "$MUNKIROOT/Python.framework" "$PYTHONROOT/usr/local/munki/"
|
||||
# Create symlink
|
||||
ln -s Python.framework/Versions/Current/bin/python3 "$PYTHONROOT/usr/local/munki/munki-python"
|
||||
|
||||
# Set permissions.
|
||||
chmod -R go-w "$PYTHONROOT/usr/local/munki"
|
||||
chmod +x "$PYTHONROOT/usr/local/munki"
|
||||
|
||||
# copy in python cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/python_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/python_cleanup_scripts/" "$PYTHONROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo python "$PKGTMP/info" norestart
|
||||
|
||||
@@ -592,6 +626,12 @@ ln -s /usr/bin/python "$NOPYTHONROOT/usr/local/munki/munki-python"
|
||||
# Set permissions.
|
||||
chmod -R go-w "$NOPYTHONROOT/usr/local/munki"
|
||||
chmod +x "$NOPYTHONROOT/usr/local/munki"
|
||||
|
||||
# copy in no_python cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/no_python_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/no_python_cleanup_scripts/" "$NOPYTHONROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo no_python "$PKGTMP/info" norestart
|
||||
|
||||
@@ -609,6 +649,12 @@ if [ "$BOOTSTRAPPKG" == "YES" ] ; then
|
||||
mkdir -p "$BOOTSTRAPROOT/Users/Shared"
|
||||
# Create bootstrap flag file
|
||||
touch "$BOOTSTRAPROOT/Users/Shared/.com.googlecode.munki.checkandinstallatstartup"
|
||||
|
||||
# copy in bootstrap cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/bootstrap_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/bootstrap_cleanup_scripts/" "$BOOTSTRAPROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo bootstrap "$PKGTMP/info" norestart
|
||||
fi
|
||||
@@ -627,6 +673,12 @@ if [ "$CONFPKG" == "YES" ] ; then
|
||||
mkdir -p "$CONFROOT/Library/Preferences"
|
||||
# Copy prefs file
|
||||
cp "$CONFFULLPATH" "$CONFROOT/Library/Preferences/ManagedInstalls.plist"
|
||||
|
||||
# copy in config cleanup scripts
|
||||
if [ -d "$MUNKIROOT/code/tools/pkgresources/config_cleanup_scripts/" ] ; then
|
||||
rsync -a --exclude '*.pyc' --exclude '.DS_Store' "$MUNKIROOT/code/tools/pkgresources/config_cleanup_scripts/" "$CONFROOT/usr/local/munki/cleanup/"
|
||||
fi
|
||||
|
||||
# Create package info file.
|
||||
makeinfo config "$PKGTMP/info" norestart
|
||||
fi
|
||||
@@ -833,7 +885,7 @@ for pkg in $ALLPKGS ; do
|
||||
esac
|
||||
echo
|
||||
echo "Packaging munkitools_$pkg.pkg"
|
||||
|
||||
|
||||
# use sudo here so pkgutil doesn't complain when it tries to
|
||||
# descend into root/Library/Managed Installs/*
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ -f "/usr/local/munki/python" ]; then
|
||||
/bin/rm /usr/local/munki/python
|
||||
fi
|
||||
|
||||
if [ -d "/usr/local/munki/Python.framework/Versions/3.7" ]; then
|
||||
/bin/rm -r /usr/local/munki/Python.framework/Versions/3.7
|
||||
fi
|
||||
Reference in New Issue
Block a user