Skip to content

Commit

Permalink
use dnf to install when available
Browse files Browse the repository at this point in the history
dnf is installed by default in Fedora 21 and will be default package
manager in Fedora 22.  Maybe a config would be better but
have to uninstall dnf if one prefers to still use yum.

Note repoquery still be to changed to use dnf too.

- yumInstall renamed to pkgInstall
- rpmInstall for localinstall
  • Loading branch information
juhp committed Feb 10, 2015
1 parent 7710be5 commit d23d083
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Commands/Depends.hs
Expand Up @@ -5,7 +5,7 @@
-- Maintainer : Jens Petersen <petersen@fedoraproject.org>
-- 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
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/Install.hs
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/RpmBuild.hs
Expand Up @@ -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)
Expand Down Expand Up @@ -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}"]
Expand Down
31 changes: 23 additions & 8 deletions src/SysCmd.hs
Expand Up @@ -22,10 +22,11 @@ module SysCmd (
cmdBool,
cmdQuiet,
cmdSilent,
pkgInstall,
rpmInstall,
trySystem,
shell,
sudo,
yumInstall,
(+-+)) where

import Control.Monad (unless, void, when)
Expand Down Expand Up @@ -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."
Expand All @@ -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

0 comments on commit d23d083

Please sign in to comment.