]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add tar archive support for extra and skeleton trees 192/head
authorLucas De Marchi <lucas.demarchi@intel.com>
Thu, 4 Jan 2018 22:45:34 +0000 (14:45 -0800)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 4 Jan 2018 22:45:34 +0000 (14:45 -0800)
Like documentation here says, it allows one to preseve file ownership
when adding files to the final image. This may be particularly useful if
you are adding configuration files for a daemon that is not supposed to
run as root, but as a pre-defined user.

README.md
mkosi

index 386000081036bbd020d9404dc9d47edfb9959558..f536f921d2e07bf91a0fc0fda6bac4d8eb8c981b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -153,17 +153,22 @@ they exist in the local directory:
   and the argument gets converted as follows: "--with-network" becomes
   "WithNetwork=yes".
 
-* `mkosi.extra/` may be a directory. If this exists all files
-  contained in it are copied over the directory tree of the
-  image after the *OS* was installed. This may be used to add in
-  additional files to an image, on top of what the
-  distribution includes in its packages.
-
-* `mkosi.skeleton/` may be a directory and works in the same way as
-  `mkosi.extra`, but the files are copied before anything else so to
-  have a skeleton tree for the OS. This allows to change the package
-  manager and create files that need to be there before anythin is
-  installed.
+* `mkosi.extra/` or `mkosi.extra.tar` may be respectively a directory
+  or archive. If any exist all files contained in it are copied over the
+  directory tree of the image after the *OS* was installed. This may be used to
+  add in additional files to an image, on top of what the distribution includes
+  in its packages. When using a directory file ownership is not preserved:
+  all files copied will be owned by root. To preserve ownership use a tar
+  archive.
+
+* `mkosi.skeleton/` or `mkosi.skeleton.tar` may be respectively a directory
+  or archive, and they work in the same way as
+  `mkosi.extra`/`mkosi.skeleton.tar`. However the files are copied before
+  anything else so to have a skeleton tree for the OS. This allows to change
+  the package manager and create files that need to be there before anything is
+  installed. When using a directory file ownership is not preserved:
+  all files copied will be owned by root. To preserve ownership use a tar
+  archive.
 
 * `mkosi.build` may be an executable script. If it exists the image
   will be built twice: the first iteration will be the *development*
diff --git a/mkosi b/mkosi
index 927ad3149f923cc599eee55bee210e76948264e9..b17ca4bcce840c73998be538f2a6cc59b4532815 100755 (executable)
--- a/mkosi
+++ b/mkosi
@@ -1567,7 +1567,10 @@ def install_extra_trees(args, workspace, for_cache):
 
     with complete_step('Copying in extra file trees'):
         for d in args.extra_trees:
-            copy(d, os.path.join(workspace, "root"))
+            if os.path.isdir(d):
+                copy(d, os.path.join(workspace, "root"))
+            else:
+                shutil.unpack_archive(d, os.path.join(workspace, "root"))
 
 def install_skeleton_trees(args, workspace, for_cache):
     if not args.skeleton_trees:
@@ -1575,7 +1578,10 @@ def install_skeleton_trees(args, workspace, for_cache):
 
     with complete_step('Copying in skeleton file trees'):
         for d in args.skeleton_trees:
-            copy(d, os.path.join(workspace, "root"))
+            if os.path.isdir(d):
+                copy(d, os.path.join(workspace, "root"))
+            else:
+                shutil.unpack_archive(d, os.path.join(workspace, "root"))
 
 def copy_git_files(src, dest, *, git_files):
     run(['git', 'clone', '--depth=1', '--recursive', '--shallow-submodules', src, dest],
@@ -2595,10 +2601,14 @@ def find_nspawn_settings(args):
 def find_extra(args):
     if os.path.isdir("mkosi.extra"):
         args.extra_trees.append("mkosi.extra")
+    if os.path.isfile("mkosi.extra.tar"):
+        args.extra_trees.append("mkosi.extra.tar")
 
 def find_skeleton(args):
     if os.path.isdir("mkosi.skeleton"):
         args.skeleton_trees.append("mkosi.skeleton")
+    if os.path.isfile("mkosi.skeleton.tar"):
+        args.skeleton_trees.append("mkosi.skeleton.tar")
 
 def find_cache(args):