Files
munki/code/client/removepackages
Greg Neagle b9f9fffccc Revert "munki: rename "/usr/local/munki/python" symlink to "munki-python" (#997)"
This change is still a good future goal, but is causing problems that are too difficult to work around right now and is delaying the vital release of Munki 5.1 for Big Sur compatibility.

This reverts commit 3bb91cabca.
2020-09-15 09:04:47 -07:00

96 lines
3.5 KiB
Python
Executable File

#!/usr/local/munki/python
# encoding: utf-8
#
# Copyright 2009-2020 Greg Neagle.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
removepackages
munkilib/removepackages.py should be a symlink to this file for backwards
compatibility
Command-line tool to analyze installed packages and remove
files unique to the packages given. No attempt
is made to revert to older versions of a file when uninstalling;
only file removals are done.
"""
from __future__ import absolute_import, print_function
import optparse
import os
import sys
from munkilib import display
from munkilib import munkistatus
from munkilib.installer import rmpkgs
def main():
'''Used when calling removepackages.py directly from the command line.'''
# command-line options
parser = optparse.OptionParser()
parser.set_usage('''Usage: %prog [options] package_id ...''')
parser.add_option('--forcedeletebundles', '-f', action='store_true',
help='Delete bundles even if they aren\'t empty.')
parser.add_option('--listfiles', '-l', action='store_true',
help='List the filesystem objects to be removed, '
'but do not actually remove them.')
parser.add_option('--rebuildpkgdb', action='store_true',
help='Force a rebuild of the internal package database.')
parser.add_option('--noremovereceipts', action='store_true',
help='''Do not remove receipts and boms from
/Library/Receipts and update internal package
database.''')
parser.add_option('--noupdateapplepkgdb', action='store_true',
help='Do not update Apple\'s package database. '
'If --noremovereceipts is also given, this is implied')
parser.add_option('--munkistatusoutput', '-m', action='store_true',
help='Output is formatted for use with MunkiStatus.')
parser.add_option('--verbose', '-v', action='count', default=1,
help='More verbose output. May be specified multiple '
'times.')
# Get our options and our package names
options, pkgnames = parser.parse_args()
# check to see if we're root
if os.geteuid() != 0:
print("You must run this as root!", file=sys.stderr)
exit(-1)
# set the display globals
display.munkistatusoutput = True
display.verbose = options.verbose
if options.munkistatusoutput:
pkgcount = len(pkgnames)
munkistatus.message("Removing %s packages..." % pkgcount)
munkistatus.detail("")
retcode = rmpkgs.removepackages(
pkgnames,
forcedeletebundles=options.forcedeletebundles,
listfiles=options.listfiles,
rebuildpkgdb=options.rebuildpkgdb,
noremovereceipts=options.noremovereceipts,
noupdateapplepkgdb=options.noupdateapplepkgdb)
if options.munkistatusoutput:
munkistatus.quit_app()
exit(retcode)
if __name__ == '__main__':
main()