OSX에서 pkg 삭제하기
다음과 같은 좋은 script를 발견했다. 출처
사용법은
/uninstall.pl --find TeX
과 같이 --find 뒤에 단어를 입력하면, 단어가 포함된 패키지를 찾아서 알려준다. 그러면
sudo ./uninstall.pl --pkg_id org.virtualbox.pkg.virtualboxcli
와 같이 삭제를 하면 된다.
혹시 사이트가 사라지면 곤란하므로 복사해 놓는다.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
GetOptions(
'pkg_id=s' => \my $pkg_id,
'debug' => \my $debug,
'find=s' => \my $find
);
my $home_dir = "/Users/" . $ENV{USER};
my $pkg_util = "/usr/sbin/pkgutil";
$pkg_id or $find or die "usage: $0 --pkg_id [--debug] or $0 --find ";
sub finding_packages
{
my $name = shift;
print "\nFinding packages for $name\n\n";
my $output = `$pkg_util --pkgs`;
my @packages = $output =~ /^(.*$name.*)$/mig;
foreach my $package (@packages) {
print "Package: '$package'\n";
}
}
sub installed_path
{
my $pkg_id = shift;
my $volume;
my $path;
my $output = `$pkg_util --pkg-info $pkg_id`;
if ($output =~ /volume: (.*)\n/) {
$volume = $1;
}
if ($output =~ /location: (.*)\n/) {
if ($1 eq "(null)") {
$path = "";
} else {
$path = $1;
}
}
return ($volume . $path);
}
sub uninstall_files
{
my $pkg_id = shift;
my $path = installed_path($pkg_id);
print "\nUninstalling files for $pkg_id from $path\n\n";
my $output = `$pkg_util --only-files --files $pkg_id`;
my @files = split(/\n/, $output);
foreach my $file (@files) {
my $full_path = $path . $file;
if ($debug) {
print "Deleted '$full_path'\n";
} else {
print "Deleted '$full_path'\n" if unlink($full_path);
}
}
}
sub delete_empty_dirs
{
my $pkg_id = shift;
my $path = installed_path($pkg_id);
print "\nDeleting empty dirs for $pkg_id from $path\n\n";
my $output = `$pkg_util --only-dir --files $pkg_id`;
my @dirs = split(/\n/, $output);
foreach my $dir (@dirs) {
my $full_path = $path . $dir;
if ($debug) {
print "Deleted dir '$full_path'\n";
} else {
print "Deleted dir '$full_path'\n" if rmdir($full_path);
}
}
}
sub forget_pkg
{
my $pkg_id = shift;
my $output = `$pkg_util --forget $pkg_id`;
print "$output\n";
}
if ($find) {
finding_packages($find);
}
if ($pkg_id) {
uninstall_files($pkg_id);
delete_empty_dirs($pkg_id);
forget_pkg($pkg_id) if (!$debug);
}
댓글
댓글 쓰기