diff options
Diffstat (limited to 'rawdisk.write')
-rwxr-xr-x | rawdisk.write | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/rawdisk.write b/rawdisk.write deleted file mode 100755 index a74d6905..00000000 --- a/rawdisk.write +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/python -# Copyright (C) 2012-2013 Codethink Limited -# -# This program 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; version 2 of the License. -# -# This program 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 this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - -'''A Morph deployment write extension for raw disk images.''' - - -import cliapp -import os -import sys -import time -import tempfile - -import morphlib.writeexts - - -class RawDiskWriteExtension(morphlib.writeexts.WriteExtension): - - '''Create a raw disk image during Morph's deployment. - - If the image already exists, it is upgraded. - - The location command line argument is the pathname of the disk image - to be created/upgraded. - - ''' - - def process_args(self, args): - if len(args) != 2: - raise cliapp.AppException('Wrong number of command line args') - - temp_root, location = args - if os.path.isfile(location): - self.upgrade_local_system(location, temp_root) - else: - self.create_local_system(temp_root, location) - self.status(msg='Disk image has been created at %s' % location) - - def upgrade_local_system(self, raw_disk, temp_root): - mp = self.mount(raw_disk) - - version_label = self.get_version_label(mp) - self.status(msg='Updating image to a new version with label %s' % - version_label) - - version_root = os.path.join(mp, 'systems', version_label) - os.mkdir(version_root) - - old_orig = os.path.join(mp, 'systems', 'factory', 'orig') - new_orig = os.path.join(version_root, 'orig') - cliapp.runcmd( - ['btrfs', 'subvolume', 'snapshot', old_orig, new_orig]) - - cliapp.runcmd( - ['rsync', '-a', '--checksum', '--numeric-ids', '--delete', - temp_root + os.path.sep, new_orig]) - - self.create_run(version_root) - - default_path = os.path.join(mp, 'systems', 'default') - if os.path.exists(default_path): - os.remove(default_path) - else: - # we are upgrading and old system that does - # not have an updated extlinux config file - if self.bootloader_is_wanted(): - self.install_extlinux(mp) - os.symlink(version_label, default_path) - - if self.bootloader_is_wanted(): - self.install_kernel(version_root, temp_root) - - self.unmount(mp) - - def get_version_label(self, mp): - version_label = os.environ.get('VERSION_LABEL') - - if version_label is None: - self.unmount(mp) - raise cliapp.AppException('VERSION_LABEL was not given') - - if os.path.exists(os.path.join(mp, 'systems', version_label)): - self.unmount(mp) - raise cliapp.AppException('VERSION_LABEL %s already exists' - % version_label) - - return version_label - - -RawDiskWriteExtension().run() - |