summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Chroot.hs
diff options
context:
space:
mode:
authorBen Boeckel2015-10-20 23:52:27 -0400
committerJoey Hess2015-10-23 01:22:30 -0400
commit62aaba85c7ff40d44fa2101b05e6577dee7d0184 (patch)
tree7231cc7e02c22431d9a07e2df9d8bd47a0825d25 /src/Propellor/Property/Chroot.hs
parent54125139a306209995f9e145998514bc6a9233ab (diff)
chroot: add a ChrootTarball chroot type
This extracts a minimal tarball into a target directory. (cherry picked from commit 33ac6c1c4bb2581d6f5a27254e52956e5a257326)
Diffstat (limited to 'src/Propellor/Property/Chroot.hs')
-rw-r--r--src/Propellor/Property/Chroot.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs
index 7ec2010c..a0bbad35 100644
--- a/src/Propellor/Property/Chroot.hs
+++ b/src/Propellor/Property/Chroot.hs
@@ -22,6 +22,7 @@ import Propellor.Types.Info
import Propellor.Property.Chroot.Util
import qualified Propellor.Property.Debootstrap as Debootstrap
import qualified Propellor.Property.Systemd.Core as Systemd
+import qualified Propellor.Property.File as File
import qualified Propellor.Shim as Shim
import Propellor.Property.Mount
@@ -52,6 +53,29 @@ class ChrootBootstrapper b where
-- If the operating System is not supported, return Nothing.
buildchroot :: b -> System -> FilePath -> Maybe (Property HasInfo)
+-- | Use to extract a tarball with a filesystem image.
+--
+-- The filesystem image is expected to be a root directory (no top-level
+-- directory, also known as a "tarbomb"). It may be optionally compressed with
+-- any format `tar` knows how to detect automatically.
+data ChrootTarball = ChrootTarball FilePath
+
+instance ChrootBootstrapper ChrootTarball where
+ buildchroot (ChrootTarball tb) _ loc = Just $ extractTarball loc tb
+
+extractTarball :: FilePath -> FilePath -> Property HasInfo
+extractTarball target src = toProp .
+ check (unpopulated target) $
+ cmdProperty "tar" params
+ `requires` File.dirExists target
+ where
+ params =
+ [ "-C"
+ , target
+ , "-xf"
+ , src
+ ]
+
-- | Use to bootstrap a chroot with debootstrap.
data Debootstrapped = Debootstrapped Debootstrap.DebootstrapConfig