Ubuntu Pastebin

Paste from ogra at Thu, 1 Sep 2016 10:50:08 +0000

Download as text
 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
ogra@styx:~/Devel/branches/ubuntu-image$ git diff
diff --git a/ubuntu_image/builder.py b/ubuntu_image/builder.py
index 3ca81ed..b3e85e7 100644
--- a/ubuntu_image/builder.py
+++ b/ubuntu_image/builder.py
@@ -26,7 +26,10 @@ def mount(img):
         tmpdir = resources.enter_context(TemporaryDirectory())
         mountpoint = os.path.join(tmpdir, 'root-mount')
         os.makedirs(mountpoint)
-        run('sudo mount -oloop {} {}'.format(img, mountpoint))
+        if os.getuid() != 0:
+            run('sudo mount -oloop {} {}'.format(img, mountpoint))
+        else:
+            run('mount -oloop {} {}'.format(img, mountpoint))
         resources.callback(run, 'sudo umount {}'.format(mountpoint))
         yield mountpoint
 
@@ -50,8 +53,12 @@ def _mkfs_ext4(img_file, contents_dir, label='writable'):
     run('mkfs.ext4 -L {} {}'.format(label, img_file))  # pragma: notravis
     with mount(img_file) as mountpoint:                # pragma: notravis
         # fixme: everything is terrible.
-        run('sudo cp -dR --preserve=mode,timestamps {}/* {}'.format(
-            contents_dir, mountpoint), shell=True)
+        if os.getuid() != 0:
+            run('sudo cp -dR --preserve=mode,timestamps {}/* {}'.format(
+                contents_dir, mountpoint), shell=True)
+        else:
+            run('cp -dR --preserve=mode,timestamps {}/* {}'.format(
+                contents_dir, mountpoint), shell=True)
 
 
 class ModelAssertionBuilder(State):
Download as text