-- | Find a package manager on the server by testing if the command is available.
getPackageManager :: MonadCric m => m PackageManager
getPackageManager = getPackageManager'
    [ ("yum", Yum)
    , ("apt-get", APT)
    , ("rpm", RPM)
    , ("pkg_add", PkgAdd)
    ]
  where
    getPackageManager' :: MonadCric m => [(String, PackageManager)] -> m PackageManager
    getPackageManager' [] = return UnknownPackageManager
    getPackageManager' ((cmd,mgr):rest) = do
      test <- testCommand cmd
      if test
        then return mgr
        else getPackageManager' rest

-- | Install a package with the package manager found.
getPackageManager :: MonadCric m => m PackageManager
getPackageManager = getPackageManager'
    [ ("yum", Yum)
    , ("apt-get", APT)
    , ("rpm", RPM)
    , ("pkg_add", PkgAdd)
    ]
  where
    getPackageManager' :: MonadCric m => [(String, PackageManager)] -> m PackageManager
    getPackageManager' [] = return UnknownPackageManager
    getPackageManager' ((cmd,mgr):rest) = do
      test <- testCommand cmd
      if test
        then return mgr
        else getPackageManager' rest

-- | Install a package with the package manager found.
getPackageManager = getPackageManager'
    [ ("yum", Yum)
    , ("apt-get", APT)
    , ("rpm", RPM)
    , ("pkg_add", PkgAdd)
    ]
  where
    getPackageManager' :: MonadCric m => [(String, PackageManager)] -> m PackageManager
    getPackageManager' [] = return UnknownPackageManager
    getPackageManager' ((cmd,mgr):rest) = do
      test <- testCommand cmd
      if test
        then return mgr
        else getPackageManager' rest

-- | Install a package with the package manager found.