summaryrefslogtreecommitdiff
path: root/fsmgr.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-07-16 16:18:33 -0400
committerAndrew Cady <d@jerkface.net>2018-07-16 16:33:35 -0400
commit043c115135e3d72424a649c74fa4d4219b3bda1d (patch)
treebd9d2eab6eba71f97f2ae547e356e20857bdae1b /fsmgr.hs
parente91baa702cb70b220116cbdd9bc897cfb3bb3e8e (diff)
fail early on a few conditions
Diffstat (limited to 'fsmgr.hs')
-rw-r--r--fsmgr.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/fsmgr.hs b/fsmgr.hs
index 6d559aa..e87ebc9 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -20,11 +20,13 @@ import Development.Shake.Command ()
20import Development.Shake.FilePath 20import Development.Shake.FilePath
21 21
22import qualified Options.Applicative as Opt 22import qualified Options.Applicative as Opt
23 ;import Options.Applicative hiding (action) 23 ;import Options.Applicative hiding (action, command)
24 24
25import ConfigFile 25import ConfigFile
26import System.Directory (createDirectoryIfMissing) 26import System.Directory (createDirectoryIfMissing)
27import System.Posix.Process (getProcessID) 27import System.Posix.Process (getProcessID)
28import System.Posix.Types (CUid (..))
29import System.Posix.User (getEffectiveUserID)
28 30
29noParent :: BaseImageSpecification -> Bool 31noParent :: BaseImageSpecification -> Bool
30noParent (EmptyImageOfBytes _) = True 32noParent (EmptyImageOfBytes _) = True
@@ -121,9 +123,6 @@ buildOpts = Build . BuildOpts <$> argument str idm
121chrootOpts :: Parser Command 123chrootOpts :: Parser Command
122chrootOpts = fmap Chroot $ ChrootOpts <$> argument str idm <*> many (argument str idm) 124chrootOpts = fmap Chroot $ ChrootOpts <$> argument str idm <*> many (argument str idm)
123 125
124-- TODO: Fail early on:
125-- 1. not running as root
126-- 2. no "selfstrap" in PATH
127main :: IO () 126main :: IO ()
128main = customExecParser (prefs showHelpOnEmpty) (info opts desc) >>= run 127main = customExecParser (prefs showHelpOnEmpty) (info opts desc) >>= run
129 where 128 where
@@ -142,8 +141,8 @@ main = customExecParser (prefs showHelpOnEmpty) (info opts desc) >>= run
142 info' o d = info (helper <*> o) (progDesc $ unwords d) 141 info' o d = info (helper <*> o) (progDesc $ unwords d)
143 142
144run :: Options -> IO () 143run :: Options -> IO ()
145run (Options (Build (BuildOpts target))) = shakeBuildOneImage target 144run (Options (Build (BuildOpts target))) = earlyFail >> shakeBuildOneImage target
146run (Options (Chroot (ChrootOpts target args))) = chrootImage target args 145run (Options (Chroot (ChrootOpts target args))) = earlyFail >> chrootImage target args
147 146
148useCGroups :: Bool 147useCGroups :: Bool
149useCGroups = True -- TODO: make command-line option 148useCGroups = True -- TODO: make command-line option
@@ -215,6 +214,13 @@ cgroupChroot groupName mnt args = do
215 "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec \"$@\""] 214 "sh -exc" ["mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec \"$@\""]
216 "sh" args 215 "sh" args
217 216
217earlyFail :: IO ()
218earlyFail = do
219 CUid euid <- liftIO getEffectiveUserID
220 when (euid /= 0) $ fail "you are not root"
221 Stdout () <- cmd (Traced []) "which selfstrap"
222 return ()
223
218shakeRules :: Rules () 224shakeRules :: Rules ()
219shakeRules = do 225shakeRules = do
220 "_build/*.yaml.canon" %> \out -> do 226 "_build/*.yaml.canon" %> \out -> do