From a4572fca407e5577e2a9cff7a6e211645dd18b56 Mon Sep 17 00:00:00 2001 From: maralorn Date: Tue, 7 Feb 2023 17:55:41 +0100 Subject: [PATCH] Fix getting HostName --- packages/builders-configurator/exe/Main.hs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/builders-configurator/exe/Main.hs b/packages/builders-configurator/exe/Main.hs index 6ce37b85..9e643f7c 100644 --- a/packages/builders-configurator/exe/Main.hs +++ b/packages/builders-configurator/exe/Main.hs @@ -94,18 +94,15 @@ printBuilders = Text.unlines . fmap builderLine . Foldable.foldr' folder [] main :: IO () main = do args <- getArgs - env_host <- fromMaybe (error "accessed $HOST which is not set.") <$> lookupEnv "HOST" + env_host <- readFileBS "/etc/hostname" `Exception.catch` \(e :: Exception.IOException) -> pure (error (show e)) let (host, withoutConnection) = case args of - [] -> (env_host, False) - [host'] -> (host', False) - [host', "--without-connection"] -> (host', True) + [] -> (Text.strip (decodeUtf8 env_host), False) + [host'] -> (into host', False) + [host', "--without-connection"] -> (into host', True) _ -> error [i|Unknown arguments: #{args}|] builder_tries :: Ping :> es => Eff es [Text] builder_tries = testBuilders $ fromMaybe (error [i|#{host} not found in builderConfigs.|]) $ Map.lookup (into host) builderConfigs - builders <- - if withoutConnection - then pure $ Eff.runPureEff $ runWithoutConnectivity builder_tries - else Eff.runEff $ runWithPing builder_tries + builders <- Eff.runEff $ (if withoutConnection then runWithoutConnectivity else runWithPing) builder_tries (path, handle) <- IO.openTempFile "/tmp" "machines" TextIO.hPutStr handle (printBuilders builders) IO.hClose handle