ruby tk -- how do you get it working?

7

7stud --

John said:
The one click installer is fine. It is stripped down a bit, but
everything is in standard locations in /usr/local/
This includes /usr/local/bin and /usr/local/lib/
Basically, it's very similar to the Hivelogic installation. You can
either, install over it (use the Hivelogic tutorial, please) OR
simply rm -rf the directories for what got installed.
It uses an OS X installer, so it should have an item in ~/Library/
Receipts/ OR in /Library/Receipts
launching that item will relaunch the installer. It will allow you to
get a manifest of installation items and some installers have an
uninstaller.

There is a file in /Library/Receipts called:

Ruby One-Click Installer for OSX Tiger.pkg

However, when I click on that file, it launches the installer. I don't
see how to get a manifest, and there is no uninstaller listed. I
progressed through the steps until I got to the last step where you are
supposed to click 'install', and there was nothing mentioned about a
manifest or an uninstaller.
 
M

Morton Goldberg

There is a file in /Library/Receipts called:

Ruby One-Click Installer for OSX Tiger.pkg

However, when I click on that file, it launches the installer. I
don't
see how to get a manifest, and there is no uninstaller listed. I
progressed through the steps until I got to the last step where you
are
supposed to click 'install', and there was nothing mentioned about a
manifest or an uninstaller.

After the installer launches, select File>Show Files from the menu
bar. Or just hit cmd-I.

Regards, Morton
 
7

7stud --

Morton said:
After the installer launches, select File>Show Files from the menu
bar. Or just hit cmd-I.

Regards, Morton

Ok, I did that, and I would estimate that there are around 500-1500
files listed. Here are the first few:
 
7

7stud --

7stud said:
1) I can't go through all those and delete them by hand.

2) That leading . confuses me. That doesn't seem like in can be the
current directory. The current directory is the Receipts directory, and
it has no sub directories.

...at least visible in Finder. I checked, though, and each file in
/Library/Receipts is a directory.
 
L

Leslie Viljoen

Ok, I did that, and I would estimate that there are around 500-1500
files listed. Here are the first few:

.
./usr
./usr/local
./usr/local/bin
./usr/local/bin/erb
./usr/local/bin/gem
./usr/local/bin/gem_mirror
./usr/local/bin/gem_server
./usr/local/bin/gemlock
./usr/local/bin/gemri
./usr/local/bin/gemwhich
./usr/local/bin/gpgen
./usr/local/bin/index_gem_repository.rb
./usr/local/bin/irb
./usr/local/bin/mongrel_rails
./usr/local/bin/ragel
./usr/local/bin/rake
./usr/local/bin/rdoc
./usr/local/bin/ri
./usr/local/bin/rlgen-cd
./usr/local/bin/rlgen-dot
./usr/local/bin/rlgen-java
./usr/local/bin/rlgen-ruby


1) I can't go through all those and delete them by hand.

You could search the drive for "rlgen-ruby". If it is only in /usr/local/bin,
you have it on good authority that the installed was in "/" when
it ran (so "." refers to "/").

You should then be able to:

cd /
for file in `cat /receipts/filelist.txt`; do ls -la $file; done

..then if you are happy with that list of file, you can do the more
dangerous:

cd /
for file in `cat /receipts/filelist.txt`; do rm $file; done

These should work on Linux under bash. OSX uses tcsh I think:
http://www.ss64.com/osx/

..so it looks the same but I haven't tested on the macbook.

Les
 
M

Morton Goldberg

Ok, I did that, and I would estimate that there are around 500-1500
files listed. Here are the first few:

.
./usr
./usr/local
./usr/local/bin
./usr/local/bin/erb
./usr/local/bin/gem
./usr/local/bin/gem_mirror
./usr/local/bin/gem_server
./usr/local/bin/gemlock
./usr/local/bin/gemri
./usr/local/bin/gemwhich
./usr/local/bin/gpgen
./usr/local/bin/index_gem_repository.rb
./usr/local/bin/irb
./usr/local/bin/mongrel_rails
./usr/local/bin/ragel
./usr/local/bin/rake
./usr/local/bin/rdoc
./usr/local/bin/ri
./usr/local/bin/rlgen-cd
./usr/local/bin/rlgen-dot
./usr/local/bin/rlgen-java
./usr/local/bin/rlgen-ruby


