summaryrefslogtreecommitdiff
path: root/morphlib/exts/rawdisk.check
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/exts/rawdisk.check')
-rwxr-xr-xmorphlib/exts/rawdisk.check21
1 files changed, 21 insertions, 0 deletions
diff --git a/morphlib/exts/rawdisk.check b/morphlib/exts/rawdisk.check
index 6a656ee7..5e75abe2 100755
--- a/morphlib/exts/rawdisk.check
+++ b/morphlib/exts/rawdisk.check
@@ -20,6 +20,8 @@ import cliapp
import morphlib.writeexts
+import os
+
class RawdiskCheckExtension(morphlib.writeexts.WriteExtension):
def process_args(self, args):
@@ -28,4 +30,23 @@ class RawdiskCheckExtension(morphlib.writeexts.WriteExtension):
self.require_btrfs_in_deployment_host_kernel()
+ location = args[0]
+ upgrade = self.get_environment_boolean('UPGRADE')
+ if upgrade:
+ if not os.path.isfile(location):
+ raise cliapp.AppException(
+ 'Cannot upgrade %s: it is not an existing disk image' %
+ location)
+
+ version_label = os.environ.get('VERSION_LABEL')
+ if version_label is None:
+ raise cliapp.AppException(
+ 'VERSION_LABEL was not given. It is required when '
+ 'upgrading an existing system.')
+ else:
+ if os.path.exists(location):
+ raise cliapp.AppException(
+ 'Target %s already exists. Pass --upgrade if you want to '
+ 'update an existing image.' % location)
+
RawdiskCheckExtension().run()