diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-08-26 11:23:42 -0700 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-08-26 11:23:42 -0700 |
| commit | a4ac16ab9432a9f6e180e9e416e95de8433ed016 (patch) | |
| tree | 8e5dc34c025109ff544c76e43a987c773fe2ac89 /src/Propellor/Property/Partition.hs | |
| parent | 01d1cbb8361d1fada638bd4c554f3ea9fe7b8c76 (diff) | |
| parent | 89dec139eef3d409c06877d5e8fd1dc1085465d1 (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Property/Partition.hs')
| -rw-r--r-- | src/Propellor/Property/Partition.hs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Propellor/Property/Partition.hs b/src/Propellor/Property/Partition.hs new file mode 100644 index 00000000..41bdf795 --- /dev/null +++ b/src/Propellor/Property/Partition.hs @@ -0,0 +1,56 @@ +{-# LANGUAGE FlexibleContexts #-} + +module Propellor.Property.Partition where + +import Propellor +import qualified Propellor.Property.Apt as Apt + +-- | Filesystems etc that can be used for a partition. +data Fs = EXT2 | EXT3 | EXT4 | BTRFS | REISERFS | XFS | FAT | VFAT | NTFS | LinuxSwap + deriving (Show) + +data Eep = YesReallyFormatPartition + +-- | Formats a partition. +formatted :: Eep -> Fs -> FilePath -> Property NoInfo +formatted = formatted' [] + +-- | Options passed to a mkfs.* command when making a filesystem. +-- +-- Eg, ["-m0"] +type MkfsOpts = [String] + +formatted' :: MkfsOpts -> Eep -> Fs -> FilePath -> Property NoInfo +formatted' opts YesReallyFormatPartition fs dev = + cmdProperty cmd opts' `requires` Apt.installed [pkg] + where + (cmd, opts', pkg) = case fs of + EXT2 -> ("mkfs.ext2", optsdev, "e2fsprogs") + EXT3 -> ("mkfs.ext3", optsdev, "e2fsprogs") + EXT4 -> ("mkfs.ext4", optsdev, "e2fsprogs") + BTRFS -> ("mkfs.btrfs", optsdev, "btrfs-tools") + REISERFS -> ("mkfs.reiserfs", optsdev, "reiserfsprogs") + XFS -> ("mkfs.xfs", optsdev, "xfsprogs") + FAT -> ("mkfs.fat", optsdev, "dosfstools") + VFAT -> ("mkfs.vfat", optsdev, "dosfstools") + NTFS -> ("mkfs.ntfs", optsdev, "ntfs-3g") + LinuxSwap -> ("mkswap", optsdev, "util-linux") + optsdev = opts++[dev] + +-- | Uses the kpartx utility to create device maps for partitions contained +-- within a disk image file. The resulting devices are passed to the +-- property, which can operate on them. Always cleans up after itself, +-- by removing the device maps after the property is run. +kpartx :: FilePath -> ([FilePath] -> Property NoInfo) -> Property NoInfo +kpartx diskimage mkprop = go `requires` Apt.installed ["kpartx"] + where + go = property (propertyDesc (mkprop [])) $ do + cleanup -- idempotency + s <- liftIO $ readProcess "kpartx" ["-avs", diskimage] + r <- ensureProperty (mkprop (devlist s)) + cleanup + return r + devlist = mapMaybe (finddev . words) . lines + finddev ("add":"map":s:_) = Just ("/dev/mapper/" ++ s) + finddev _ = Nothing + cleanup = void $ liftIO $ boolSystem "kpartx" [Param "-d", File diskimage] |
