diff --git a/src/Commands/Depends.hs b/src/Commands/Depends.hs index 8894a96..5ae15a0 100644 --- a/src/Commands/Depends.hs +++ b/src/Commands/Depends.hs @@ -5,7 +5,7 @@ -- Maintainer : Jens Petersen -- Stability : alpha -- --- Explanation: cabal wrapper which yum installs dependencies +-- Explanation: determines dependencies -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by diff --git a/src/Commands/Install.hs b/src/Commands/Install.hs index 6416633..fb81143 100644 --- a/src/Commands/Install.hs +++ b/src/Commands/Install.hs @@ -6,7 +6,7 @@ -- Stability : alpha -- Portability : portable -- --- Explanation: cabal wrapper which yum installs dependencies +-- Explanation: cabal wrapper which installs rpm dependencies -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ import Commands.RpmBuild (rpmBuild) import Dependencies (missingPackages, notInstalled) import PackageUtils (PackageData (..), RpmStage (..), stripPkgDevel) import Setup (RpmFlags (..)) -import SysCmd (cmd, cmd_, sudo, yumInstall, (+-+)) +import SysCmd (cmd, cmd_, pkgInstall, rpmInstall, (+-+)) import Control.Applicative ((<$>)) import Control.Monad (unless, when) @@ -32,7 +32,7 @@ install pkgdata flags = do let pkgDesc = packageDesc pkgdata missing <- missingPackages pkgDesc unless (null missing) $ do - yumInstall missing False + pkgInstall missing False stillMissing <- missingPackages pkgDesc unless (null stillMissing) $ do putStrLn $ "Missing:" +-+ unwords stillMissing @@ -42,7 +42,7 @@ install pkgdata flags = do rpmdir <- cmd "rpm" ["--eval", "%{_rpmdir}"] rpms <- (map (\ p -> rpmdir arch p ++ ".rpm") . lines) <$> cmd "rpmspec" ["-q", spec] - sudo "yum" $ ["-y", "localinstall"] ++ rpms + rpmInstall rpms installMissing :: String -> IO () installMissing pkg = do diff --git a/src/Commands/RpmBuild.hs b/src/Commands/RpmBuild.hs index e7b964d..bdc0091 100644 --- a/src/Commands/RpmBuild.hs +++ b/src/Commands/RpmBuild.hs @@ -24,7 +24,7 @@ import Dependencies (missingPackages) import PackageUtils (copyTarball, isScmDir, PackageData (..), packageName, packageVersion, rpmbuild, RpmStage (..)) import Setup (RpmFlags (..)) -import SysCmd (cmd, yumInstall, (+-+)) +import SysCmd (cmd, pkgInstall, (+-+)) --import Control.Exception (bracket) import Control.Monad (unless, void, when) @@ -62,7 +62,7 @@ rpmBuild pkgdata flags stage = do name = packageName pkg when (stage `elem` [Binary,BuildDep]) $ do missing <- missingPackages pkgDesc - yumInstall missing (stage == Binary) + pkgInstall missing (stage == Binary) unless (stage == BuildDep) $ do srcdir <- cmd "rpm" ["--eval", "%{_sourcedir}"] diff --git a/src/SysCmd.hs b/src/SysCmd.hs index 71a05c0..6214cb6 100644 --- a/src/SysCmd.hs +++ b/src/SysCmd.hs @@ -22,10 +22,11 @@ module SysCmd ( cmdBool, cmdQuiet, cmdSilent, + pkgInstall, + rpmInstall, trySystem, shell, sudo, - yumInstall, (+-+)) where import Control.Monad (unless, void, when) @@ -119,11 +120,20 @@ removeTrailingNewline str = s +-+ "" = s s +-+ t = s ++ " " ++ t -yumInstall :: [String] -> Bool -> IO () -yumInstall [] _ = return () -yumInstall pkgs hard = do +packageManager :: IO String +packageManager = do + havednf <- optionalProgram "dnf" + if havednf + then return "dnf" + else requireProgram "yum" >> return "yum" + +pkgInstall :: [String] -> Bool -> IO () +pkgInstall [] _ = return () +pkgInstall pkgs hard = do + pkginstaller <- packageManager putStrLn $ "Running repoquery" +-+ unwords pkgs - repopkgs <- lines <$> readProcess "repoquery" (["--qf", "%{name}"] ++ pkgs) [] + let (repoquery, arg) = if pkginstaller == "dnf" then ("dnf", ["repoquery"]) else ("repoquery", []) + repopkgs <- lines <$> readProcess repoquery (arg ++ ["--qf", "%{name}"] ++ pkgs) [] let missing = pkgs \\ repopkgs if not (null missing) && hard then error $ unwords missing +-+ "not available." @@ -141,13 +151,18 @@ yumInstall pkgs hard = do else do havesudo <- optionalProgram "sudo" return $ if havesudo then Just "sudo" else Nothing - requireProgram "yum" let args = map showPkg repopkgs - putStrLn $ "Running:" +-+ fromMaybe "" maybeSudo +-+ "yum install" +-+ unwords args + putStrLn $ "Running:" +-+ fromMaybe "" maybeSudo +-+ pkginstaller +-+ "install" +-+ unwords args let exec = if hard then cmd_ else trySystem fedora <- cmd "rpm" ["--eval", "%fedora"] let nogpgcheck = ["--nogpgcheck" | fedora `elem` ["21", "22"]] - exec (fromMaybe "yum" maybeSudo) $ maybe [] (const "yum") maybeSudo : "install" : args ++ nogpgcheck + exec (fromMaybe pkginstaller maybeSudo) $ maybe [] (const pkginstaller) maybeSudo : "install" : args ++ nogpgcheck showPkg :: String -> String showPkg p = if '(' `elem` p then show p else p + +rpmInstall :: [String] -> IO () +rpmInstall rpms = do + pkginstaller <- packageManager + let (inst, arg) = if pkginstaller == "dnf" then ("dnf", "install") else ("yum", "localinstall") + sudo inst $ ["-y", arg] ++ rpms