2efedc3303f1c494f1a8ed1038a95626560310c5
[grml2usb.git] / grml2usb.py
1 #!/usr/bin/env python
2 # Filename:      grml2usb
3 # Purpose:       install grml-system to usb-device
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 prog_version = "0.0.1"
10
11 import os, sys
12 from optparse import OptionParser
13
14 # cmdline parsing {{{
15 usage = "usage: %prog [options] arg1 arg2"
16 parser = OptionParser(usage=usage)
17
18 parser.add_option("--bootoptions", dest="bootoptions", action="store", type="string",
19                   help="use specified bootoptions as defaut")
20 parser.add_option("--dry-run", dest="dryrun", action="store_true",
21                   help="do not actually execute any commands")
22 parser.add_option("--fat16", dest="fat16", action="store_true",
23                   help="format specified partition with FAT16")
24 parser.add_option("--force", dest="force", action="store_true",
25                   help="force any actions requiring manual interaction")
26 parser.add_option("--grub", dest="grub", action="store_true",
27                   help="install grub bootloader instead of syslinux")
28 parser.add_option("--initrd", dest="initrd", action="store", type="string",
29                   help="install specified initrd instead of the default")
30 parser.add_option("--kernel", dest="kernel", action="store", type="string",
31                   help="install specified kernel instead of the default")
32 parser.add_option("--mbr", dest="mbr", action="store_true",
33                   help="install master boot record (MBR) on the device")
34 parser.add_option("--squashfs", dest="squashfs", action="store", type="string",
35                   help="install specified squashfs file instead of the default")
36 parser.add_option("--verbose", dest="verbose", action="store_true",
37                   help="enable verbose mode")
38 parser.add_option("-v", "--version", dest="version", action="store_true",
39                   help="display version and exit")
40
41 (options, args) = parser.parse_args()
42 # }}}
43
44 # FIXME: implement argument handling
45 def execute(command):
46     """Wrapper for executing a command. Either really executes
47     the command (default) or when using --dry-run commandline option
48     just displays what would be executed."""
49     if options.dryrun:
50         print "would execute %s now" % command
51     else:
52         print "executing %s" % command
53
54 def install_syslinux(device):
55     """Install syslinux on specified device."""
56     print("syslinux %s") % device
57
58 def install_grub(device):
59     """Install grub on specified device."""
60     print("grub-install %s") % device
61
62 def install_bootloader(device):
63     """Install bootloader on specified device."""
64     if options.grub:
65         install_grub(device)
66     else:
67         install_syslinux(device)
68
69 def check_uid_root():
70     """Check for root permissions"""
71     if not os.geteuid()==0:
72         sys.exit("Error: please run this script with uid 0 (root).")
73
74 def main():
75     if options.version:
76         print("%s %s")% (os.path.basename(sys.argv[0]), prog_version)
77         sys.exit(0)
78
79     if len(args) < 2:
80         parser.error("invalid usage")
81
82     # check_uid_root()
83
84     device = args[len(args) - 1]
85     isos = args[0:len(args) - 1]
86
87     # FIXME: check for valid blockdevice
88     if device is not None:
89         install_bootloader(device)
90
91     for iso in isos:
92         print("iso = %s") % iso
93
94 if __name__ == "__main__":
95     main()
96
97 ## END OF FILE #################################################################
98 # vim:foldmethod=marker expandtab ai ft=python