This commit is contained in:
Joey Hess 2014-03-30 01:17:19 -04:00
parent 8684db8bbf
commit 3940f2cbde
Failed to extract signature
3 changed files with 7 additions and 26 deletions

View File

@ -1,10 +1,9 @@
module HostName where
import Data.Maybe
import Control.Applicative
import System.Environment
import qualified Utility.Network as Network
import Utility.Process
type HostName = String
@ -12,5 +11,8 @@ getHostName :: IO HostName
getHostName = go =<< getArgs
where
go (h:_) = return h
go [] = fromMaybe nohostname <$> Network.getHostname
nohostname = error "Cannot determine hostname! Pass it on the command line."
go [] = do
s <- takeWhile (/= '\n') <$> readProcess "hostname" ["-f"]
if null s
then error "Cannot determine hostname! Pass it on the command line."
else return s

View File

@ -15,7 +15,7 @@ main = ensureProperties . getProperties =<< getHostName
- or one specified on the command line is converted into a list of
- Properties for that system. -}
getProperties :: HostName -> [Property]
getProperties "clam" =
getProperties "clam.kitenet.net" =
-- Clean up the system as installed by cloudatcost.com
[ User.nuked "user"
, Apt.removed ["exim4"] `onChange` Apt.autoRemove

View File

@ -1,21 +0,0 @@
{- network functions
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Utility.Network where
import Utility.Process
import Utility.Exception
import Control.Applicative
{- Haskell lacks uname(2) bindings, except in the
- Bindings.Uname addon. Rather than depend on that,
- use uname -n when available. -}
getHostname :: IO (Maybe String)
getHostname = catchMaybeIO uname_node
where
uname_node = takeWhile (/= '\n') <$> readProcess "uname" ["-n"]