1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#!/usr/bin/env python
#
# live_iso.py
#
# (c) Copyright 2009 - 2010 Michael Towers (larch42 at googlemail dot com)
#
# This file is part of the larch project.
#
# larch is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# larch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with larch; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
#----------------------------------------------------------------------------
# 2010.07.12
# This is a command line script to prepare an 'iso' file from an
# already larchified Arch Linux installation. Alternatively, another
# larch medium can be used as source (with the '-S' option).
# All needed parameters are passed as options.
import os
from config import *
from backend import *
from media_common import *
def build_iso(options):
"""Create a bootable iso from the source larch image. If a chroot
build is used (default unless -S is specified) the resulting iso file
will be relative to the larch build area (CHROOT_DIR_BUILD) in the
chroot directory, otherwise as specified to the -o option.
"""
medium = Medium(options)
ipath = medium.chrootpath
build = medium.build
# Write bootloader configuration file
bootconfig(build, options.syslinux)
if not os.path.isfile(medium.medium_dir + '/larch/larchboot'):
add_larchboot(build)
# Need to adjust paths to cater for chroot!
source0 = medium.chroot_medium_dir()
isopath0 = medium.iso_path()
# Select bootloader
if options.syslinux:
# Get fresh isolinux.bin
runcmd('cp %s/boot/isolinux/isolinux.bin0 %s/boot/isolinux/isolinux.bin'
% (build, build))
parms = '-b boot/isolinux/isolinux.bin -c boot/isolinux/isolinux.boot'
# Select bootloader
else:
parms = '-b boot/grub/stage2_eltorito'
# Actually the volume label can be 32 bytes, but 16 is compatible
# with ext2 (though a little longer than vfat)
label = check_label(options.label, 16)
# Build iso
if not chroot(ipath, ('mkisofs -R -l %s -no-emul-boot -boot-load-size 4'
' -boot-info-table -input-charset=UTF-8'
' -V "%s"'
' -o "%s"'
' -x "%s/boot"'
' -x "%s/larch/save"'
' "%s" "%s"') % (parms, label, isopath0,
source0, source0, source0, BUILD0),
filter=mkisofs_filter_gen()):
errout(_("iso build failed"))
# Process iso so that it can be 'dd'ed to a USB-stick
if options.syslinux and not chroot(ipath, ('isohybrid %s' % isopath0)):
errout(_("Couldn't perform 'isohybrid' operation on larch 'iso'"
" (Not Critical!)"), 0)
medium.unmount()
runcmd('rm -rf %s' % build)
comment(" *** %s ***" % (_("%s was successfully created")
% (options.isofile)))
if __name__ == "__main__":
start_translator()
from optparse import OptionParser, OptionGroup
parser = OptionParser(usage=_("usage: %prog [options]"))
parser.add_option("-p", "--profile", action="store", type="string",
default="", dest="profile",
help=_("Profile: 'user:profile-name' or path to profile directory"
" (conflicts with -S)"))
parser.add_option("-S", "--source", action="store", type="string",
default="", dest="source",
help=_("Source: path to larch medium image (conflicts with -p)."
" It can also be a device ('/dev/...') or an 'iso' file."))
parser.add_option("-i", "--installation-dir", action="store", type="string",
default="", dest="idir",
help=_("Path to larchified directory (default %s)") % INSTALLATION)
parser.add_option("-s", "--slave", action="store_true", dest="slave",
default=False, help=_("Run as a slave from a controlling program"
" (e.g. from a gui)"))
parser.add_option("-q", "--quiet", action="store_true", dest="quiet",
default=False, help=_("Suppress output messages, except errors"
" (no effect if -s specified)"))
parser.add_option("-f", "--force", action="store_true", dest="force",
default=False, help=_("Don't ask for confirmation"))
parser.add_option("-b", "--isolinux", action="store_true", dest="syslinux",
default=False, help=_("Use the isolinux bootloader"
" (the default is GRUB)"))
parser.add_option("-l", "--label", action="store", type="string",
default=LABEL, dest="label",
help=_("Volume label for iso (default '%s')") % LABEL)
parser.add_option("-o", "--isofile", action="store", type="string",
default=ISOFILE, dest="isofile",
help=_("Specify the output file (default '%s'). It will be"
" generated to the current directory.") % ISOFILE)
parser.add_option("-D", "--setdir", action="store", type="string",
dest='setdir', default='',
help=_("Set current directory,"
" so that the 'iso' can be placed there"))
parser.add_option("-C", "--chroot", action="store_true",
dest="chroot", default=False,
help=_("Use chroot for build (default when -S not specified)"))
parser.add_option("-c", "--nochroot", action="store_true",
dest="nochroot", default=False,
help=_("Don't use chroot for build (default when -S specified)"))
parser.add_option('-T', '--testmedium', action='store_true',
dest='testmedium', default=False,
help=_("Test source medium only (used by gui)"))
(options, args) = parser.parse_args()
if os.getuid() != 0:
print _("This application must be run as root")
sys.exit(1)
init('live_iso', options)
build_iso(options)
|