2018-03-31 06:07:46 +03:00
|
|
|
{-# LANGUAGE ExtendedDefaultRules #-}
|
2019-01-18 11:20:47 +03:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
2018-04-04 12:24:55 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2018-03-31 06:07:46 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
|
2018-04-04 12:24:55 +03:00
|
|
|
|
2018-12-24 02:02:54 +03:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import OurPrelude
|
|
|
|
|
|
|
|
import Control.Applicative ((<**>))
|
2018-03-31 06:07:46 +03:00
|
|
|
import qualified Data.Text as T
|
2018-07-11 05:30:34 +03:00
|
|
|
import qualified Data.Text.IO as T
|
2018-09-06 16:47:09 +03:00
|
|
|
import DeleteMerged (deleteDone)
|
2019-10-07 02:17:08 +03:00
|
|
|
import NVD (withVulnDB)
|
2019-09-08 02:48:10 +03:00
|
|
|
import qualified Nix
|
|
|
|
import qualified Options.Applicative as O
|
2019-03-21 08:27:20 +03:00
|
|
|
import System.Posix.Env (setEnv)
|
2019-10-13 00:37:34 +03:00
|
|
|
import Update (cveAll, cveReport, sourceGithubAll, updateAll)
|
2019-10-07 02:17:08 +03:00
|
|
|
import Utils (Options(..), UpdateEnv(..), setupNixpkgs)
|
2018-04-04 02:03:46 +03:00
|
|
|
|
2018-03-31 06:07:46 +03:00
|
|
|
default (T.Text)
|
|
|
|
|
2019-09-26 16:56:49 +03:00
|
|
|
newtype UpdateOptions =
|
2019-09-08 02:48:10 +03:00
|
|
|
UpdateOptions
|
|
|
|
{ dry :: Bool
|
2019-08-25 00:03:30 +03:00
|
|
|
}
|
2019-01-18 11:20:47 +03:00
|
|
|
|
2019-09-08 02:48:10 +03:00
|
|
|
data Command
|
|
|
|
= Update UpdateOptions
|
|
|
|
| DeleteDone
|
|
|
|
| Version
|
2019-09-08 02:53:01 +03:00
|
|
|
| UpdateVulnDB
|
2019-10-07 02:17:08 +03:00
|
|
|
| CheckAllVulnerable
|
2019-10-13 00:37:34 +03:00
|
|
|
| SourceGithub
|
2019-10-07 02:17:08 +03:00
|
|
|
| CheckVulnerable Text Text Text
|
2018-04-04 02:03:46 +03:00
|
|
|
|
2019-09-08 02:48:10 +03:00
|
|
|
updateOptionsParser :: O.Parser Command
|
|
|
|
updateOptionsParser =
|
2019-09-26 16:56:49 +03:00
|
|
|
Update . UpdateOptions <$>
|
2019-09-08 02:48:10 +03:00
|
|
|
O.switch
|
|
|
|
(O.long "dry-run" <>
|
|
|
|
O.help
|
2019-01-18 11:20:47 +03:00
|
|
|
"Do everything except actually pushing the updates to the remote repository")
|
|
|
|
|
2019-09-08 02:48:10 +03:00
|
|
|
commandParser :: O.Parser Command
|
|
|
|
commandParser =
|
|
|
|
O.hsubparser
|
2019-09-26 16:56:49 +03:00
|
|
|
(O.command
|
|
|
|
"update"
|
|
|
|
(O.info updateOptionsParser (O.progDesc "Update packages")) <>
|
|
|
|
O.command
|
|
|
|
"delete-done"
|
|
|
|
(O.info
|
|
|
|
(pure DeleteDone)
|
|
|
|
(O.progDesc "Deletes branches from PRs that were merged or closed")) <>
|
|
|
|
O.command
|
|
|
|
"version"
|
|
|
|
(O.info
|
|
|
|
(pure Version)
|
|
|
|
(O.progDesc
|
|
|
|
"Displays version information for nixpkgs-update and dependencies")) <>
|
|
|
|
O.command
|
|
|
|
"update-vulnerability-db"
|
|
|
|
(O.info
|
|
|
|
(pure UpdateVulnDB)
|
2019-10-07 00:16:35 +03:00
|
|
|
(O.progDesc "Updates the vulnerability database")) <>
|
|
|
|
O.command
|
|
|
|
"check-vulnerable"
|
2019-10-07 02:17:08 +03:00
|
|
|
(O.info checkVulnerable (O.progDesc "checks if something is vulnerable")) <>
|
|
|
|
O.command
|
|
|
|
"check-all-vulnerable"
|
|
|
|
(O.info
|
|
|
|
(pure CheckAllVulnerable)
|
2019-10-13 00:37:34 +03:00
|
|
|
(O.progDesc "checks all packages to update for vulnerabilities")) <>
|
|
|
|
O.command
|
|
|
|
"source-github"
|
|
|
|
(O.info (pure SourceGithub) (O.progDesc "looks for updates on GitHub")))
|
2019-10-07 00:16:35 +03:00
|
|
|
|
|
|
|
checkVulnerable :: O.Parser Command
|
|
|
|
checkVulnerable =
|
|
|
|
CheckVulnerable <$> O.strArgument (O.metavar "PRODUCT_ID") <*>
|
2019-10-07 02:17:08 +03:00
|
|
|
O.strArgument (O.metavar "OLD_VERSION") <*>
|
|
|
|
O.strArgument (O.metavar "NEW_VERSION")
|
2019-09-08 02:48:10 +03:00
|
|
|
|
|
|
|
programInfo :: O.ParserInfo Command
|
2018-04-06 18:17:22 +03:00
|
|
|
programInfo =
|
2019-09-08 02:48:10 +03:00
|
|
|
O.info
|
|
|
|
(commandParser <**> O.helper)
|
2019-10-07 00:16:35 +03:00
|
|
|
(O.fullDesc <>
|
|
|
|
O.progDesc "Update packages in the Nixpkgs repository" <>
|
2019-09-08 02:48:10 +03:00
|
|
|
O.header "nixpkgs-update")
|
2018-03-31 06:07:46 +03:00
|
|
|
|
2019-09-08 02:48:10 +03:00
|
|
|
getGithubToken :: IO Text
|
|
|
|
getGithubToken = T.strip <$> T.readFile "github_token.txt"
|
2018-03-31 06:07:46 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2018-07-11 05:30:34 +03:00
|
|
|
main = do
|
2019-09-08 02:48:10 +03:00
|
|
|
command <- O.execParser programInfo
|
|
|
|
case command of
|
|
|
|
DeleteDone -> do
|
|
|
|
token <- getGithubToken
|
|
|
|
setupNixpkgs token
|
|
|
|
setEnv "GITHUB_TOKEN" (T.unpack token) True
|
|
|
|
deleteDone token
|
2019-09-26 16:56:49 +03:00
|
|
|
Update UpdateOptions {dry} -> do
|
2019-09-08 02:48:10 +03:00
|
|
|
token <- getGithubToken
|
|
|
|
updates <- T.readFile "packages-to-update.txt"
|
|
|
|
setupNixpkgs token
|
|
|
|
setEnv "PAGER" "" True
|
|
|
|
setEnv "GITHUB_TOKEN" (T.unpack token) True
|
|
|
|
setEnv "GC_INITIAL_HEAP_SIZE" "10g" True
|
|
|
|
updateAll (Options dry token) updates
|
|
|
|
Version -> do
|
2019-09-26 16:56:49 +03:00
|
|
|
v <- runExceptT Nix.version
|
2019-09-08 02:48:10 +03:00
|
|
|
case v of
|
|
|
|
Left t -> T.putStrLn ("error:" <> t)
|
|
|
|
Right t -> T.putStrLn t
|
2019-10-01 13:49:24 +03:00
|
|
|
UpdateVulnDB -> withVulnDB $ \_conn -> pure ()
|
2019-10-07 02:17:08 +03:00
|
|
|
CheckAllVulnerable -> do
|
2019-10-28 17:41:45 +03:00
|
|
|
setupNixpkgs undefined
|
2019-10-07 02:17:08 +03:00
|
|
|
updates <- T.readFile "packages-to-update.txt"
|
|
|
|
cveAll (Options undefined undefined) updates
|
|
|
|
CheckVulnerable productID oldVersion newVersion -> do
|
2019-10-28 17:41:45 +03:00
|
|
|
setupNixpkgs undefined
|
2019-10-07 02:17:08 +03:00
|
|
|
report <-
|
|
|
|
cveReport
|
|
|
|
(UpdateEnv productID oldVersion newVersion (Options False undefined))
|
|
|
|
T.putStrLn report
|
2019-10-13 00:37:34 +03:00
|
|
|
SourceGithub -> do
|
|
|
|
token <- getGithubToken
|
|
|
|
updates <- T.readFile "packages-to-update.txt"
|
|
|
|
setupNixpkgs token
|
|
|
|
setEnv "GITHUB_TOKEN" (T.unpack token) True
|
|
|
|
sourceGithubAll (Options False token) updates
|