@@ -49,7 +49,7 @@ import Prelude hiding ( abs
4949 , writeFile
5050 )
5151import System.Info
52- import System.OsRelease
52+ import System.OsRelease as OSR
5353import System.Exit
5454import System.FilePath
5555import Text.PrettyPrint.HughesPJClass ( prettyShow )
@@ -134,33 +134,34 @@ getLinuxDistro :: (Alternative m, MonadCatch m, MonadIO m, MonadFail m)
134134 => Excepts '[DistroNotFound ] m (LinuxDistro , Maybe Versioning )
135135getLinuxDistro = do
136136 -- TODO: don't do alternative on IO, because it hides bugs
137- (name, ver) <- handleIO (\ _ -> throwE DistroNotFound ) $ lift $ asum
137+ (name, mid, ver) <- handleIO (\ _ -> throwE DistroNotFound ) $ lift $ asum
138138 [ liftIO try_os_release
139139 , try_lsb_release_cmd
140140 , liftIO try_redhat_release
141141 , liftIO try_debian_version
142142 ]
143+ let hasWord xs = let f t = any (\ x -> match (regex x) (T. unpack t)) xs
144+ in f name || maybe False f mid
143145 let parsedVer = ver >>= either (const Nothing ) Just . versioning
144146 distro = if
145- | hasWord name [" debian" ] -> Debian
146- | hasWord name [" ubuntu" ] -> Ubuntu
147- | hasWord name [" linuxmint" , " Linux Mint" ] -> Mint
148- | hasWord name [" fedora" ] -> Fedora
149- | hasWord name [" centos" ] -> CentOS
150- | hasWord name [" Red Hat" ] -> RedHat
151- | hasWord name [" alpine" ] -> Alpine
152- | hasWord name [" exherbo" ] -> Exherbo
153- | hasWord name [" gentoo" ] -> Gentoo
154- | hasWord name [" amazonlinux" , " Amazon Linux" ] -> AmazonLinux
155- | hasWord name [" rocky" , " Rocky Linux" ] -> Rocky
147+ | hasWord [" debian" ] -> Debian
148+ | hasWord [" ubuntu" ] -> Ubuntu
149+ | hasWord [" linuxmint" , " Linux Mint" ] -> Mint
150+ | hasWord [" fedora" ] -> Fedora
151+ | hasWord [" centos" ] -> CentOS
152+ | hasWord [" Red Hat" ] -> RedHat
153+ | hasWord [" alpine" ] -> Alpine
154+ | hasWord [" exherbo" ] -> Exherbo
155+ | hasWord [" gentoo" ] -> Gentoo
156+ | hasWord [" opensuse" , " suse" ] -> OpenSUSE
157+ | hasWord [" amazonlinux" , " Amazon Linux" ] -> AmazonLinux
158+ | hasWord [" rocky" , " Rocky Linux" ] -> Rocky
156159 -- https://github.com/void-linux/void-packages/blob/master/srcpkgs/base-files/files/os-release
157- | hasWord name [" void" , " Void Linux" ] -> Void
158- | otherwise -> UnknownLinux
160+ | hasWord [" void" , " Void Linux" ] -> Void
161+ | otherwise -> OtherLinux ( T. unpack $ fromMaybe name mid)
159162 pure (distro, parsedVer)
160163 where
161- hasWord t = any (\ x -> match (regex x) (T. unpack t))
162- where
163- regex x = makeRegexOpts compIgnoreCase execBlank ([s |\<|] ++ x ++ [s |\>|])
164+ regex x = makeRegexOpts compIgnoreCase execBlank ([s |\<|] ++ x ++ [s |\>|])
164165
165166 lsb_release_cmd :: FilePath
166167 lsb_release_cmd = " lsb-release"
@@ -169,21 +170,21 @@ getLinuxDistro = do
169170 debian_version :: FilePath
170171 debian_version = " /etc/debian_version"
171172
172- try_os_release :: IO (Text , Maybe Text )
173+ try_os_release :: IO (Text , Maybe Text , Maybe Text )
173174 try_os_release = do
174- Just OsRelease { name = name, version_id = version_id } <-
175+ Just OsRelease { name = name, version_id = version_id, OSR. id = id' } <-
175176 fmap osRelease <$> parseOsRelease
176- pure (T. pack name, fmap T. pack version_id)
177+ pure (T. pack name, Just ( T. pack id'), fmap T. pack version_id)
177178
178179 try_lsb_release_cmd :: (MonadFail m , MonadIO m )
179- => m (Text , Maybe Text )
180+ => m (Text , Maybe Text , Maybe Text )
180181 try_lsb_release_cmd = do
181182 (Just _) <- liftIO $ findExecutable lsb_release_cmd
182183 name <- fmap _stdOut $ executeOut lsb_release_cmd [" -si" ] Nothing
183184 ver <- fmap _stdOut $ executeOut lsb_release_cmd [" -sr" ] Nothing
184- pure (decUTF8Safe' name, Just $ decUTF8Safe' ver)
185+ pure (decUTF8Safe' name, Nothing , Just $ decUTF8Safe' ver)
185186
186- try_redhat_release :: IO (Text , Maybe Text )
187+ try_redhat_release :: IO (Text , Maybe Text , Maybe Text )
187188 try_redhat_release = do
188189 t <- T. readFile redhat_release
189190 let nameRegex n =
@@ -199,16 +200,16 @@ getLinuxDistro = do
199200 verRe = fromEmpty . match verRegex $ T. unpack t :: Maybe String
200201 (Just name) <- pure
201202 (nameRe " CentOS" <|> nameRe " Fedora" <|> nameRe " Red Hat" )
202- pure (T. pack name, fmap T. pack verRe)
203+ pure (T. pack name, Nothing , fmap T. pack verRe)
203204 where
204205 fromEmpty :: String -> Maybe String
205206 fromEmpty " " = Nothing
206207 fromEmpty s' = Just s'
207208
208- try_debian_version :: IO (Text , Maybe Text )
209+ try_debian_version :: IO (Text , Maybe Text , Maybe Text )
209210 try_debian_version = do
210211 ver <- T. readFile debian_version
211- pure (T. pack " debian" , Just ver)
212+ pure (T. pack " debian" , Just ( T. pack " debian " ), Just ver)
212213
213214
214215getStackGhcBuilds :: (MonadReader env m , HasLog env , MonadIO m )
0 commit comments