diff options
author | Andrew Cady <d@jerkface.net> | 2018-07-09 22:25:33 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2018-07-09 22:25:33 -0400 |
commit | 67994be688ab65d9f135e920410f546b84de200d (patch) | |
tree | 73efaf8ac502886f8c683fa6e4f566996f162ed6 /fsmgr.hs | |
parent | 93745db66c1295b10a7917120b2cc121f5b0c9ae (diff) |
added config directive "chroot-commands"
Diffstat (limited to 'fsmgr.hs')
-rw-r--r-- | fsmgr.hs | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -9,8 +9,6 @@ | |||
9 | module Main where | 9 | module Main where |
10 | import Rebase.Prelude hiding (bool, hash, (<.>)) | 10 | import Rebase.Prelude hiding (bool, hash, (<.>)) |
11 | 11 | ||
12 | import Crypto.Hash | ||
13 | import Crypto.Hash.Types.Digest.Read () | ||
14 | import Data.Yaml.Combinators | 12 | import Data.Yaml.Combinators |
15 | import Development.Shake | 13 | import Development.Shake |
16 | import Development.Shake.Command () | 14 | import Development.Shake.Command () |
@@ -54,11 +52,12 @@ data BaseImageSpecification | |||
54 | deriving (Show, Read) | 52 | deriving (Show, Read) |
55 | 53 | ||
56 | data DiskImageConfig = DiskImageConfig { | 54 | data DiskImageConfig = DiskImageConfig { |
57 | initialImage :: BaseImageSpecification | 55 | initialImage :: BaseImageSpecification |
58 | , packages :: Set Package | 56 | , packages :: Set Package |
59 | -- , debconfConfig :: DebconfConfig | 57 | -- , debconfConfig :: DebconfConfig |
60 | , unpackOnly :: Bool | 58 | , unpackOnly :: Bool |
61 | , binaries :: Vector Text -- :: [Patch] | 59 | , binaries :: Vector Text |
60 | , chrootCommands :: Vector Text | ||
62 | } deriving (Show, Read) | 61 | } deriving (Show, Read) |
63 | 62 | ||
64 | parsePackageName :: Text -> Package | 63 | parsePackageName :: Text -> Package |
@@ -72,12 +71,7 @@ diskImageConfigParser = object $ | |||
72 | -- <*> pure (DebconfConfig "") | 71 | -- <*> pure (DebconfConfig "") |
73 | <*> defaultField "unpack-only" False bool | 72 | <*> defaultField "unpack-only" False bool |
74 | <*> defaultField "binaries" Vector.empty (array string) | 73 | <*> defaultField "binaries" Vector.empty (array string) |
75 | 74 | <*> defaultField "chroot-commands" Vector.empty (array string) | |
76 | diskImageFilename :: DiskImageConfig -> FilePath | ||
77 | diskImageFilename = (++ ".btrfs") . show . sha1 . show | ||
78 | where | ||
79 | sha1 :: String -> Digest SHA1 | ||
80 | sha1 = hash . encodeUtf8 . pack | ||
81 | 75 | ||
82 | readCfg :: FilePath -> Action DiskImageConfig | 76 | readCfg :: FilePath -> Action DiskImageConfig |
83 | readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml | 77 | readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml |
@@ -92,6 +86,7 @@ buildRoot DiskImageConfig{..} finalOut = do | |||
92 | let parent = "_build" </> f -<.> "btrfs" | 86 | let parent = "_build" </> f -<.> "btrfs" |
93 | need [parent] | 87 | need [parent] |
94 | cmd_ "cp --reflink" [parent, out] | 88 | cmd_ "cp --reflink" [parent, out] |
89 | cmd_ "btrfstune -f -S0" [out] | ||
95 | cmd_ "mkdir -p" [mountpoint] | 90 | cmd_ "mkdir -p" [mountpoint] |
96 | cmd_ "mount -t btrfs" [out] mountpoint | 91 | cmd_ "mount -t btrfs" [out] mountpoint |
97 | EmptyImageOfBytes n -> do | 92 | EmptyImageOfBytes n -> do |
@@ -110,10 +105,16 @@ buildRoot DiskImageConfig{..} finalOut = do | |||
110 | 105 | ||
111 | -- TODO: catch errors and umount, rmdir mountpoint | 106 | -- TODO: catch errors and umount, rmdir mountpoint |
112 | let (debs, packageNames) = partitionPackages $ unpack . coerce <$> toList packages | 107 | let (debs, packageNames) = partitionPackages $ unpack . coerce <$> toList packages |
108 | -- TODO: don't even run seflstrap when packageNames is null and a parent image exists | ||
113 | cmd_ "selfstrap --skip-update" | 109 | cmd_ "selfstrap --skip-update" |
114 | (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint]) packageNames | 110 | (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint]) packageNames |
115 | forM_ debs $ \pkg -> do | 111 | forM_ debs $ \pkg -> do |
116 | cmd_ "dpkg -i --root" [mountpoint, pkg] | 112 | cmd_ "dpkg -i --root" [mountpoint, pkg] |
113 | forM_ chrootCommands $ \c -> do | ||
114 | cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c] | ||
115 | cmd_ "umount" [mountpoint] | ||
116 | cmd_ "rmdir" [mountpoint] | ||
117 | cmd_ "btrfstune -S1" [out] | ||
117 | cmd_ "mv" [out, finalOut] | 118 | cmd_ "mv" [out, finalOut] |
118 | 119 | ||
119 | partitionPackages :: [String] -> ([String], [String]) | 120 | partitionPackages :: [String] -> ([String], [String]) |
@@ -171,5 +172,6 @@ shakeRules = do | |||
171 | buildRoot cfg out | 172 | buildRoot cfg out |
172 | 173 | ||
173 | "*.btrfs" %> \out -> do | 174 | "*.btrfs" %> \out -> do |
174 | orderOnly ["_build" </> out] | 175 | need ["_build" </> out] |
175 | cmd_ "cp --reflink=always -i" ["_build" </> out, out] | 176 | -- WithStderr False needed for `cp` to interact with the tty |
177 | cmd_ (WithStderr False) "cp --reflink=always -i" ["_build" </> out, out] | ||