2 # real Perl code begins here
4 # Adapted from Apple's uninstall-devtools.pl (Version 7 for Xcode Tools 1.2)
6 # BSD License: c.f. <http://www.opensource.org/licenses/bsd-license>
12 use vars qw
($do_nothing $print_donothing_removals $receipts_dir $verbose $noisy_warnings);
13 use vars qw
($suppress_spin $spin_counter $spin_state $spin_slower_downer);
14 use vars qw
(%exception_list $gen_dirs @gen_files @rmfiles @rmdirs @rmpkg);
16 #----------------------------------------------------------------------------------------
19 $print_donothing_removals = 1;
23 # One of rm -rf in this script uses $receipts_dir -- change with care.
24 $receipts_dir = "/Library/Receipts";
27 # '/usr/bin/aklog', '',
31 #$gen_dirs->{"/"}->{"Library"}->{"OpenAFS"}->{"Tools"} = {};
34 "/var/db/openafs/etc/cacheinfo",
35 "/var/db/openafs/etc/ThisCell",
36 "/var/db/openafs/etc/config/afsd.options",
37 "/var/db/openafs/etc/config/afs.conf",
38 "/var/db/openafs/etc/CellServDB.save",
39 "/var/db/openafs/etc/CellServDB.master.last",
40 "/var/db/openafs/etc/CellServDB",
41 "/var/db/openafs/etc/config/settings.plist",
44 #----------------------------------------------------------------------------------------
47 #if ($do_nothing == 0 && $< != 0)
49 # die "ERROR: Must be run with root permissions--prefix command with 'sudo'.\n";
55 # 0: dir of packages to remove
56 # 1: flag indicating whether to keep package receipts
57 # 2: flag indicating whether to supress spin indicator
61 @ARGV = ("$Bin/..", 0, 0);
63 $suppress_spin = defined ($ARGV[2]) && $ARGV[2];
70 print "Uninstalling OpenAFS package:\n\n";
72 remove_generated_files ();
73 remove_main_packages ();
74 remove_generated_directories ();
76 if ($do_nothing == 0) {
77 my @rmcmd = ('osascript', '-e', "do shell script \"/bin/rm -f @rmfiles; /bin/rmdir @rmdirs; /bin/rm -rf @rmpkg\" with administrator privileges");
79 my $retcode = $? >> 8;
81 print_warning ("Warning: There may have been a problem uninstalling\n");
86 print "\nFinished uninstalling.\n";
89 sub remove_main_packages
91 # opendir (DIR, $ARGV[0]) or die "ERROR: package directory $ARGV[0] not found\n";
92 # my @pkglist = grep /\.pkg$/, readdir DIR;
94 my @pkglist = ("org.openafs.OpenAFS-debug",
95 "org.openafs.OpenAFS",
97 "OpenAFS-debug-extension",
105 my $infopath = undef;
106 my $pkgname_plist_newpath = "/var/db/receipts/$pkgname.pkg.plist";
107 my $pkgname_bom_newpath = "/var/db/receipts/$pkgname.pkg.bom";
108 my $pkgname_plist_fullpath = "/Library/Receipts/$pkgname.pkg/Contents/Info.plist";
109 my $pkgname_bom_fullpath = "/Library/Receipts/$pkgname.pkg/Contents/Archive.bom";
111 if (-f $pkgname_plist_newpath && -r $pkgname_plist_newpath && -f $pkgname_bom_newpath && -r $pkgname_bom_newpath) {
112 print_verbose ("Removing package $pkgname.pkg\n");
113 $bompath = $pkgname_bom_newpath;
114 $infopath = $pkgname_plist_newpath;
116 if (-f $pkgname_plist_fullpath && -r $pkgname_plist_fullpath && -f $pkgname_bom_fullpath && -r $pkgname_bom_fullpath) {
117 print_verbose ("Removing package $pkgname.pkg\n");
118 $bompath = $pkgname_bom_fullpath;
119 $infopath = $pkgname_plist_fullpath;
125 next if (!defined ($bompath));
128 open (INFO, "$infopath") or next;
130 m/IFPkgFlagDefaultLocation/ or next;
135 $bomroot =~ />(.*)</;
137 $bomroot =~ s/^\/$//;
141 open (LSBOM, "/usr/bin/lsbom -l -f -p f '$bompath' |") or next;
146 next if (!defined ($1) || $1 eq "");
147 my $filename = $bomroot . $1;
149 remove_a_file ($filename);
155 open (LSBOM, "/usr/bin/lsbom -d -p f '$bompath' |") or next;
160 next if (!defined ($1) || $1 eq "");
161 my $directory = $bomroot . $1;
164 $rooth = add_directory_to_tree ($directory, $rooth);
170 print_warning ("Warning: \"$directory\" listed in BOM but not present on system.\n");
177 remove_empty_directories ($rooth, "/");
179 if (-d "$receipts_dir/$pkgname.pkg" ) {
180 remove_package_receipts ("$pkgname.pkg") if (!defined ($ARGV[1]) || !$ARGV[1]) ;
182 unshift(@rmfiles, "$bompath");
183 unshift(@rmfiles, "$infopath");
188 sub remove_generated_files
196 sub remove_generated_directories
198 remove_empty_directories ($gen_dirs, "/");
201 sub add_directory_to_tree
207 my @pathcomp = split /\//, $dir;
213 if ($cur_name eq "" || !defined ($cur_name))
217 if (!defined ($p->{"$cur_name"}))
219 $p->{$cur_name} = { };
221 $p = $p->{$cur_name};
226 sub remove_empty_directories
230 my $children = (scalar (keys %{$rooth}));
235 foreach my $dirname (sort keys %{$rooth})
238 $printpath = "$path/$dirname";
239 $printpath =~ s#^/*#/#;
240 remove_empty_directories ($rooth->{$dirname}, "$printpath");
241 $dirs_remain = 1 if (-d "$printpath");
245 if ($dirs_remain == 0)
247 maybe_remove_ds_store ("$path");
250 remove_a_dir ("$path");
256 my $dirname = dirname ($fn);
257 my $basename = basename ($fn);
258 my $ufs_rsrc_file = "$dirname/._$basename";
261 return if (!defined ($fn) || $fn eq "");
263 # Leave any files that are shared between packages alone.
264 if (defined($exception_list{$fn}))
268 print_warning ("Warning: file \"$fn\" intentionally not removed, even though it's in the BOM.\n");
273 if (! -f $fn && ! -l $fn)
277 print_warning ("Warning: file \"$fn\" present in BOM but not found on disc.\n");
282 if ($do_nothing == 1)
284 print_donothing ("rm $fn\n");
285 print_donothing ("rm $ufs_rsrc_file\n") if ( -f $ufs_rsrc_file);
289 unshift(@rmfiles, "$fn");
290 unshift(@rmfiles, "$ufs_rsrc_file") if ( -f $ufs_rsrc_file);
299 return if (!defined ($dir) || $dir eq "" || $dir eq "/" || $dir eq "/usr");
304 print_warning ("Warning: directory \"$dir\" present in BOM but not found on disc.\n");
309 if ($do_nothing == 1)
311 print_donothing ("rmdir $dir\n");
315 push(@rmdirs, "$dir");
319 sub remove_package_receipts
322 $pkgname =~ s#/##g; # There shouldn't be any path seps in the pkg name...
323 return if (!defined ($pkgname) || $pkgname eq ""
324 || $pkgname eq "." || $pkgname eq "..");
326 my $pkgdir = "$receipts_dir/$pkgname";
327 return if (!defined ($pkgdir) || $pkgdir eq "" || ! -d $pkgdir);
329 push(@rmpkg, "$pkgdir");
333 sub maybe_remove_ds_store
337 return if (!defined ($path) || $path eq "" || $path eq "/" || $path eq "/usr");
338 return if (! -f "$path/.DS_Store");
340 open (LS, "/bin/ls -a '$path' |");
344 next if (m#^\.$# || m#^\.\.$#);
349 if ($filecount == 1 && -f "$path/.DS_Store")
351 remove_a_file ("$path/.DS_Store");
358 return if ($print_donothing_removals != 1);
366 return if ($verbose != 1);
387 print " \b" unless ($suppress_spin);
392 $spin_slower_downer = 150;
397 $spin_slower_downer = 75;
402 return if ($suppress_spin);
404 if (($spin_counter % $spin_slower_downer) == 0)
406 my $spin_chars = "|/-\\";
407 my $c = substr ($spin_chars, $spin_state % 4, 1);
409 print "\e[7m$c\e[m\b";
415 #----------------------------------------------------------------------------------------