#!/usr/bin/python # Copland Drive Mounter (decended from pyWinStab) version 0.4 # This program is distributed under the GPLv2. Python, and the libraries included with it # (and used in this program), are distributed under the PSF GPL-compatible license. """Enter a terminal in the appropriate directory and invoke the program with sudo or as root user. It will search your computer for System 7 (HFS) and Mac OS 8+ (HFS+) drives, and add them to your fstab file. IMPORTANT: This is alpha-quality software, and has had no testing apart from fake files on the author's machine. If it messes up your fstab file (which should NOT already have any Mac partitions entered in it), you can restore it through the backup made at /etc/fstab-backup Debugging Mode is available through the --debug flag.""" print "Copland Drive Mounter starting up... please be patient" from Tkinter import * import commands import sys import string import cStringIO import pwd import os d = 0 #initialise "debug" value if len(sys.argv) == 2: if sys.argv[1] == "--debug": d = True username = pwd.getpwuid(os.getuid())[0] if username != "root": commands.getoutput("gksudo -m \"The Copland drive mounter must run with higher privileges. Please enter your password to grant these.\" drivemounter-0.4.py") sys.exit() # // end if class AppProgress: def __init__(self): print "Ready to start. Please refer to GUI." self.root = Tk() self.root.title("Copland Filesystem Mounter") self.whatDoingLabel = Label(self.root, text="Ready to start.") self.actionButton = Button(self.root, text="Start", command=self.start) self.whatDoingLabel.pack(anchor=W) self.actionButton.pack(anchor=E) self.root.mainloop() def start(self): commands.getoutput("cp /etc/fstab /etc/fstab-backup") #duplicates fstab file self.whatDoingLabel.config(text="Checking for partitions...") self.actionButton.config(text="Cancel", command=sys.exit) output = commands.getoutput("fdisk -l") #asks system for details on all partitions outputLines = output.splitlines() macPartNum = 1 fstabAdditions = cStringIO.StringIO() if d: print fstabAdditions for line in outputLines: try: if line[0] != "/": continue #it doesn't have an entry on it if len(line) <= 11: continue #it's just a header if line[7] == "c": continue #it's the CD drive, which we REALLY don't want again in the fstab except IndexError: if d: print "IndexError - normal behaviour" #this is normal behaviour actually, and doesn't signify an error. continue entities = line.split(" ") if (line.find("HFS") == -1): continue #the search failed device = entities[0] if d: print device + " is either HFS or HFS+ - trying to determine now!" # stuff all the silly testing routine that was present in the previous # version - testing filesystem size, asking user etc... let's just # mount the thing with hfsplus, and if it fails, it's an HFS # volume (or damaged, in which case you're buggered anyway) hfsOutput = commands.getoutput("hpmount " + device + " -r") if (hfsOutput.find("Neither wrapper") != -1): #it is HFS fstabfs = "hfs" else: fstabfs = "hfsplus" fstabAdditions.write(device+"\t/media/Mac"+str(macPartNum)+"\t"+fstabfs+"\tdefaults\t0\t0\n") if d: print "Added device " + device + " to fstabAdditions" # The next line creates what's called a "mount point". # This is a directory - inside it you can access your # partition. commands.getoutput("mkdir /media/Mac" + str(macPartNum)) print "Added " + fstabfs + " partition at " + device + ". This is Macintosh partition number " + str(macPartNum) + ", and it is mounted at /media/Mac" + str(macPartNum) macPartNum = macPartNum + 1 # end loop self.whatDoingLabel.config(text="Saving changes to the fstab file...") fileObj = open("/etc/fstab", "a") fileObj.write(fstabAdditions.getvalue()) if d: print fstabAdditions.getvalue() fileObj.close() self.thanksBox = Toplevel(self.root) self.thanksBox.title("Task completed") commands.getoutput("mount -a") Label(self.thanksBox, text="You should now have access to your Macintosh partitions through /media/MacX, \nwhere X is a number. \n\nYour original fstab file has been backed up into /etc/fstab-backup. For best results, please reboot now.").pack(anchor=W) Button(self.thanksBox, text="OK", command=sys.exit).pack(anchor=E) # end constructor #end class AppProgress()