2011-03-16 15:48:26 -04:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2020-03-09 16:47:57 -04:00
|
|
|
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
|
2011-03-16 15:48:26 -04:00
|
|
|
-
|
2019-03-13 15:48:14 -04:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-03-16 15:48:26 -04:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Upgrade where
|
|
|
|
|
|
|
|
import Command
|
2011-03-19 18:58:10 -04:00
|
|
|
import Upgrade
|
2016-03-31 17:20:43 -04:00
|
|
|
import Annex.Version
|
|
|
|
import Annex.Init
|
2011-03-16 15:48:26 -04:00
|
|
|
|
2015-07-08 12:33:27 -04:00
|
|
|
cmd :: Command
|
2020-05-11 08:40:13 +02:00
|
|
|
cmd = dontCheck
|
|
|
|
-- because an old version may not seem to exist
|
2019-09-01 13:29:55 -04:00
|
|
|
-- and also, this avoids automatic silent upgrades before
|
|
|
|
-- this command can start up.
|
2020-05-11 08:40:13 +02:00
|
|
|
repoExists $
|
|
|
|
-- avoid upgrading repo out from under daemon
|
2019-09-01 13:29:55 -04:00
|
|
|
noDaemonRunning $
|
2023-05-10 12:41:43 -04:00
|
|
|
withAnnexOptions [jsonOptions] $
|
2019-09-01 13:29:55 -04:00
|
|
|
command "upgrade" SectionMaintenance "upgrade repository"
|
2020-03-09 16:47:57 -04:00
|
|
|
paramNothing (seek <$$> optParser)
|
2011-03-16 15:48:26 -04:00
|
|
|
|
2020-03-09 16:47:57 -04:00
|
|
|
data UpgradeOptions = UpgradeOptions
|
|
|
|
{ autoOnly :: Bool
|
|
|
|
}
|
2011-03-16 15:48:26 -04:00
|
|
|
|
2020-03-09 16:47:57 -04:00
|
|
|
optParser :: CmdParamsDesc -> Parser UpgradeOptions
|
|
|
|
optParser _ = UpgradeOptions
|
|
|
|
<$> switch
|
|
|
|
( long "autoonly"
|
|
|
|
<> help "only do automatic upgrades"
|
|
|
|
)
|
|
|
|
|
|
|
|
seek :: UpgradeOptions -> CommandSeek
|
|
|
|
seek o = commandAction (start o)
|
|
|
|
|
|
|
|
start :: UpgradeOptions -> CommandStart
|
2020-10-19 11:14:01 -04:00
|
|
|
start (UpgradeOptions { autoOnly = True }) =
|
2020-09-14 16:49:33 -04:00
|
|
|
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
|
2020-10-19 11:14:01 -04:00
|
|
|
getVersion >>= maybe noop checkUpgrade
|
|
|
|
next $ return True
|
|
|
|
start _ =
|
|
|
|
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
|
|
|
|
whenM (isNothing <$> getVersion) $ do
|
2022-11-18 13:58:35 -04:00
|
|
|
initialize Nothing Nothing
|
2020-10-19 11:14:01 -04:00
|
|
|
r <- upgrade False latestVersion
|
|
|
|
next $ return r
|