{-# LANGUAGE DeriveDataTypeable #-}
module Propellor.Types.OS (
System(..),
Distribution(..),
TargetOS(..),
DebianKernel(..),
DebianSuite(..),
FreeBSDRelease(..),
FBSDVersion(..),
isStable,
Release,
Architecture(..),
architectureToDebianArchString,
HostName,
UserName,
User(..),
Group(..),
userGroup,
Port(..),
systemToTargetOS,
) where
import Propellor.Types.ConfigurableValue
import Network.BSD (HostName)
import Data.Typeable
import Data.String
data System = System Distribution Architecture
deriving (Show, Eq, Typeable)
data Distribution
= Debian DebianKernel DebianSuite
| Buntish Release
| ArchLinux
| FreeBSD FreeBSDRelease
deriving (Show, Eq)
data TargetOS
= OSDebian
| OSBuntish
| OSArchLinux
| OSFreeBSD
deriving (Show, Eq, Ord)
systemToTargetOS :: System -> TargetOS
systemToTargetOS (System (Debian _ _) _) = OSDebian
systemToTargetOS (System (Buntish _) _) = OSBuntish
systemToTargetOS (System (ArchLinux) _) = OSArchLinux
systemToTargetOS (System (FreeBSD _) _) = OSFreeBSD
data DebianKernel = Linux | KFreeBSD | Hurd
deriving (Show, Eq)
data DebianSuite = Experimental | Unstable | Testing | Stable Release
deriving (Show, Eq)
data FreeBSDRelease = FBSDProduction FBSDVersion | FBSDLegacy FBSDVersion
deriving (Show, Eq)
data FBSDVersion = FBSD101 | FBSD102 | FBSD093
deriving (Eq)
instance IsString FBSDVersion where
fromString "10.1-RELEASE" = FBSD101
fromString "10.2-RELEASE" = FBSD102
fromString "9.3-RELEASE" = FBSD093
fromString _ = error "Invalid FreeBSD release"
instance ConfigurableValue FBSDVersion where
val FBSD101 = "10.1-RELEASE"
val FBSD102 = "10.2-RELEASE"
val FBSD093 = "9.3-RELEASE"
instance Show FBSDVersion where
show = val
isStable :: DebianSuite -> Bool
isStable (Stable _) = True
isStable _ = False
type Release = String
data Architecture
= X86_64
| X86_32
| ARMHF
| ARMEL
| PPC
| PPC64
| SPARC
| SPARC64
| MIPS
| MIPSEL
| MIPS64EL
| SH4
| IA64
| S390
| S390X
| ALPHA
| HPPA
| M68K
| ARM64
| X32
deriving (Show, Eq)
architectureToDebianArchString :: Architecture -> String
architectureToDebianArchString X86_64 = "amd64"
architectureToDebianArchString X86_32 = "i386"
architectureToDebianArchString ARMHF = "armhf"
architectureToDebianArchString ARMEL = "armel"
architectureToDebianArchString PPC = "powerpc"
architectureToDebianArchString PPC64 = "ppc64el"
architectureToDebianArchString SPARC = "sparc"
architectureToDebianArchString SPARC64 = "sparc64"
architectureToDebianArchString MIPS = "mips"
architectureToDebianArchString MIPSEL = "mipsel"
architectureToDebianArchString MIPS64EL = "mips64el"
architectureToDebianArchString SH4 = "sh"
architectureToDebianArchString IA64 = "ia64"
architectureToDebianArchString S390 = "s390"
architectureToDebianArchString S390X = "s390x"
architectureToDebianArchString ALPHA = "alpha"
architectureToDebianArchString HPPA = "hppa"
architectureToDebianArchString M68K = "m68k"
architectureToDebianArchString ARM64 = "arm64"
architectureToDebianArchString X32 = "x32"
type UserName = String
newtype User = User UserName
deriving (Eq, Ord, Show)
instance ConfigurableValue User where
val (User n) = n
newtype Group = Group String
deriving (Eq, Ord, Show)
instance ConfigurableValue Group where
val (Group n) = n
userGroup :: User -> Group
userGroup (User u) = Group u
newtype Port = Port Int
deriving (Eq, Ord, Show)
instance ConfigurableValue Port where
val (Port p) = show p