1) I can't go through all those and delete them by hand.

2) That leading . confuses me. That doesn't seem like in can be the
current directory. The current directory is the Receipts
directory, and
it has no sub directories.

1. Ruby is, among other things, a first-class scripting language. Use
your Ruby skills. Write a script to delete the files on the install
manifest if that's what you are set on doing.

2. The dot refers to current directory when the installer ran. In
this case, you can infer from the manifest that . == /, so you can
ignore the dot.

Regards, Morton
 
J

John Joyce

You could search the drive for "rlgen-ruby". If it is only in /usr/
local/bin,
you have it on good authority that the installed was in "/" when
it ran (so "." refers to "/").

You should then be able to:

cd /
for file in `cat /receipts/filelist.txt`; do ls -la $file; done

..then if you are happy with that list of file, you can do the more
dangerous:

cd /
for file in `cat /receipts/filelist.txt`; do rm $file; done

These should work on Linux under bash. OSX uses tcsh I think:
http://www.ss64.com/osx/

..so it looks the same but I haven't tested on the macbook.

Les
No. OS X uses Bash as default shell.
It used to use tcsh before 10.4
it's been Bash for several years...

At this point, I'm going to recommend the OP get a book such as UNIX
in a Nutshell from Oreilly.
It's a great reference to keep around.
If new to *nix get Learning Unix for Mac OS X Tiger (since that's
apparently the version you've got)
I'm not trying to say RTFM, but if you want to get farther with Ruby
(or Perl, Python, PHP, etc...) these books will help you get up to
speed on the unix things you should learn.

You'll feel a lot more comfortable with what you're doing, I promise.
Regardless, definitely go for the Hivelogic install, building it
yourself gives you some practice and experience with command line
tools. Nothing to fear. If you hose your system, reinstall. If you
don't already, do backups.
 
7

7stud --

John said:
No. OS X uses Bash as default shell.
It used to use tcsh before 10.4
it's been Bash for several years...

At this point, I'm going to recommend the OP get a book such as UNIX
in a Nutshell from Oreilly.
It's a great reference to keep around.
If new to *nix get Learning Unix for Mac OS X Tiger (since that's
apparently the version you've got)
I'm not trying to say RTFM, but if you want to get farther with Ruby
(or Perl, Python, PHP, etc...) these books will help you get up to
speed on the unix things you should learn.

You'll feel a lot more comfortable with what you're doing, I promise.
Regardless, definitely go for the Hivelogic install, building it
yourself gives you some practice and experience with command line
tools. Nothing to fear. If you hose your system, reinstall. If you
don't already, do backups.

I think it's really misleading for the main ruby site to promote a one
click installer for mac, where the one click installer website concludes
its promotional hype by saying, you have nothing to lose by installing
ruby 1.8.6 with the one click installer because its simple to uninstall.
That's a lie, and I don't think the main ruby site should promote con
artists.
 
T

Tim Ferrell

7stud said:
I think it's really misleading for the main ruby site to promote a one
click installer for mac, where the one click installer website concludes
its promotional hype by saying, you have nothing to lose by installing
ruby 1.8.6 with the one click installer because its simple to uninstall.
That's a lie, and I don't think the main ruby site should promote con
artists.

Uh, I understand your frustrations but, hey, relax a bit, okay? I
wouldn't say it was a lie - they just made assumptions about whether you
would have other software installed under /usr/local ... As a Mac user
I'm sure you know that *most* mac installs do not uninstall
automatically... but they do uninstall easily by deleting the app or
folder, which I suppose was what they were saying...

If you'd like help with a script to clean up the one-click installer
just say the word and I'll be glad to help... If you'd email me a list
of files that the installer installed I'll send you a script to safely
clean them up...

Anyway, going forward, I'd suggest you use MacPorts to install and
maintain a "non-Apple" version of Ruby - the Ruby port maintainer is
great about keeping it up to date with the latest patch level and you
can choose between version with and without tk... There are even a few
gui tools to manage installed ports if you prefer that kind of thing...

Cheers,
Tim
 
7

7stud --

Tim said:
Uh, I understand your frustrations but, hey, relax a bit, okay? I
wouldn't say it was a lie - they just made assumptions about whether you
would have other software installed under /usr/local ...

So some developer assumed that /usr/local would be empty except for
their install? Heck why didn't they just say, "Our install is easy to
uninstall: delete your hard drive and it's gone. What could be
simpler?"
As a Mac user
I'm sure you know that *most* mac installs do not uninstall
automatically... but they do uninstall easily by deleting the app or
folder, which I suppose was what they were saying...

Their app didn't create a folder--it installed files all over the place
If you'd like help with a script to clean up the one-click installer
just say the word and I'll be glad to help... If you'd email me a list
of files that the installer installed I'll send you a script to safely
clean them up...

I should be able to manage a script like that on my own. Will deleting
anything under usr/local affect the operation of the pre-installed ruby?
After I delete all the files will the pre-installed ruby automatically
work, or is there some link somewhere that I have to change?

Anyway, going forward, I'd suggest you use MacPorts to install and
maintain a "non-Apple" version of Ruby - the Ruby port maintainer is
great about keeping it up to date with the latest patch level and you
can choose between version with and without tk... There are even a few
gui tools to manage installed ports if you prefer that kind of thing...

Ok, thanks.
 
T

Tim Ferrell

7stud said:
So some developer assumed that /usr/local would be empty except for
their install? Heck why didn't they just say, "Our install is easy to
uninstall: delete your hard drive and it's gone. What could be
simpler?"

Well, that would definitely qualify as an easy uninstall ;-0 Of course
it wouldn't leave you with a usable system but that is another issue...
hehe
Their app didn't create a folder--it installed files all over the place

Actually, it may *have* created that /usr/local hierarchy unless you
have installed other stuff there yourself... Did you? If not then it
should be safe to just delete the stuff under /usr/local, although
writing a script to delete from the installer bom would be the best
choice, in my opinion...

Just FYI, you can extract a list of files from a .bom file with the
following command: lsbom -s said:
I should be able to manage a script like that on my own. Will deleting
anything under usr/local affect the operation of the pre-installed ruby?
After I delete all the files will the pre-installed ruby automatically
work, or is there some link somewhere that I have to change?

No - all of the bundled stuff is under /usr/bin, etc (/usr/local is
typically reserved for user-installed stuff) so it won't affect the
apple-supplied ruby...
Ok, thanks.

One thing to note: if you plan to upgrade to Leopard then it wouldn't
really be needed, as the latest versions of ruby (1.8.6-p111) and
rubygems (1.0.1) are included in the 10.5.2 update and, as long as you
install the developer tools, then Tk will work out of the box...

Cheers,
Tim
 
T

Tim Ferrell

Tim said:
Just FYI, you can extract a list of files from a .bom file with the
following command: lsbom -s <bom file>

Oh, one other thing that might not be immediately obvious... the bom
file would be located under /Library/Receipts/boms ... in this case I
think it would be prefixed with something like
"com.parasew.and.5uper.net.rubyosx" since that seems to be the package
bundle identifier...

Also, not to be overly pedantic, but after some looking I don't think
that the one-click installer for the Mac is in any way officially
endorsed by the ruby developers... If you look at
http://www.ruby-lang.org/en/downloads/ it is not listed and they suggest
either Locomotive as a quick way to set up Rails development or MacPorts
(or Fink, another package management option similar to MacPorts) for the
Mac...

Let me know if you need any help getting cleaned up or set up with
MacPorts...

Cheers,
Tim
 
7

7stud --

Tim said:
Actually, it may *have* created that /usr/local hierarchy unless you
have installed other stuff there yourself... Did you?
Yes.



Oh, one other thing that might not be immediately obvious... the bom
file would be located under /Library/Receipts/boms ... in this case I
think it would be prefixed with something like
"com.parasew.and.5uper.net.rubyosx" since that seems to be the package
bundle identifier...

I can't find the boms directory:

/Library/Receipts$ ls

2005-06XcodeExtras.pkg
AdditionalEssentials.pkg
AdditionalFonts.pkg
AdditionalSpeechVoices.pkg
AddressBook.pkg
AppleIntermediateCodec.pkg
AsianLanguagesSupport.pkg
Automator.pkg
BSD.pkg
BSDSDK.pkg
BaseSystem.pkg
BluetoothSDK.pkg
Booth.pkg
BrazilianPortuguese.pkg
BrotherPrinterDrivers.pkg
CPU_BBBGames.pkg
CPU_ComicLife.pkg
CPU_Help.pkg
CPU_OfficeTDUS.pkg
CPU_OmniOutliner.pkg
CPU_RegionalBoot.pkg
CanonPrinterDrivers.pkg
Comic Life.pkg
CoreAudioSDK.pkg
Danish.pkg
DevDocumentation.pkg
DevExamples.pkg
DevSDK.pkg
DeveloperTools.pkg
Dutch.pkg
ElectronicsForImagingPrinterDrivers.pkg
EpsonPrinterDrivers.pkg
Essentials.pkg
Finnish.pkg
FireWireSDK.pkg
French.pkg
FrontRow.pkg
FrontRowUpdate1.3.pkg
GarageBand.pkg
GarageBand_304.pkg
GarageBand_DemoSongs_Tiger.pkg
GarageBand_FactoryContent.pkg
GarageBand_Instruments_Tiger.pkg
GarageBand_Loops_Tiger.pkg
GarageBand_MIDI_Tiger.pkg
German.pkg
GimpPrintPrinterDrivers.pkg
HewlettPackardPrinterDrivers.pkg
Italian.pkg
Japanese.pkg
Java.pkg
Java14Documentation.pkg
Java14Tools.pkg
Keynote3.0.2.pkg
Korean.pkg
LexmarkPrinterDrivers.pkg
MacOSX10.3.9.pkg
MacOSX10.4.Universal.pkg
Mail.pkg
MediaFiles.pkg
MigrationAssistant.pkg
Norwegian.pkg
OmniOutliner 3.5 v134.3.pkg
OpenGLSDK.pkg
OxfordDictionaries.pkg
PIL-platlib-1.1.5-py2.4-macosx10.4.pkg
PIL-scripts-1.1.5-py2.4-macosx10.4.pkg
Pages2.0.2.pkg
PythonApplications-2.4.pkg
PythonDocumentation-2.4.pkg
PythonFramework-2.4.pkg
PythonProfileChanges-2.4.pkg
PythonSystemFixes-2.4.pkg
PythonUnixTools-2.4.pkg
QuickTime713.pkg
QuickTimeSDK.pkg
RicohPrinterDrivers.pkg
Ruby One-Click Installer for OSX Tiger.pkg
Russian.pkg
Safari.pkg
SimplifiedChinese.pkg
Spanish.pkg
Swedish.pkg
TraditionalChinese.pkg
WebKitSDK.pkg
X11SDK.pkg
X11User.pkg
XeroxPrinterDrivers.pkg
gcc3.3.pkg
gcc4.0.pkg
iCal.pkg
iChat.pkg
iDVD.pkg
iDVDThemes_Tiger.pkg
iDVD_603.pkg
iLifeSoundEffects_Loops.pkg
iMacFirmwareUpdate.pkg
iMovie.pkg
iMovieThemes_Tiger.pkg
iMovie_603.pkg
iPhoto.pkg
iPhotoContent.pkg
iPhoto_605.pkg
iTunes.pkg
iTunesX.pkg
iWeb_112.pkg
iWeb_App.pkg
iWeb_Temp_de.pkg
iWeb_Temp_en.pkg
iWeb_Temp_fr.pkg
iWeb_Temp_ja.pkg
iWeb_Temp_other.pkg
iWork Trial.pkg


I found this though:

/Library/Receipts/Ruby One-Click Installer for OSX Tiger.pkg/Contents$
ls -al

total 320
drwxrwxr-x 6 root admin 204 Jan 26 23:48 .
drwxrwxr-x 3 root admin 102 Jan 26 23:48 ..
-rwxrwxr-x 1 root admin 151947 Jul 8 2007 Archive.bom
-rw-rw-r-- 1 root admin 2211 Jan 26 23:48 Info.plist
-rw-rw-r-- 1 root admin 8 Jul 8 2007 PkgInfo
drwxrwxr-x 15 root admin 510 Feb 20 04:12 Resources

...but Archive.bom isn't a directory.
Also, not to be overly pedantic, but after some looking I don't think
that the one-click installer for the Mac is in any way officially
endorsed by the ruby developers... If you look at
http://www.ruby-lang.org/en/downloads/ it is not listed and they suggest
either Locomotive as a quick way to set up Rails development or MacPorts
(or Fink, another package management option similar to MacPorts) for the
Mac...

I sent an email to the contact listed on the main ruby website detailing
my problems, and they removed the link to the Mac one click
installer--which I think was justified.
 
7

7stud --

7stud said:
I can't find the boms directory:


I found this though:

/Library/Receipts/Ruby One-Click Installer for OSX Tiger.pkg/Contents$
ls -al

total 320
drwxrwxr-x 6 root admin 204 Jan 26 23:48 .
drwxrwxr-x 3 root admin 102 Jan 26 23:48 ..
-rwxrwxr-x 1 root admin 151947 Jul 8 2007 Archive.bom
-rw-rw-r-- 1 root admin 2211 Jan 26 23:48 Info.plist
-rw-rw-r-- 1 root admin 8 Jul 8 2007 PkgInfo
drwxrwxr-x 15 root admin 510 Feb 20 04:12 Resources

...but Archive.bom isn't a directory.

I found the .bom file here:

/Library/Receipts/Ruby One-Click Installer for OSX
Tiger.pkg/Contents/Resources$ ls

Archive.sizes
Description.plist
IFRequirement.strings
License.rtf
ReadMe.rtf
Ruby One-Click Installer for OSX Tiger.bom
Ruby One-Click Installer for OSX Tiger.info
Ruby One-Click Installer for OSX Tiger.post_install
Ruby One-Click Installer for OSX Tiger.sizes
Welcome.rtf
background.jpg
package_version
postinstall
 
T

Tim Ferrell

7stud said:
I found the .bom file here:

/Library/Receipts/Ruby One-Click Installer for OSX
Tiger.pkg/Contents/Resources$ ls

Archive.sizes
Description.plist
IFRequirement.strings
License.rtf
ReadMe.rtf
Ruby One-Click Installer for OSX Tiger.bom
Ruby One-Click Installer for OSX Tiger.info
Ruby One-Click Installer for OSX Tiger.post_install
Ruby One-Click Installer for OSX Tiger.sizes
Welcome.rtf
background.jpg
package_version
postinstall

Ok ... The boms directory I mentioned may be a Leopard thing... Now that
you found that file, you should be able to do:

lsbom -s "/Library/Receipts/Ruby One-Click Installer for OSX
Tiger.pkg/Contents/Resources/Ruby One-Click Installer for OSX Tiger.bom"
filelist.txt

to get a list of file to delete... and then read that into a shell
script or whatever to delete the files and clean up any empty
directories once that is done.

Glad to hear the ruby guys were responsive to your complaints. :)

Cheers,
Tim
 
M

Morton Goldberg

Ok ... The boms directory I mentioned may be a Leopard thing... Now
that
you found that file, you should be able to do:

lsbom -s "/Library/Receipts/Ruby One-Click Installer for OSX
Tiger.pkg/Contents/Resources/Ruby One-Click Installer for OSX
Tiger.bom"

to get a list of file to delete... and then read that into a shell
script or whatever to delete the files and clean up any empty
directories once that is done.

The following may be easier -- at least I think it is.

1. Open the installer package in the Receipts folder.
2. Cmd-I to get the bill-of-material window.
3. Click on the window title.
4. Cmd-A to select the whole file list
5. Cmd-C to copy it to the clipboard.

You can then paste the list into your favorite text editor and save it.

Regards, Morton
 
7

7stud --

In case anyone else would like to use it, the following is what I used
to uninstall all the files installed by the mac one click installer.
Look how easy it was!

The program produces output while running that identifies each file name
as either a dir or a file. If the file name is a dir, it is skipped. If
the file name is a file, it is deleted. For files that are deleted, the
dir containing the file is examined to determine if it is now empty. If
the dir is empty, it is deleted. Here is some sample output:

/users/me/2testing/dir2 is a dir
---Skipping to next file name.
/users/me/2testing/dir2/aaa.txt is a file
---Deleted file: /users/me/2testing/dir2/aaa.txt
examining dir: /users/me/2testing/dir2
---Dir isn't empty.
/users/me/2testing/dir2/test1.txt is a file
---Deleted file: /users/me/2testing/dir2/test1.txt
examining dir: /users/me/2testing/dir2
---Dir isn't empty.
/users/me/2testing/dir2/sub_dir is a dir
---Skipping to next file name.
/users/me/2testing/dir2/sub_dir/bbb.txt is a file
---Deleted file: /users/me/2testing/dir2/sub_dir/bbb.txt
examining dir: /users/me/2testing/dir2/sub_dir
---Dir isn't empty.
/users/me/2testing/dir2/sub_dir/test2.txt is a file
---Deleted file: /users/me/2testing/dir2/sub_dir/test2.txt
examining dir: /users/me/2testing/dir2/sub_dir
---Deleted dir: /users/me/2testing/dir2/sub_dir
examining dir: /users/me/2testing/dir2
---Deleted dir: /users/me/2testing/dir2


The program also writes every file and directory that it deletes to a
file named:

deleted_files_Mac_One_Click_Installer.txt

so that there is a permanent record of what the program did. The output
to the file looks like this:

Deleted Directories:
/users/me/2testing/dir2/sub_dir
/users/me/2testing/dir2

Deleted Files:
/users/me/2testing/dir2/aaa.txt
/users/me/2testing/dir2/test1.txt
/users/me/2testing/dir2/sub_dir/bbb.txt
/users/me/2testing/dir2/sub_dir/test2.txt


Here is the program (I also wrote some comments after the code):

=begin
If you go here:

/Library/Receipts/

and click on:

Ruby One-Click Installer for OSX Tiger.pkg

the installer will launch. If you then click on File>Show Files
in the Apple menubar, you will see a list of the files installed
by the installer. To copy all the file names, click anywhere in
the window and hit <apple>A and <apple>C. You can then paste the
file names into a .txt file by hitting <apple>P.

You can also get that list of files here:

/Library/Receipts/Ruby One-Click Installer for OSX
Tiger.pkg/Contents/Resources$

with this command:

/Library.../Resources$ lsbom -s Ruby\ One-Click\ Installer\ for\ OSX\
Tiger.bom
=end



def get_master_file_and_path_to_remove

puts
puts <<STR
To delete the files under the directory /usr/local, you will most
likely need 'root permissions'. Therefore, you need to run this
program using the command:

$ sudo ruby this_program_name.rb
password: <enter your password>

If you didn't run this program using that command, then exit
the program now. Would you like to exit now('y' or 'n'):
STR

answer = gets.strip
if ['y', 'Y', 'yes'].include?(answer)
puts
puts "Program terminated."
exit(1)
end

puts
puts <<STR
Enter the path to a file that contains the file names you
want to delete(if the path has spaces in it, escape the
spaces with a '\\'). You will be given the opportunity
to exit the program before any actual deleting takes place:
STR

#File containing all the file names to delete:
delete_list = gets.strip

puts
puts <<STR
Enter the path that should be removed from the front of
the filenames(or hit return for none):
STR

remove_path = gets.strip
if remove_path.length == 0
remove_path = nil
end

#Show examples of new file names:
samples = []
count = 0
fname = nil
IO.foreach(delete_list) do |line|
fname = extract_fname(line, remove_path) #extract_fname() defined
below

if fname
samples << fname
count += 1
break if count > 5
end
end

puts

#Confirm whether these are the file names that should be deleted:
puts <<STR
Do the following look like the names of the files you want to
delete(y or n)?\n
STR
puts samples

answer = gets.strip
puts
if !['y', 'Y', 'yes'].include?(answer)
puts
puts "Program terminated."
exit(1)
end

puts <<STR
Are you sure you want to delete all the files? If you answer yes,
then this program will scour your hard drive for all the file names
contained in the file you entered. The program will then delete
those files as well as any directories that become empty as a result
of deleting a file. This program will NOT delete the directory
/usr/local or any higher directories.

The names of all the files and directories that were deleted will
be written to a file called:

'deleted_files_Mac_One_Click_Installer.txt'.

Enter 'y'(for yes) if you want to begin deleting the files now.
Otherwise enter, 'n'(for no) if you want to exit the program:
STR

answer = gets.strip
puts
if !['y', 'Y', 'yes'].include?(answer):
puts
puts "Program Terminated"
exit(1)
end

return delete_list, remove_path
end


def extract_fname(line_from_file, path_to_remove=nil)

#remove any leading and trailing whitespace:
fname = line_from_file.strip

if fname.length == 0 #then blank line in file
return nil

elsif not path_to_remove
return fname

else #then chop the specified path off the start of fname
if fname == path_to_remove #
return nil
end

len = path_to_remove.length
if fname[0, len] == path_to_remove #then fname starts with the path
fname = fname[len..-1] #remove leading path from fname
return fname

else #fname doesn't start with the specified path
raise ArgumentError,
"Cannot remove path:\n\t%s from file name:\n\t%s" %
[path_to_remove, fname]
end
end
end


def delete_file(file_name)
#If the file name corresponds to a file, delete the file.
#If the file name is a dir, take no action.
#If the file name doesn't correspond to an existing file or dir,
#raise a RuntimeError.

if File.directory?(file_name)
printf("%s is a dir\n", file_name)
puts "---Skipping to next file name."
return false
elsif File.file?(file_name)
printf("%s is a file\n", file_name)
File.delete(file_name)
printf("---Deleted file: %s\n", file_name)
return true
else
raise RuntimeError, "No such file or directory - %s" % file_name
end
end


def delete_empty_dirs(curr_dir, stop_dir)
#Check whether the current directory that used to contain
#the deleted file is empty and therefore should be deleted.
#as well. If the current diretory is deleted, then recursively
#check the parent directories to see if they are now
#empty and need deleting.
#--stop_dir is the furthest up the file hierarchy
#that this method will delete empty dirs.

deleted_dirs = []
while curr_dir != stop_dir
printf("examining dir: %s\n", curr_dir)

files_in_dir = Dir.entries(curr_dir)
#Empty dirs on a mac contain the dirs ".", ".." and possibly a file
#called ".DS_Store". A .DS_Store file is created if you ever
#navigated to the dir using Finder. The .DS_Store file contains view
#options, icon position info, etc. Ruby will delete a dir if the dir
#contains only "." and "..", but ruby won't delete a dir if the dir
#contains the file .DS_Store. Hence the following:
empty_dir_on_mac = [".", "..", ".DS_Store"]
extra_files = files_in_dir - empty_dir_on_mac

if extra_files.length == 0 #then dir needs deleting
if files_in_dir.include?(".DS_Store")
full_path = File.join(curr_dir, ".DS_Store")
File.delete(full_path)
end

Dir.delete(curr_dir)
printf("---Deleted dir: %s\n", curr_dir)
deleted_dirs << curr_dir

else
printf("---Dir isn't empty.\n")
break #no need to check parent dirs
end

#Get parent dir for the next loop to examine:
curr_dir = File.dirname(curr_dir)
end

return deleted_dirs
end


def log_results(files_deleted, dirs_deleted)
File.open('deleted_files_Mac_One_Click_Installer.txt', 'w') do |file|
file.puts("Deleted Directories:")
file.puts(dirs_deleted)

file.puts

file.puts("Deleted Files:")
file.puts(files_deleted)
end
end





#------MAIN PROGRAM-----------

delete_list, path_to_remove = get_master_file_and_path_to_remove()

deleted_files = []
deleted_dirs = []

IO.foreach(delete_list) do |a_line|

#Extract a file name from the line:
fname = extract_fname(a_line, path_to_remove)
next if !fname

#If fname is the name of a file, delete it:
if delete_file(fname)
deleted_files << fname
else #then fname is a dir
next #A dir doesn't become empty unless you delete a file contained
#therein, so skip the code below which checks for empty dirs.
end


#Delete any directories that are now empty as the result
#of deleting a file:
top_dir = '/users/autie/2testing' #don't check directories above this
one
dir_name = File.dirname(fname)
deleted = delete_empty_dirs(dir_name, top_dir)
deleted_dirs.concat(deleted)

end

#Write the names of all the deleted files and dirs
#to a file:
log_results(deleted_files, deleted_dirs)


===============
**********************
===============

Comments on testing


For testing, I used this hierarchy:
/
--users
-----me
-------2testing
-----------dir2
---------------aaa.txt
---------------test1.txt
---------------sub_dir
-------------------test2.txt
-------------------bbb.txt

This was my list of files to delete:

/users/me/2testing/dir2
/users/me/2testing/dir2/aaa.txt
/users/me/2testing/dir2/test1.txt

/users/me/2testing/dir2/sub_dir
/users/me/2testing/dir2/sub_dir/bbb.txt
/users/me/2testing/dir2/sub_dir/test2.txt


During testing, I used the directory /users/me/2testing as the top
directory in the code (instead of /usr/local). After running the
program and entering the file name with the files to delete and '.' as
the path to remove, I was left with this hierarchy:

/
--me
----2testing


After getting that to work correctly, I changed the top directory in the
code to /usr/local, and then I ran the program for real. When prompted,
I entered a file name containing all the files that the mac one click
installer installed, and I entered '.' as the path to remove.

After the program finished deleting all the files, the pre-installed
ruby, which is version 1.8.2 for me, worked without me doing anything
else, and ruby tk started working again.
 
7

7stud --

Morton said:
The following may be easier -- at least I think it is.

1. Open the installer package in the Receipts folder.
2. Cmd-I to get the bill-of-material window.
3. Click on the window title.
4. Cmd-A to select the whole file list
5. Cmd-C to copy it to the clipboard.

You can then paste the list into your favorite text editor and save it.

Regards, Morton

Thanks. I used your tip to copy the file names to a file in the current
directory. You don't need to click on the window title, though--you can
click anywhere on the window and then hit <apple>A to select all the
file names.
 
T

Tim Ferrell

7stud said:
In case anyone else would like to use it, the following is what I used
to uninstall all the files installed by the mac one click installer.
Look how easy it was!

One small point I meant to bring up earlier - when I've written scripts
like this in the past, I always have the script *move* the files to a
temporary location rather than deleting them directly. That way I can
inspect everything and delete them by hand if everything checks out
ok...

Maybe that's overly paranoid but having a script delete something
important by mistake really sucks... :)

Anyway, glad you got everything sorted out!

Cheers,
Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top