#!/bin/bash # # bomremove - removes all files from a MacOS X installer package # (Warning: use at your own risk!) # # Author: Christoph Dalitz # License: Freely distributable under the GPL # History: # 2005-01-21 first creation # PGM="`basename $0`" USAGE="Usage:\n\t$PGM [-n] [-f] \n\ Purpose:\n\ \tRemoves all files listet in an OSX package list (Archive.bom).\n\ \tThese files are stored in /Library/Receipts/.pkg/Contents.\n\ \tNote that $PGM does not remove the package description itself,\n\ \tyou must do this manually afterwards\n\ Warning:\n\ \tUse this script at your own risk!\n\ \tTo see what this commandwould do, use the option -n (noexec)\n\ Options:\n\ \t-n only print statements, do not execute them\n\ \t-f skip interactive question" BOMFILE="" NOEXEC="no" FORCE="no" # get command line arguments while [ $# -gt 0 ] do case "$1" in -n) NOEXEC="YES";; -f) FORCE="YES";; -*) echo -e "$USAGE" 1>&2; exit 1;; *) BOMFILE="$1";; esac shift done if [ -z "$BOMFILE" -o ! -e "$BOMFILE" ] then echo -e "$USAGE" 1>&2 exit 1 fi # interactive question if [ "$FORCE" = "no" -a "$NOEXEC" = "no" ] then echo -n -e "This will remove all files from this package!\n\ To first see what this statement would do, use the option -n (noexec)\n\ Proceed? [Y/n] " read ok test "$ok" = "n" -o "$ok" = "N" && exit 0 fi # list of directories DIRFILES="" # delete plain files first and remember directories for later for f in `lsbom -p f "$BOMFILE"` do f="`echo \"$f\" | sed 's/^\.//'`" # remove leading dot if [ ! -z "$f" ]; then if [ -f "$f" ]; then echo "rm $f" test "$NOEXEC" = "no" && rm "$f" elif [ -d "$f" ]; then DIRFILES="$DIRFILES\n$f" else echo "not found: $f" fi fi done # remove empty directories # to catch them all we need to sort them so that subdirs come first echo -e "$DIRFILES" | sort -r | while read d do if [ ! -z "$d" ]; then echo "rmdir $d" test "$NOEXEC" = "no" && rmdir "$d" fi done