blob: 43801a18aa06c42307fc82dd09b31071c2d862b7 [file] [log] [blame]
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +08001#!/usr/bin/python -Bu
2#
3# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Factory toolkit installer.
8
9The factory toolkit is a self-extracting shellball containing factory test
10related files and this installer. This installer is invoked when the toolkit
11is deployed and is responsible for installing files.
12"""
13
14
15import argparse
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +080016from contextlib import contextmanager
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +080017import os
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +080018import sys
Jon Salz4f3ade52014-02-20 17:55:09 +080019import tempfile
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +080020
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +080021import factory_common # pylint: disable=W0611
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +080022from cros.factory.test import factory
Vic Yang196d5242014-08-05 13:51:35 +080023from cros.factory.test import utils
Jon Salz25590302014-07-11 16:07:20 +080024from cros.factory.tools import install_symlinks
Rong Chang6d65fad2014-08-22 16:00:12 +080025from cros.factory.utils import file_utils
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +080026from cros.factory.utils.process_utils import Spawn
Hung-Te Lincdc2a042014-08-27 13:05:16 +080027from cros.factory.utils.sys_utils import MountPartition
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +080028
29
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +080030INSTALLER_PATH = 'usr/local/factory/py/toolkit/installer.py'
Rong Chang6d65fad2014-08-22 16:00:12 +080031MAKESELF_SHELL = '/bin/sh'
32TOOLKIT_NAME = 'install_factory_toolkit.run'
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +080033
Jon Salz4f3ade52014-02-20 17:55:09 +080034# Short and sweet help header for the executable generated by makeself.
35HELP_HEADER = """
36Installs the factory toolkit, transforming a test image into a factory test
37image. You can:
38
39- Install the factory toolkit on a CrOS device that is running a test
40 image. To do this, copy install_factory_toolkit.run to the device and
41 run it. The factory tests will then come up on the next boot.
42
43 rsync -a install_factory_toolkit.run crosdevice:/tmp
44 ssh crosdevice '/tmp/install_factory_toolkit.run && sync && reboot'
45
46- Modify a test image, turning it into a factory test image. When you
47 use the image on a device, the factory tests will come up.
48
49 install_factory_toolkit.run chromiumos_test_image.bin
50"""
51
52HELP_HEADER_ADVANCED = """
53- (advanced) Modify a mounted stateful partition, turning it into a factory
54 test image. This is equivalent to the previous command:
55
56 mount_partition -rw chromiumos_test_image.bin 1 /mnt/stateful
57 install_factory_toolkit.run /mnt/stateful
58 umount /mnt/stateful
59
60- (advanced) Unpack the factory toolkit, modify a file, and then repack it.
61
62 # Unpack but don't actually install
63 install_factory_toolkit.run --target /tmp/toolkit --noexec
64 # Edit some files in /tmp/toolkit
65 emacs /tmp/toolkit/whatever
66 # Repack
67 install_factory_toolkit.run -- --repack /tmp/toolkit \\
68 --pack-into /path/to/new/install_factory_toolkit.run
69"""
70
71# The makeself-generated header comes next. This is a little confusing,
72# so explain.
73HELP_HEADER_MAKESELF = """
74For complete usage information and advanced operations, run
75"install_factory_toolkit.run -- --help" (note the extra "--").
76
77Following is the help message from makeself, which was used to create
78this self-extracting archive.
79
80-----
81"""
82
Vic Yang196d5242014-08-05 13:51:35 +080083# The method to determine whether running on Chrome OS device or not.
84# Override this for unit testing.
85_in_cros_device = utils.in_cros_device
86
Vic Yangdb1e20e2014-10-05 12:10:33 +080087SERVER_FILE_MASK = [
88 # Exclude Umpire server but keep Umpire client
89 '--include', 'py/umpire/__init__.*',
90 '--include', 'py/umpire/common.*',
91 '--include', 'py/umpire/client',
92 '--include', 'py/umpire/client/**',
93 '--exclude', 'py/umpire/**',
94
95 # Lumberjack is only used on Umpire server
96 '--exclude', 'py/lumberjack'
97]
98
Jon Salz4f3ade52014-02-20 17:55:09 +080099
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800100class FactoryToolkitInstaller():
101 """Factory toolkit installer.
102
103 Args:
104 src: Source path containing usr/ and var/.
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800105 dest: Installation destination path. Set this to the mount point of the
106 stateful partition if patching a test image.
107 no_enable: True to not install the tag file.
108 system_root: The path to the root of the file system. This must be left
109 as its default value except for unit testing.
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800110 """
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800111
Jon Salzb7e44262014-05-07 15:53:37 +0800112 # Whether to sudo when rsyncing; set to False for testing.
113 _sudo = True
114
Peter Ammon948b7172014-07-15 12:43:06 -0700115 def __init__(self, src, dest, no_enable, enable_presenter,
Vic Yang7039f422014-07-07 15:38:13 -0700116 enable_device, system_root='/'):
Jon Salz4f3ade52014-02-20 17:55:09 +0800117 self._src = src
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800118 self._system_root = system_root
119 if dest == self._system_root:
120 self._usr_local_dest = os.path.join(dest, 'usr', 'local')
121 self._var_dest = os.path.join(dest, 'var')
Jon Salz4f3ade52014-02-20 17:55:09 +0800122
123 # Make sure we're on a CrOS device.
Vic Yang196d5242014-08-05 13:51:35 +0800124 if not _in_cros_device():
Jon Salz4f3ade52014-02-20 17:55:09 +0800125 sys.stderr.write(
Vic Yang196d5242014-08-05 13:51:35 +0800126 "ERROR: You're not on a CrOS device (for more details, please\n"
127 "check utils.py:in_cros_device), so you must specify a test\n"
128 "image or a mounted stateful partition on which to install the\n"
129 "factory toolkit. Please run\n"
Jon Salz4f3ade52014-02-20 17:55:09 +0800130 "\n"
131 " install_factory_toolkit.run -- --help\n"
132 "\n"
133 "for help.\n")
134 sys.exit(1)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800135 if os.getuid() != 0:
Jon Salz4f3ade52014-02-20 17:55:09 +0800136 raise Exception('You must be root to install the factory toolkit on a '
137 'CrOS device.')
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800138 else:
139 self._usr_local_dest = os.path.join(dest, 'dev_image')
140 self._var_dest = os.path.join(dest, 'var_overlay')
141 if (not os.path.exists(self._usr_local_dest) or
142 not os.path.exists(self._var_dest)):
143 raise Exception(
144 'The destination path %s is not a stateful partition!' % dest)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800145
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800146 self._dest = dest
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800147 self._usr_local_src = os.path.join(src, 'usr', 'local')
148 self._var_src = os.path.join(src, 'var')
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800149 self._no_enable = no_enable
Vic (Chun-Ju) Yang7cc3e672014-01-20 14:06:39 +0800150 self._tag_file = os.path.join(self._usr_local_dest, 'factory', 'enabled')
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800151
Peter Ammon948b7172014-07-15 12:43:06 -0700152 self._enable_presenter = enable_presenter
153 self._presenter_tag_file = os.path.join(self._usr_local_dest, 'factory',
154 'init', 'run_goofy_presenter')
Vic Yang7039f422014-07-07 15:38:13 -0700155
156 self._enable_device = enable_device
Ricky Liangd7716912014-07-10 11:52:24 +0800157 self._device_tag_file = os.path.join(self._usr_local_dest, 'factory',
158 'init', 'run_goofy_device')
Vic Yang7039f422014-07-07 15:38:13 -0700159
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800160 if (not os.path.exists(self._usr_local_src) or
161 not os.path.exists(self._var_src)):
162 raise Exception(
163 'This installer must be run from within the factory toolkit!')
164
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800165 def WarningMessage(self, target_test_image=None):
Jon Salz4f3ade52014-02-20 17:55:09 +0800166 with open(os.path.join(self._src, 'VERSION')) as f:
167 ret = f.read()
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800168 if target_test_image:
Jon Salz4f3ade52014-02-20 17:55:09 +0800169 ret += (
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800170 '\n'
171 '\n'
Jon Salz4f3ade52014-02-20 17:55:09 +0800172 '*** You are about to patch the factory toolkit into:\n'
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800173 '*** %s\n'
174 '***' % target_test_image)
175 else:
Jon Salz4f3ade52014-02-20 17:55:09 +0800176 ret += (
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800177 '\n'
178 '\n'
Jon Salz4f3ade52014-02-20 17:55:09 +0800179 '*** You are about to install the factory toolkit to:\n'
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800180 '*** %s\n'
181 '***' % self._dest)
182 if self._dest == self._system_root:
Vic (Chun-Ju) Yang7cc3e672014-01-20 14:06:39 +0800183 if self._no_enable:
184 ret += ('\n'
185 '*** Factory tests will be disabled after this process is done, but\n'
Jon Salz4f3ade52014-02-20 17:55:09 +0800186 '*** you can enable them by creating the factory enabled tag:\n'
Vic (Chun-Ju) Yang7cc3e672014-01-20 14:06:39 +0800187 '*** %s\n'
188 '***' % self._tag_file)
189 else:
190 ret += ('\n'
191 '*** After this process is done, your device will start factory\n'
192 '*** tests on the next reboot.\n'
193 '***\n'
Jon Salz4f3ade52014-02-20 17:55:09 +0800194 '*** Factory tests can be disabled by deleting the factory enabled\n'
195 '*** tag:\n'
Vic (Chun-Ju) Yang7cc3e672014-01-20 14:06:39 +0800196 '*** %s\n'
197 '***' % self._tag_file)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800198 return ret
199
Vic Yang7039f422014-07-07 15:38:13 -0700200 def _SetTagFile(self, name, path, enabled):
201 """Install or remove a tag file."""
202 if enabled:
203 print '*** Installing %s enabled tag...' % name
204 Spawn(['touch', path], sudo=True, log=True, check_call=True)
Ricky Liang8c88a122014-07-11 21:21:22 +0800205 Spawn(['chmod', 'go+r', path], sudo=True, log=True, check_call=True)
Vic Yang7039f422014-07-07 15:38:13 -0700206 else:
207 print '*** Removing %s enabled tag...' % name
208 Spawn(['rm', '-f', path], sudo=True, log=True, check_call=True)
209
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800210 def Install(self):
211 print '*** Installing factory toolkit...'
Jon Salzb7e44262014-05-07 15:53:37 +0800212 for src, dest in ((self._usr_local_src, self._usr_local_dest),
213 (self._var_src, self._var_dest)):
214 # Change the source directory to root, and add group/world read
215 # permissions. This is necessary because when the toolkit was
216 # unpacked, the user may not have been root so the permessions
217 # may be hosed. This is skipped for testing.
Peter Ammon5ac58422014-06-09 14:45:50 -0700218 # --force is necessary to allow goofy directory from prior
219 # toolkit installations to be overwritten by the goofy symlink.
Ricky Liang5e95be22014-07-09 12:52:07 +0800220 try:
221 if self._sudo:
222 Spawn(['chown', '-R', 'root', src],
223 sudo=True, log=True, check_call=True)
224 Spawn(['chmod', '-R', 'go+rX', src],
225 sudo=True, log=True, check_call=True)
226 print '*** %s -> %s' % (src, dest)
Vic Yangdb1e20e2014-10-05 12:10:33 +0800227 Spawn(['rsync', '-a', '--force', ] + SERVER_FILE_MASK +
228 [src + '/', dest], sudo=self._sudo, log=True,
229 check_output=True, cwd=src)
Ricky Liang5e95be22014-07-09 12:52:07 +0800230 finally:
231 # Need to change the source directory back to the original user, or the
232 # script in makeself will fail to remove the temporary source directory.
233 if self._sudo:
234 myuser = os.environ.get('USER')
235 Spawn(['chown', '-R', myuser, src],
236 sudo=True, log=True, check_call=True)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800237
Jon Salz25590302014-07-11 16:07:20 +0800238 print '*** Installing symlinks...'
239 install_symlinks.InstallSymlinks(
240 '../factory/bin',
241 os.path.join(self._usr_local_dest, 'bin'),
242 install_symlinks.MODE_FULL,
243 sudo=self._sudo)
244
245 print '*** Removing factory-mini...'
246 Spawn(['rm', '-rf', os.path.join(self._usr_local_dest, 'factory-mini')],
247 sudo=self._sudo, log=True, check_call=True)
248
Vic Yang7039f422014-07-07 15:38:13 -0700249 self._SetTagFile('factory', self._tag_file, not self._no_enable)
Peter Ammon948b7172014-07-15 12:43:06 -0700250 self._SetTagFile('presenter', self._presenter_tag_file,
251 self._enable_presenter)
Vic Yang7039f422014-07-07 15:38:13 -0700252 self._SetTagFile('device', self._device_tag_file, self._enable_device)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800253
254 print '*** Installation completed.'
255
256
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800257@contextmanager
258def DummyContext(arg):
259 """A context manager that simply yields its argument."""
260 yield arg
261
262
Vic (Chun-Ju) Yang98b4fbc2014-02-18 19:32:32 +0800263def PrintBuildInfo(src_root):
264 """Print build information."""
265 info_file = os.path.join(src_root, 'REPO_STATUS')
266 if not os.path.exists(info_file):
267 raise OSError('Build info file not found!')
268 with open(info_file, 'r') as f:
269 print f.read()
270
271
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +0800272def PackFactoryToolkit(src_root, output_path):
273 """Packs the files containing this script into a factory toolkit."""
274 with open(os.path.join(src_root, 'VERSION'), 'r') as f:
275 version = f.read().strip()
Jon Salz4f3ade52014-02-20 17:55:09 +0800276 with tempfile.NamedTemporaryFile() as help_header:
277 help_header.write(version + "\n" + HELP_HEADER + HELP_HEADER_MAKESELF)
278 help_header.flush()
279 Spawn([os.path.join(src_root, 'makeself.sh'), '--bzip2', '--nox11',
280 '--help-header', help_header.name,
281 src_root, output_path, version, INSTALLER_PATH, '--in-exe'],
282 check_call=True, log=True)
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +0800283 print ('\n'
284 ' Factory toolkit generated at %s.\n'
285 '\n'
286 ' To install factory toolkit on a live device running a test image,\n'
287 ' copy this to the device and execute it as root.\n'
288 '\n'
289 ' Alternatively, the factory toolkit can be used to patch a test\n'
290 ' image. For more information, run:\n'
Jon Salz4f3ade52014-02-20 17:55:09 +0800291 ' %s --help\n'
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +0800292 '\n' % (output_path, output_path))
293
294
Rong Chang6d65fad2014-08-22 16:00:12 +0800295def InitUmpire(exe_path, src_root, target_board):
296 """Inits Umpire server environment."""
297 if exe_path is None:
298 parent_cmdline = open('/proc/%s/cmdline' % os.getppid(),
299 'r').read().rstrip('\0').split('\0')
300
301 if parent_cmdline > 1 and parent_cmdline[0] == MAKESELF_SHELL:
302 # Get parent script name from parent process.
303 exe_path = parent_cmdline[1]
304 else:
305 # Set to default.
306 exe_path = TOOLKIT_NAME
307
308 if not exe_path.startswith('/'):
309 exe_path = os.path.join(os.environ.get('OLDPWD'), exe_path)
310
311 with file_utils.TempDirectory() as nano_bundle:
312 bundle_toolkit_dir = os.path.join(nano_bundle, 'factory_toolkit')
313 os.mkdir(bundle_toolkit_dir)
314 os.symlink(exe_path, os.path.join(bundle_toolkit_dir,
315 os.path.basename(exe_path)))
316 umpire_bin = os.path.join(src_root, 'usr', 'local', 'factory', 'bin',
317 'umpire')
318 Spawn([umpire_bin, 'init', '--board', target_board, nano_bundle],
319 check_call=True, log=True)
320 print ('\n'
321 ' Umpire initialized successfully. Upstart service is running:\n'
322 ' umpire BOARD=%(board)s.\n'
323 ' For more information, please check umpire command line:\n'
324 '\n'
325 ' umpire-%(board)s --help (if your id is in umpire group)\n'
326 ' or sudo umpire-%(board)s --help\n'
327 '\n' % {'board': target_board})
328
329
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800330def main():
Jon Salz4f3ade52014-02-20 17:55:09 +0800331 import logging
332 logging.basicConfig(level=logging.INFO)
333
334 # In order to determine which usage message to show, first determine
335 # whether we're in the self-extracting archive. Do this first
336 # because we need it to even parse the arguments.
337 if '--in-exe' in sys.argv:
338 sys.argv = [x for x in sys.argv if x != '--in-exe']
339 in_archive = True
340 else:
341 in_archive = False
342
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800343 parser = argparse.ArgumentParser(
Jon Salz4f3ade52014-02-20 17:55:09 +0800344 description=HELP_HEADER + HELP_HEADER_ADVANCED,
345 usage=('install_factory_toolkit.run -- [options]' if in_archive
346 else None),
347 formatter_class=argparse.RawDescriptionHelpFormatter)
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800348 parser.add_argument('dest', nargs='?', default='/',
349 help='A test image or the mount point of the stateful partition. '
350 "If omitted, install to live system, i.e. '/'.")
Vic (Chun-Ju) Yang7cc3e672014-01-20 14:06:39 +0800351 parser.add_argument('--no-enable', '-n', action='store_true',
352 help="Don't enable factory tests after installing")
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800353 parser.add_argument('--yes', '-y', action='store_true',
354 help="Don't ask for confirmation")
Vic (Chun-Ju) Yang98b4fbc2014-02-18 19:32:32 +0800355 parser.add_argument('--build-info', action='store_true',
356 help="Print build information and exit")
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +0800357 parser.add_argument('--pack-into', metavar='NEW_TOOLKIT',
358 help="Pack the files into a new factory toolkit")
359 parser.add_argument('--repack', metavar='UNPACKED_TOOLKIT',
360 help="Repack from previously unpacked toolkit")
Vic Yang7039f422014-07-07 15:38:13 -0700361
Peter Ammon948b7172014-07-15 12:43:06 -0700362 parser.add_argument('--enable-presenter', dest='enable_presenter',
Vic Yang7039f422014-07-07 15:38:13 -0700363 action='store_true',
Peter Ammon948b7172014-07-15 12:43:06 -0700364 help="Run goofy in presenter mode on startup")
365 parser.add_argument('--no-enable-presenter', dest='enable_presenter',
Vic Yang7039f422014-07-07 15:38:13 -0700366 action='store_false', help=argparse.SUPPRESS)
Vic Yang423c2722014-09-24 16:05:06 +0800367 parser.set_defaults(enable_presenter=True)
Vic Yang7039f422014-07-07 15:38:13 -0700368
369 parser.add_argument('--enable-device', dest='enable_device',
370 action='store_true',
Peter Ammon948b7172014-07-15 12:43:06 -0700371 help="Run goofy in device mode on startup")
Vic Yang7039f422014-07-07 15:38:13 -0700372 parser.add_argument('--no-enable-device', dest='enable_device',
373 action='store_false', help=argparse.SUPPRESS)
Vic Yang423c2722014-09-24 16:05:06 +0800374 parser.set_defaults(enable_device=True)
375
Rong Chang6d65fad2014-08-22 16:00:12 +0800376 parser.add_argument('--init-umpire-board', dest='umpire_board',
377 nargs='?', default=None,
378 help="Locally install Umpire server for specific board")
379 parser.add_argument('--exe-path', dest='exe_path',
380 nargs='?', default=None,
381 help="Current self-extracting archive pathname")
Vic Yang7039f422014-07-07 15:38:13 -0700382
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800383 args = parser.parse_args()
384
Vic (Chun-Ju) Yang98b4fbc2014-02-18 19:32:32 +0800385 src_root = factory.FACTORY_PATH
386 for _ in xrange(3):
387 src_root = os.path.dirname(src_root)
388
Rong Chang6d65fad2014-08-22 16:00:12 +0800389 # --init-umpire-board creates a nano bundle, then calls umpire command
390 # line utility to install the server code and upstart configurations.
391 if args.umpire_board:
392 InitUmpire(args.exe_path, src_root, args.umpire_board)
393 return
394
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +0800395 # --pack-into may be called directly so this must be done before changing
396 # working directory to OLDPWD.
397 if args.pack_into and args.repack is None:
398 PackFactoryToolkit(src_root, args.pack_into)
Vic (Chun-Ju) Yang98b4fbc2014-02-18 19:32:32 +0800399 return
400
Jon Salz4f3ade52014-02-20 17:55:09 +0800401 if not in_archive:
402 # If you're not in the self-extracting archive, you're not allowed to
403 # do anything except the above --pack-into call.
404 parser.error('Not running from install_factory_toolkit.run; '
405 'only --pack-into (without --repack) is allowed')
406
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800407 # Change to original working directory in case the user specifies
408 # a relative path.
409 # TODO: Use USER_PWD instead when makeself is upgraded
410 os.chdir(os.environ['OLDPWD'])
411
Vic (Chun-Ju) Yangb7388f72014-02-19 15:22:58 +0800412 if args.repack:
413 if args.pack_into is None:
414 parser.error('Must specify --pack-into when using --repack.')
415 Spawn([os.path.join(args.repack, INSTALLER_PATH),
416 '--pack-into', args.pack_into], check_call=True, log=True)
417 return
418
419 if args.build_info:
420 PrintBuildInfo(src_root)
421 return
422
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800423 if not os.path.exists(args.dest):
424 parser.error('Destination %s does not exist!' % args.dest)
425
426 patch_test_image = os.path.isfile(args.dest)
427
428 with (MountPartition(args.dest, 1, rw=True) if patch_test_image
429 else DummyContext(args.dest)) as dest:
Peter Ammon948b7172014-07-15 12:43:06 -0700430 installer = FactoryToolkitInstaller(src_root, dest, args.no_enable,
431 args.enable_presenter, args.enable_device)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800432
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800433 print installer.WarningMessage(args.dest if patch_test_image else None)
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800434
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800435 if not args.yes:
436 answer = raw_input('*** Continue? [y/N] ')
437 if not answer or answer[0] not in 'yY':
438 sys.exit('Aborting.')
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800439
Vic (Chun-Ju) Yang469592b2014-02-18 19:15:41 +0800440 installer.Install()
Vic (Chun-Ju) Yang296871a2014-01-13 12:05:18 +0800441
442if __name__ == '__main__':
443 main()