summaryrefslogtreecommitdiff
path: root/fsmgr.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-07-10 01:18:55 -0400
committerAndrew Cady <d@jerkface.net>2018-07-10 05:46:00 -0400
commit8bca4cb18e18977c594fbebf5cbebb909bc0ef4b (patch)
treef91a84122eccdec729000fc5942a4028c4d971c9 /fsmgr.hs
parentca5de8fc5e6fd55a73ac58f939961818e31d3dbf (diff)
support for debconf
Diffstat (limited to 'fsmgr.hs')
-rw-r--r--fsmgr.hs28
1 files changed, 20 insertions, 8 deletions
diff --git a/fsmgr.hs b/fsmgr.hs
index 68def93..626f79f 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -55,7 +55,7 @@ data BaseImageSpecification
55data DiskImageConfig = DiskImageConfig { 55data DiskImageConfig = DiskImageConfig {
56 initialImage :: BaseImageSpecification 56 initialImage :: BaseImageSpecification
57, packages :: Set Package 57, packages :: Set Package
58-- , debconfConfig :: DebconfConfig 58, debconfConfig :: Maybe FilePath
59, unpackOnly :: Bool 59, unpackOnly :: Bool
60, binaries :: Vector Text 60, binaries :: Vector Text
61, chrootCommands :: Vector Text 61, chrootCommands :: Vector Text
@@ -69,7 +69,7 @@ diskImageConfigParser = object $
69 DiskImageConfig 69 DiskImageConfig
70 <$> field "parent" ((EmptyImageOfBytes <$> integer) <> (ParentImageConfigFile . unpack <$> string)) 70 <$> field "parent" ((EmptyImageOfBytes <$> integer) <> (ParentImageConfigFile . unpack <$> string))
71 <*> (Set.fromList . toList . fmap parsePackageName <$> defaultField "packages" Vector.empty (array string)) 71 <*> (Set.fromList . toList . fmap parsePackageName <$> defaultField "packages" Vector.empty (array string))
72 -- <*> pure (DebconfConfig "") 72 <*> (fmap unpack <$> optField "debconf" string)
73 <*> defaultField "unpack-only" False bool 73 <*> defaultField "unpack-only" False bool
74 <*> defaultField "binaries" Vector.empty (array string) 74 <*> defaultField "binaries" Vector.empty (array string)
75 <*> defaultField "chroot-commands" Vector.empty (array string) 75 <*> defaultField "chroot-commands" Vector.empty (array string)
@@ -77,6 +77,10 @@ diskImageConfigParser = object $
77readCfg :: FilePath -> Action DiskImageConfig 77readCfg :: FilePath -> Action DiskImageConfig
78readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml 78readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml
79 79
80noParent :: BaseImageSpecification -> Bool
81noParent (EmptyImageOfBytes _) = True
82noParent (ParentImageConfigFile _) = False
83
80buildRoot :: DiskImageConfig -> FilePath -> Action () 84buildRoot :: DiskImageConfig -> FilePath -> Action ()
81buildRoot DiskImageConfig{..} finalOut = do 85buildRoot DiskImageConfig{..} finalOut = do
82 let out = finalOut <.> "tmp" 86 let out = finalOut <.> "tmp"
@@ -102,20 +106,28 @@ buildRoot DiskImageConfig{..} finalOut = do
102 cmd_ "mount -t btrfs" [out, mountpoint] 106 cmd_ "mount -t btrfs" [out, mountpoint]
103 107
104 cmd_ (Cwd mountpoint) "mkdir -p var/cache/apt" 108 cmd_ (Cwd mountpoint) "mkdir -p var/cache/apt"
109 cmd_ (Cwd mountpoint) "mkdir -p var/cache/debconf"
105 cmd_ (Cwd mountpoint) "btrfs subvolume create var/cache/apt/archives" 110 cmd_ (Cwd mountpoint) "btrfs subvolume create var/cache/apt/archives"
106
107 -- TODO: catch errors and umount, rmdir mountpoint 111 -- TODO: catch errors and umount, rmdir mountpoint
112 {- 1. debconf -}
113 forM_ debconfConfig $
114 readFile' >=> liftIO . appendFile (mountpoint </> "var/cache/debconf/config.dat")
115 {- 2. dpkg installs -}
108 let (debs, packageNames) = partitionPackages $ unpack . coerce <$> toList packages 116 let (debs, packageNames) = partitionPackages $ unpack . coerce <$> toList packages
109 -- TODO: don't even run seflstrap when packageNames is null and a parent image exists 117 when (noParent initialImage || not (null packageNames)) $
110 cmd_ "selfstrap --skip-update" 118 -- When there is no parent, selfstrap should install packages marked
111 (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint]) packageNames 119 -- "Required" even if no packages are specified. When there is a parent,
120 -- assume that this has already happened.
121 cmd_ "selfstrap --skip-update" (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint]) packageNames
122 forM_ debs $ \pkg -> do cmd_ "dpkg -i --root" [mountpoint, pkg]
123 {- 3. binaries -}
112 forM_ (unpack <$> binaries) $ \b -> do 124 forM_ (unpack <$> binaries) $ \b -> do
113 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) 125 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b)
114 cmd_ "cp -L" [p] [mountpoint </> "usr/local/bin" </> b] 126 cmd_ "cp -L" [p] [mountpoint </> "usr/local/bin" </> b]
115 forM_ debs $ \pkg -> do 127 {- 4. custom setup commands -}
116 cmd_ "dpkg -i --root" [mountpoint, pkg]
117 forM_ chrootCommands $ \c -> do 128 forM_ chrootCommands $ \c -> do
118 cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c] 129 cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c]
130 -- cleanup
119 cmd_ "umount" [mountpoint] 131 cmd_ "umount" [mountpoint]
120 cmd_ "rmdir" [mountpoint] 132 cmd_ "rmdir" [mountpoint]
121 cmd_ "btrfstune -S1" [out] 133 cmd_ "btrfstune -S1" [out]