diff options
author | Andrew Cady <d@jerkface.net> | 2019-06-19 12:03:35 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2019-06-19 12:03:35 -0400 |
commit | 67553d3fb69b4af520a819ecf390dd943eb5880f (patch) | |
tree | 7e8cc4546550d3836e76f3a1938e8ddd69fdeba8 /fsmgr.hs | |
parent | e5fc609586b56ab41c494d0c76757cc071c712a8 (diff) |
support for skel-files
Diffstat (limited to 'fsmgr.hs')
-rw-r--r-- | fsmgr.hs | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -23,7 +23,7 @@ import qualified Options.Applicative as Opt | |||
23 | ;import Options.Applicative hiding (action, command) | 23 | ;import Options.Applicative hiding (action, command) |
24 | 24 | ||
25 | import ConfigFile | 25 | import ConfigFile |
26 | import System.Directory (createDirectoryIfMissing) | 26 | import System.Directory (getCurrentDirectory, createDirectoryIfMissing) |
27 | import System.Posix.Process (getProcessID) | 27 | import System.Posix.Process (getProcessID) |
28 | import System.Posix.Types (CUid (..)) | 28 | import System.Posix.Types (CUid (..)) |
29 | import System.Posix.User (getEffectiveUserID) | 29 | import System.Posix.User (getEffectiveUserID) |
@@ -63,6 +63,12 @@ buildRoot config@DiskImageConfig{..} finalOut = do | |||
63 | forM_ (unpack <$> binaries) $ \b -> do | 63 | forM_ (unpack <$> binaries) $ \b -> do |
64 | p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) | 64 | p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) |
65 | cmd_ "cp -L" [p] [mountpoint </> "usr/local/bin" </> b] | 65 | cmd_ "cp -L" [p] [mountpoint </> "usr/local/bin" </> b] |
66 | {- 3.5 skel -} | ||
67 | forM_ (unpack <$> skelFiles) $ \f -> do | ||
68 | homeDir <- getHomeDir | ||
69 | target <- absPath mountpoint <&> (</> "etc/skel") | ||
70 | cmd_ "mkdir -p" [target] | ||
71 | cmd_ (Cwd homeDir) "cp -r --preserve=mode,timestamps -L --parents -t" [target] [f] | ||
66 | {- 4. custom setup commands -} | 72 | {- 4. custom setup commands -} |
67 | forM_ chrootCommands $ \c -> do | 73 | forM_ chrootCommands $ \c -> do |
68 | cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c] | 74 | cmd_ "chroot" [mountpoint] "/bin/sh -c" [unpack c] |
@@ -78,6 +84,17 @@ buildRoot config@DiskImageConfig{..} finalOut = do | |||
78 | cmd_ "btrfstune -S1" [out] | 84 | cmd_ "btrfstune -S1" [out] |
79 | cmd_ "mv" [out, finalOut] | 85 | cmd_ "mv" [out, finalOut] |
80 | 86 | ||
87 | absPath :: MonadIO m => FilePath -> m FilePath | ||
88 | absPath f@('/':_) = return f | ||
89 | absPath f = do | ||
90 | wd <- liftIO getCurrentDirectory | ||
91 | return $ wd </> f | ||
92 | |||
93 | getHomeDir :: Action FilePath | ||
94 | getHomeDir = do | ||
95 | Stdout homeDir <- cmd ["sh", "-c", "getent passwd \"$SUDO_USER\"|(IFS=: read _ _ _ _ _ d _; printf %s \"$d\")"] | ||
96 | return homeDir | ||
97 | |||
81 | buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () | 98 | buildInitialImage :: DiskImageConfig -> FilePath -> FilePath -> Action () |
82 | buildInitialImage DiskImageConfig{..} mountpoint out = do | 99 | buildInitialImage DiskImageConfig{..} mountpoint out = do |
83 | case initialImage of | 100 | case initialImage of |