Skip to content

Instantly share code, notes, and snippets.

@vpetersson
Last active June 14, 2019 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpetersson/f9970eb394adfa1173362a1aa71b2c4b to your computer and use it in GitHub Desktop.
Save vpetersson/f9970eb394adfa1173362a1aa71b2c4b to your computer and use it in GitHub Desktop.
Helper script for cleaning up pkg files
#!/bin/bash
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# -*- sh-basic-offset: 4 -*-
set -euo pipefail
IFS=$'\n\t'
if [[ -z ${1} ]]; then
echo "Package name must be used as the argument."
exit 1
fi
PACKAGE=${1}
if [[ -z $(pkgutil --pkgs | grep ${PACKAGE}) ]]; then
echo "Package ${PACKAGE} does not exist."
exit 1
fi
ROOT=$(pkgutil --pkg-info ${PACKAGE} | grep volume | sed 's/volume: //g')
APP_PATH=$(pkgutil --pkg-info ${PACKAGE} | grep location | sed 's/location: //g')
GET_FILES=$(pkgutil --only-files --files ${PACKAGE})
GET_DIRS=$(pkgutil --only-dirs --files ${PACKAGE})
echo "Listing files and directories to be deleted:"
for f in ${GET_FILES}; do
echo ${ROOT}${APP_PATH}/${f}
done
for f in ${GET_DIRS}; do
echo ${ROOT}${APP_PATH}/${f}
done
echo -e "\n\nWARNING!\nLook throught the list carefully!\nThis could cause significant harm to your system.\n\n"
read -p "Delete files and directories? (y/N) " rm_files
if [[ ${rm_files} != 'y' ]]; then
echo "Aborting"
exit 1
fi
for f in ${GET_FILES}; do
rm -fv "${ROOT}${APP_PATH}/${f}"
done
for f in ${GET_DIRS}; do
rm -rfv "${ROOT}${APP_PATH}/${f}"
done
read -p "Forget package? (y/N) " forget_pkg
if [[ ${forget_pkg} == 'y' ]]; then
pkgutil --forget ${PACKAGE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment