diff options
author | Andrew Cady <d@jerkface.net> | 2020-05-29 21:50:50 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-05-29 21:50:50 -0400 |
commit | be7e755858e700aebb11f7533b8bd362e7a77656 (patch) | |
tree | 55712bd8f26beaa47cfd03d1172bdfe734723d41 | |
parent | e1794208b62172db0bfe37f69173b6362fd618b4 (diff) |
track devices in multi-device btrfs images, in file *.btrfs.devices.txt
-rw-r--r-- | fsmgr.hs | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -25,6 +25,7 @@ import qualified Options.Applicative as Opt | |||
25 | 25 | ||
26 | import ConfigFile | 26 | import ConfigFile |
27 | import String | 27 | import String |
28 | import System.Directory as IO | ||
28 | import System.Directory (createDirectoryIfMissing, | 29 | import System.Directory (createDirectoryIfMissing, |
29 | getCurrentDirectory) | 30 | getCurrentDirectory) |
30 | import System.Posix.Process (getProcessID) | 31 | import System.Posix.Process (getProcessID) |
@@ -126,6 +127,11 @@ getHomeDir = do | |||
126 | Stdout homeDir <- cmd "sh -c" ["if [ \"$SUDO_USER\" ]; then getent passwd \"$SUDO_USER\" | cut -d: -f6; else printf \"%s\n\" \"$HOME\"; fi"] | 127 | Stdout homeDir <- cmd "sh -c" ["if [ \"$SUDO_USER\" ]; then getent passwd \"$SUDO_USER\" | cut -d: -f6; else printf \"%s\n\" \"$HOME\"; fi"] |
127 | return homeDir | 128 | return homeDir |
128 | 129 | ||
130 | readFileOptional :: FilePath -> IO (String) | ||
131 | readFileOptional f = IO.doesFileExist f >>= \case | ||
132 | True -> readFile f | ||
133 | False -> return "" | ||
134 | |||
129 | buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () | 135 | buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () |
130 | buildInitialImage DiskImageConfig{..} mountpoint out = do | 136 | buildInitialImage DiskImageConfig{..} mountpoint out = do |
131 | case initialImage of | 137 | case initialImage of |
@@ -135,12 +141,17 @@ buildInitialImage DiskImageConfig{..} mountpoint out = do | |||
135 | cmd_ "cp --reflink" [parent, out] | 141 | cmd_ "cp --reflink" [parent, out] |
136 | cmd_ "btrfstune -f -S0" [out] | 142 | cmd_ "btrfstune -f -S0" [out] |
137 | cmd_ "mkdir -p" [mountpoint] | 143 | cmd_ "mkdir -p" [mountpoint] |
144 | cmd_ "sh -c" ["if [ -e \"$0\" ]; then cp \"$0\" \"$1\"; fi", parent <.> "devices.txt", out -<.> "devices.txt"] | ||
145 | |||
138 | cmd_ "mount -t btrfs" [out] mountpoint | 146 | cmd_ "mount -t btrfs" [out] mountpoint |
139 | 147 | ||
140 | SeededImage n f -> do | 148 | SeededImage n f -> do |
141 | let parent = "_build" </> f -<.> "btrfs" | 149 | let parent = "_build" </> f -<.> "btrfs" |
142 | need [parent] | 150 | need [parent] |
143 | 151 | ||
152 | devices <- either (const []) lines . readEither <$> liftIO (readFileOptional (parent <.> "devices.txt")) | ||
153 | writeFile' (out -<.> "devices.txt") (unlines $ parent:devices) | ||
154 | |||
144 | -- allocate new image file | 155 | -- allocate new image file |
145 | cmd_ "rm -f" [out] | 156 | cmd_ "rm -f" [out] |
146 | cmd_ "truncate -s" [show n, out] | 157 | cmd_ "truncate -s" [show n, out] |