plash import-tar
Usage
plash import-tar [ TARFILE ]
Description
Create a container from a tar file.
If the TARFILE argument is ommited, the tar file is read from stdin.
Tested Behaviour
#!/bin/sh
set -ex
tar=$(mktemp)
plash b export-tar -f 1 --run 'touch /myperson' -- $tar
• importing tar file succeeds
new=$(plash import-tar $tar)
plash with-mount $new ls ./myperson
• can import file from stdin
cat $tar | plash import-tar
• importing invalid or missing file fails
(! plash import-tar /doesnotexistssssh_really_4423487)
badtar=$(mktemp)
(! plash import-tar $badtar)
• importing invalid file from stdin fails
(! echo 'invalid' | plash import-tar)
Source Code
#define USAGE "usage: plash import-tar [ TARFILE ]\n"
#include <plash.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int import_tar_main(int argc, char *argv[]) {
char *tarfile = argv[1];
if (tarfile == NULL) {
tarfile = "-";
}
char *tmpdir = pl_call("mkdtemp");
pl_run("/proc/self/exe", "sudo", "tar", "-C", tmpdir, "-xf", tarfile);
execlp("/proc/self/exe", "plash", "add-layer", "0", tmpdir, NULL);
pl_fatal("execlp");
return EXIT_FAILURE;
}