commit 7d3d84cdd25dc32432efc67ac82a5567d33ca794
Author: Dave Riches <dcr226(a)fedorapeople.org>
Date: Thu Jan 20 20:18:56 2011 +0000
made -q --quiet work. Added a couple of deps to README for now
README | 7 ++++
multiboot-media-creator.py | 68 +++++++++++++++++++++++++++++++++----------
2 files changed, 59 insertions(+), 16 deletions(-)
---
diff --git a/README b/README
index 98024eb..5ff7e50 100644
--- a/README
+++ b/README
@@ -9,3 +9,10 @@ It will take all of the .iso files within the working directory.
Usage:
The result should be a Multi-Boot.iso image which can then be used, as described above
+
+Requirements
+
+Python
+pyparted
+grub2
+**more coming soon**
diff --git a/multiboot-media-creator.py b/multiboot-media-creator.py
index 33afa93..c7b31de 100755
--- a/multiboot-media-creator.py
+++ b/multiboot-media-creator.py
@@ -35,6 +35,8 @@ parser.add_option("-j", "--justdoit", action="store_true", dest="justdoit", defa
help="Attempt to build without intervention - be careful")
parser.add_option("-r", "--rsync", action="store_true", dest="rsync", default=False,
help="Use rsync instead of shutil.copy2. This uses system calls, and carries and additional overhead")
+parser.add_option("-u", "--update", action="store_true", dest="update", default=False,
+ help="Update an existing device, adds the isos defined in --source to the device --destination")
(options, args) = parser.parse_args()
#print options.directory
@@ -52,31 +54,49 @@ else:
mytemp=tempfile.mkdtemp(suffix=".mmc")
dev=options.device
rawdev=dev[:-1]
+if options.verbose==True:
+ rsync_opts="-avH --progress"
+ grub2_opts=""
+else:
+ rsync_opts="-aH --progress"
+ grub2_opts=">/dev/null"
if dev==None:
sys.exit("Program requires a destination device")
-print path
-print dev
+if options.verbose==True:
+ print "Path to iso directory: %s" % path
+ print "Path to device: %s " % dev
def check_device():
+ if options.verbose==True:
+ print "Checking device to see if its already in use.."
devinfo=parted.getDevice(dev)
if devinfo.busy==True:
sys.exit("The device is busy or already mounted, please check and try again")
else:
- print "Device not busy, continuing"
+ if options.verbose==True:
+ print "Device not busy, continuing"
def mount_device(dev):
+ if options.verbose==True:
+ print "Mounting device: %s" % dev
os.system("mount %s %s" % (dev, mytemp))
def umount_device(dev):
+ if options.verbose==True:
+ print "Un-mounting device: %s" % dev
os.system("umount %s" % dev)
def grub_install():
+ if options.verbose==True:
+ print "Installing grub to %s" % dev
try:
- os.system("grub2-install --root-directory=%s %s --force" % (mytemp,rawdev))
+ os.system("grub2-install --root-directory=%s %s --force %s" % (mytemp,rawdev,grub2_opts))
except:
sys.exit("Unable to grub-install, check device")
+ if options.verbose==True:
+ print "Attempting to relabel partition"
try:
os.system("e2label %s Multi-Boot" % dev)
except:
@@ -85,24 +105,27 @@ def grub_install():
def getisos(isopath,isotype):
"""getisos returns a list of isos inside a specific path
based on a given type"""
+ if options.verbose==True:
+ print "Searching for %s isos" % isotype
isopath=os.path.join(isopath, "*.iso")
isos=[]
for i in glob.glob(isopath):
os.system("mount -o loop %s %s &>/dev/null" % (i, mytemp))
if os.path.isfile(os.path.join(mytemp+"/.discinfo")) == True:
info="dvd"
- print i+" is dvd"
else:
info="live"
- print i+" is live"
os.system("umount %s &>/dev/null" % i)
if info==isotype:
isos.append(i)
return isos
def makedirs(iso,filesys):
+ if os.path.exists(os.path.join(mytemp, "boot/grub2"))==True:
+ os.exit("It seems like there is already a filesystem on that device, possibly built by mmc previously. You might want to either delete this, or use the -u --update option")
BN=os.path.basename(iso.strip(".iso"))
- os.makedirs(os.path.join(mytemp, "boot/grub2"))
+ if options.update==False:
+ os.makedirs(os.path.join(mytemp, "boot/grub2"))
os.makedirs(os.path.join(mytemp, BN,"CHECKSUM"))
os.makedirs(os.path.join(mytemp, BN,"tmp"))
if filesys=="dvd":
@@ -132,7 +155,8 @@ def make_iso():
def build_filesystem():
try:
for i in getisos(path, "live"):
- print "Building filesystem for: %s" % i
+ if options.verbose==True:
+ print "Building filesystem for: %s" % i
BN=os.path.basename(i.strip(".iso"))
makedirs(i, "live")
tree_path=mount_iso(i)
@@ -142,7 +166,8 @@ def build_filesystem():
os.system("rsync -avH --progress %s %s" % (tree_path,os.path.join(mytemp, BN,"images/")))
umount_iso(i)
except:
- print "No live isos found"
+ if options.verbose==True:
+ print "No live isos found"
try:
for i in getisos(path, "dvd"):
print "Building filesystem for: %s" % i
@@ -155,14 +180,16 @@ def build_filesystem():
shutil.copy2(os.path.join(tree_path, "images/install.img"),os.path.join(mytemp, BN,"images/"))
shutil.copy2(i,os.path.join(mytemp, BN))
else:
- os.system("rsync -avH --progress %s %s" % (os.path.join(tree_path, "isolinux/vmlinuz"),os.path.join(mytemp, BN,"boot/")))
- os.system("rsync -avH --progress %s %s" % (os.path.join(tree_path, "isolinux/initrd.img"),os.path.join(mytemp, BN,"boot/")))
- os.system("rsync -avH --progress %s %s" % (os.path.join(tree_path, "isolinux/initrd.img"),os.path.join(mytemp, BN,"boot/")))
- os.system("rsync -avH --progress %s %s" % (i,os.path.join(mytemp, BN)))
+ os.system("rsync %s %s %s" % (rsync_opts, os.path.join(tree_path, "isolinux/vmlinuz"),os.path.join(mytemp, BN,"boot/")))
+ os.system("rsync %s %s %s" % (rsync_opts, os.path.join(tree_path, "isolinux/initrd.img"),os.path.join(mytemp, BN,"boot/")))
+ os.system("rsync %s %s %s" % (rsync_opts, os.path.join(tree_path, "isolinux/initrd.img"),os.path.join(mytemp, BN,"boot/")))
+ os.system("rsync %s %s %s" % (rsync_opts, i,os.path.join(mytemp, BN)))
umount_iso(i)
except:
- print "No dvd isos found"
- print "Done!"
+ if options.verbose==True:
+ print "No dvd isos found"
+ if options.verbose==True:
+ print "Done!"
def create_grub(gtimeout=10):
grub=open(os.path.join(mytemp, "boot/grub2/grub.cfg"), "w")
@@ -183,11 +210,20 @@ def create_grub(gtimeout=10):
grub.close()
def doit(device):
+ check_device()
mount_device(device)
build_filesystem()
create_grub()
grub_install()
- umount_device(dev)
+ umount_device(device)
+ removetemps()
+
+def update(device):
+ check_device()
+ mount_device(device)
+ build_filesystem(update)
+ create_grub()
+ umount_device(device)
removetemps()
if options.justdoit==True: