From: Lucas De Marchi Date: Thu, 4 Jan 2018 22:45:34 +0000 (-0800) Subject: Add tar archive support for extra and skeleton trees X-Git-Tag: v4~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F192%2Fhead;p=thirdparty%2Fmkosi.git Add tar archive support for extra and skeleton trees 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. --- diff --git a/README.md b/README.md index 386000081..f536f921d 100644 --- 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 927ad3149..b17ca4bcc 100755 --- 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):