Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Dec 18, 2011
0 parents commit 57d4a25
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 0 deletions.
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2011 Michal Papis

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

http: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.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# OSX Packages Uninstaller

This software is aimed to help manage packages uninstalling in OSX.

## Installation

Installation is as simple as:

[sudo] bash < <(curl -sL https://raw.github.com/mpapis/pkg_uninstaller/master/pkg-installer)

Adding to PATH, for system installation (with sudo):

echo 'PATH=$PATH:/opt/pkg_uninstaller' >> /etc/profile

Adding PATH when installed as user (without sudo):

echo 'PATH=$PATH:$HOME/.pkg_uninstaller' >> $HOME/.bash_profile

Note the single quotes are important in both cases.

## Installing package file

Install packages with:

pkg-install <package_file.pkg>

This will create `uninstall_<package_file_pkg>.sh` in current directory.

To uninstall this package just execute `./uninstall_<package_file_pkg>.sh`.

### Example

# coming soon

## Uninstalling single packages by name.

List available package names (possibly filtering by [name]):

pkg-list [name]

Uninstall package:

pkg-uninstall <name>

## Using internally in package to build uninstaller

1. You have to bundle `pkg-wrapper` with your application
and install it to disk before executing the hook bellow.

1. In before installing hook call this script:

#!/bin/bash

pkg-wrapper before "your package name"

1. In after installing hook call this script:

#!/bin/bash

pkg-wrapper before "your package name" /path/to/uninstaller_name.sh

1. In uninstall hook call:

#!/bin/bash

/path/to/uninstaller_name.sh
rm /path/to/uninstaller_name.sh
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
137 changes: 137 additions & 0 deletions pkg-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env bash

: \
TMPDIR:${TMPDIR:=/tmp}: \
pkg_list_prefix:${pkg_list_prefix:=${TMPDIR}/.pkg_list}:

__pkg_extract_function()
{
type $1 | sed '1 d; 2 s/ //;'
}

__pkg_list()
{
pkgutil --pkgs
}

__pkg_install_before()
{
__pkg_list > ${pkg_list_prefix}_before
}

__pkg_install_after()
{
__pkg_list > ${pkg_list_prefix}_after

diff --normal ${pkg_list_prefix}_before ${pkg_list_prefix}_after |
awk '/^>/{print $2}' > ${pkg_list_prefix}_new

rm ${pkg_list_prefix}_before ${pkg_list_prefix}_after
}

__pkg_uninstall_pkg()
{
typeset _file _package
_package=$1

while read _file
do
if ! pkgutil --file-info "${_file}" | grep "^pkgid: " | grep -v ${_package} >/dev/null
then
rm -rf "${_file}"
fi
done < <(pkgutil --files ${_package})
}

__pkg_build_uninstaller()
{
{
printf "#!/usr/bin/env bash\n\n"
__pkg_extract_function __pkg_uninstall_pkg
printf "\nprintf 'Uninstalling $1\\n'\n\n"
awk 'print "__pkg_uninstall_pkg $1"' < ${pkg_list_prefix}_new
printf "\n\nprintf 'Uninstalled $1\\n'\n"
} > $2
chmod +x $2
}

__pkg_install_file()
{
__pkg_install_before
installer -pkg $1 -target /
__pkg_install_after
__pkg_build_uninstaller $1 $2
}

__pkg_install_self()
{
(
typeset _path
if (( UID ))
then _path="$HOME/.pkg_uninstaller"
else _path="/opt/pkg_uninstaller"
fi

mkdir -p "${_path}" && printf "Installing to ${_path}\n" || {
printf "Can not create ${_path}\n"
return 1
}
cd "${_path}"

curl -L https://github.com/mpapis/pkg_uninstaller/tarball/master -o package.tgz || {
printf "Can not download package.\n"
return 2
}

tar xzf package.tgz || {
printf "Can not extract package.\n"
return 3
}
rm -f package.tgz

printf "
Thank you for using pkg_uninstaller.
Now add ${_path} to your PATH.
~Michal
"
)
}

case $(basename $0) in
(*sh)
__pkg_install_self "$@"
;;
(pkg-list)
if [[ -n "$1" ]]
then
__pkg_list | grep "$1"
else
__pkg_list
fi
;;
(pkg-install)
__pkg_install_file $1 uninstall_${1//./_}.sh
;;
(pkg-uninstall)
for _pkg in $@
do
__pkg_uninstall_pkg ${_pkg}
done
;;
(pkg-wrapper)
pkg_list_prefix=${TMPDIR}/.pkg_list_${2// /_}
case "$1" in
(before)
__pkg_install_before
;;
(after)
__pkg_install_after
__pkg_build_uninstaller $2 $3
;;
esac
;;
(*)
echo "ERROR: unknown binary $0." >&2
exit 1
;;
esac
1 change: 1 addition & 0 deletions pkg-list
1 change: 1 addition & 0 deletions pkg-uninstall
1 change: 1 addition & 0 deletions pkg-wrapper

0 comments on commit 57d4a25

Please sign in to comment.