summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Assistant/MakeRemote.hs25
-rw-r--r--Command/EnableRemote.hs56
-rw-r--r--Command/InitRemote.hs52
-rw-r--r--GitAnnex.hs2
-rw-r--r--debian/changelog3
-rw-r--r--doc/encryption.mdwn4
-rw-r--r--doc/git-annex.mdwn37
-rw-r--r--doc/special_remotes/S3.mdwn2
-rw-r--r--doc/special_remotes/bup.mdwn2
-rw-r--r--doc/special_remotes/directory.mdwn2
-rw-r--r--doc/special_remotes/glacier.mdwn2
-rw-r--r--doc/special_remotes/hook.mdwn2
-rw-r--r--doc/special_remotes/rsync.mdwn4
-rw-r--r--doc/special_remotes/webdav.mdwn2
14 files changed, 142 insertions, 53 deletions
diff --git a/Assistant/MakeRemote.hs b/Assistant/MakeRemote.hs
index 33ca0b2c0..2ef35a7b9 100644
--- a/Assistant/MakeRemote.hs
+++ b/Assistant/MakeRemote.hs
@@ -69,17 +69,22 @@ makeRsyncRemote name location = makeRemote name location $
, ("type", "rsync")
]
-{- Inits a special remote. Currently, only 'weak' ciphers can be
- - generated from the assistant, because otherwise GnuPG may block once
- - the entropy pool is drained, and as of now there's no way to tell the
- - user to perform IO actions to refill the pool. -}
+{- Inits a new special remote, or enables an existing one.
+ -
+ - Currently, only 'weak' ciphers can be generated from the assistant,
+ - because otherwise GnuPG may block once the entropy pool is drained,
+ - and as of now there's no way to tell the user to perform IO actions
+ - to refill the pool. -}
makeSpecialRemote :: String -> RemoteType -> R.RemoteConfig -> Annex ()
-makeSpecialRemote name remotetype config = do
- (u, c) <- Command.InitRemote.findByName name
- c' <- R.setup remotetype u $
- M.insert "highRandomQuality" "false" $ M.union config c
- describeUUID u name
- configSet u c'
+makeSpecialRemote name remotetype config =
+ go =<< Command.InitRemote.findExisting name
+ where
+ go Nothing = go =<< Just <$> Command.InitRemote.generateNew name
+ go (Just (u, c)) = do
+ c' <- R.setup remotetype u $
+ M.insert "highRandomQuality" "false" $ M.union config c
+ describeUUID u name
+ configSet u c'
{- Returns the name of the git remote it created. If there's already a
- remote at the location, returns its name. -}
diff --git a/Command/EnableRemote.hs b/Command/EnableRemote.hs
new file mode 100644
index 000000000..ea606c284
--- /dev/null
+++ b/Command/EnableRemote.hs
@@ -0,0 +1,56 @@
+{- git-annex command
+ -
+ - Copyright 2013 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Command.EnableRemote where
+
+import Common.Annex
+import Command
+import qualified Logs.Remote
+import qualified Types.Remote as R
+import qualified Command.InitRemote as InitRemote
+
+import qualified Data.Map as M
+
+def :: [Command]
+def = [command "enableremote"
+ (paramPair paramName $ paramOptional $ paramRepeating paramKeyValue)
+ seek SectionSetup "enables use of an existing special remote"]
+
+seek :: [CommandSeek]
+seek = [withWords start]
+
+start :: [String] -> CommandStart
+start [] = unknownNameError "Specify the name of the special remote to enable."
+start (name:ws) = go =<< InitRemote.findExisting name
+ where
+ config = Logs.Remote.keyValToConfig ws
+
+ go Nothing = unknownNameError "Unknown special remote name."
+ go (Just (u, c)) = do
+ let fullconfig = config `M.union` c
+ t <- InitRemote.findType fullconfig
+
+ showStart "enableremote" name
+ next $ perform t u fullconfig
+
+unknownNameError :: String -> Annex a
+unknownNameError prefix = do
+ names <- InitRemote.remoteNames
+ error $ prefix ++
+ if null names
+ then ""
+ else " Known special remotes: " ++ intercalate " " names
+
+perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
+perform t u c = do
+ c' <- R.setup t u c
+ next $ cleanup u c'
+
+cleanup :: UUID -> R.RemoteConfig -> CommandCleanup
+cleanup u c = do
+ Logs.Remote.configSet u c
+ return True
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs
index 948b6ef63..684a2cc91 100644
--- a/Command/InitRemote.hs
+++ b/Command/InitRemote.hs
@@ -1,6 +1,6 @@
{- git-annex command
-
- - Copyright 2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2011,2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -23,26 +23,23 @@ import Data.Ord
def :: [Command]
def = [command "initremote"
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue)
- seek SectionSetup "sets up a special (non-git) remote"]
+ seek SectionSetup "creates a special (non-git) remote"]
seek :: [CommandSeek]
seek = [withWords start]
start :: [String] -> CommandStart
-start [] = do
- names <- remoteNames
- error $ "Specify a name for the remote. " ++
- if null names
- then ""
- else "Either a new name, or one of these existing special remotes: " ++ intercalate " " names
-start (name:ws) = do
- (u, c) <- findByName name
- let fullconfig = config `M.union` c
- t <- findType fullconfig
-
- showStart "initremote" name
- next $ perform t u name $ M.union config c
-
+start [] = error "Specify a name for the remote."
+start (name:ws) = ifM (isJust <$> findExisting name)
+ ( error $ "There is already a special remote named \"" ++ name ++
+ "\". (Use enableremote to enable an existing special remote.)"
+ , do
+ (u, c) <- generateNew name
+ t <- findType config
+
+ showStart "initremote" name
+ next $ perform t u name $ M.union config c
+ )
where
config = Logs.Remote.keyValToConfig ws
@@ -57,21 +54,22 @@ cleanup u name c = do
Logs.Remote.configSet u c
return True
-{- Look up existing remote's UUID and config by name, or generate a new one -}
-findByName :: String -> Annex (UUID, R.RemoteConfig)
-findByName name = do
+{- See if there's an existing special remote with this name. -}
+findExisting :: String -> Annex (Maybe (UUID, R.RemoteConfig))
+findExisting name = do
t <- trustMap
matches <- sortBy (comparing $ \(u, _c) -> M.lookup u t )
- . findByName' name
+ . findByName name
<$> Logs.Remote.readRemoteLog
- maybe generate return $ headMaybe matches
- where
- generate = do
- uuid <- liftIO genUUID
- return (uuid, M.insert nameKey name M.empty)
+ return $ headMaybe matches
+
+generateNew :: String -> Annex (UUID, R.RemoteConfig)
+generateNew name = do
+ uuid <- liftIO genUUID
+ return (uuid, M.singleton nameKey name)
-findByName' :: String -> M.Map UUID R.RemoteConfig -> [(UUID, R.RemoteConfig)]
-findByName' n = filter (matching . snd) . M.toList
+findByName :: String -> M.Map UUID R.RemoteConfig -> [(UUID, R.RemoteConfig)]
+findByName n = filter (matching . snd) . M.toList
where
matching c = case M.lookup nameKey c of
Nothing -> False
diff --git a/GitAnnex.hs b/GitAnnex.hs
index 7dbaca3b5..211d79ef3 100644
--- a/GitAnnex.hs
+++ b/GitAnnex.hs
@@ -30,6 +30,7 @@ import qualified Command.Fix
import qualified Command.Init
import qualified Command.Describe
import qualified Command.InitRemote
+import qualified Command.EnableRemote
import qualified Command.Fsck
import qualified Command.Unused
import qualified Command.DropUnused
@@ -91,6 +92,7 @@ cmds = concat
, Command.Init.def
, Command.Describe.def
, Command.InitRemote.def
+ , Command.EnableRemote.def
, Command.Reinject.def
, Command.Unannex.def
, Command.Uninit.def
diff --git a/debian/changelog b/debian/changelog
index 4dde2760b..07a70fdc9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -40,6 +40,9 @@ git-annex (4.20130418) UNRELEASED; urgency=low
its edit page.
* Automatically register public urls for files uploaded to the
Internet Archive.
+ * To enable an existing special remote, the new enableremote command
+ must be used. The initremote command now is used only to create
+ new special remotes.
-- Joey Hess <joeyh@debian.org> Thu, 18 Apr 2013 16:22:48 -0400
diff --git a/doc/encryption.mdwn b/doc/encryption.mdwn
index 5349e8c7a..d93bee9d2 100644
--- a/doc/encryption.mdwn
+++ b/doc/encryption.mdwn
@@ -31,10 +31,10 @@ non-empty remote.
The [[encryption_design|design/encryption]] allows additional encryption keys
to be added on to a special remote later. Once a key is added, it is able
to access content that has already been stored in the special remote.
-To add a new key, just run `git annex initremote` again, specifying the
+To add a new key, just run `git annex enableremote` specifying the
new encryption key:
- git annex initremote myremote encryption=788A3F4C
+ git annex enableremote myremote encryption=788A3F4C
Note that once a key has been given access to a remote, it's not
possible to revoke that access, short of deleting the remote. See
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 05ca4474a..8cab00ac8 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -236,15 +236,40 @@ subdirectories).
* initremote name [param=value ...]
- Sets up a special remote. The remote's
- configuration is specified by the parameters. If a remote
- with the specified name has already been configured, its configuration
- is modified by any values specified. In either case, the remote will be
- added to `.git/config`.
+ Creates a new special remote, and adds it to `.git/config`.
+
+ The remote's configuration is specified by the parameters. Different
+ types of special remotes need different configuration values. The
+ command will prompt for parameters as needed.
+
+ All special remotes support encryption. You must either specify
+ encryption=none to disable encryption, or use encryption=keyid
+ (or encryption=emailaddress) to specify a gpg key that can access
+ the encrypted special remote.
Example Amazon S3 remote:
- initremote mys3 type=S3 encryption=none datacenter=EU
+ git annex initremote mys3 type=S3 encryption=me@example.com datacenter=EU
+
+* enableremote name [param=value ...]
+
+ Enables use of an existing special remote in the current repository,
+ which may be a different repository than the one in which it was
+ originally created with the initremote command.
+
+ The name of the remote is the same name used when origianlly
+ creating that remote with "initremote". Run "git annex enableremote"
+ with no parameters to get a list of special remote names.
+
+ Some special remotes may need parameters to be specified every time.
+ For example, the directory special remote requires a directory= parameter.
+
+ This command can also be used to modify the configuration of an existing
+ special remote, by specifying new values for parameters that were originally
+ set when using initremote. For example, to add a new gpg key to the keys
+ that can access an encrypted remote:
+
+ git annex initremote mys3 encryption=friend@example.com
* trust [repository ...]
diff --git a/doc/special_remotes/S3.mdwn b/doc/special_remotes/S3.mdwn
index 5a7ecc25b..e15361f3e 100644
--- a/doc/special_remotes/S3.mdwn
+++ b/doc/special_remotes/S3.mdwn
@@ -21,7 +21,7 @@ the S3 remote.
every clone of the repository to access the encrypted data (use with caution).
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `embedcreds` - Optional. Set to "yes" embed the login credentials inside
the git repository, which allows other clones to also access them. This is
diff --git a/doc/special_remotes/bup.mdwn b/doc/special_remotes/bup.mdwn
index ec444912c..f323237b1 100644
--- a/doc/special_remotes/bup.mdwn
+++ b/doc/special_remotes/bup.mdwn
@@ -26,7 +26,7 @@ These parameters can be passed to `git annex initremote` to configure bup:
every clone of the repository to access the encrypted data (use with caution).
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `buprepo` - Required. This is passed to `bup` as the `--remote`
to use to store data. To create the repository,`bup init` will be run.
diff --git a/doc/special_remotes/directory.mdwn b/doc/special_remotes/directory.mdwn
index 7fdfdfca0..d23c1ae26 100644
--- a/doc/special_remotes/directory.mdwn
+++ b/doc/special_remotes/directory.mdwn
@@ -16,7 +16,7 @@ remote:
every clone of the repository to decrypt the encrypted data.
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `chunksize` - Avoid storing files larger than the specified size in the
directory. For use on directories on mount points that have file size
diff --git a/doc/special_remotes/glacier.mdwn b/doc/special_remotes/glacier.mdwn
index 79c3c38b1..d6dbad59a 100644
--- a/doc/special_remotes/glacier.mdwn
+++ b/doc/special_remotes/glacier.mdwn
@@ -27,7 +27,7 @@ the Glacier remote.
every clone of the repository to access the encrypted data (use with caution).
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `embedcreds` - Optional. Set to "yes" embed the login credentials inside
the git repository, which allows other clones to also access them. This is
diff --git a/doc/special_remotes/hook.mdwn b/doc/special_remotes/hook.mdwn
index 6867edb8f..d17fae4c8 100644
--- a/doc/special_remotes/hook.mdwn
+++ b/doc/special_remotes/hook.mdwn
@@ -31,7 +31,7 @@ These parameters can be passed to `git annex initremote`:
every clone of the repository to access the encrypted data.
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `hooktype` - Required. This specifies a collection of hooks to use for
this remote.
diff --git a/doc/special_remotes/rsync.mdwn b/doc/special_remotes/rsync.mdwn
index f98c80a83..641faf474 100644
--- a/doc/special_remotes/rsync.mdwn
+++ b/doc/special_remotes/rsync.mdwn
@@ -21,7 +21,7 @@ These parameters can be passed to `git annex initremote` to configure rsync:
every clone of the repository to decrypt the encrypted data.
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `rsyncurl` - Required. This is the url or `hostname:/directory` to
pass to rsync to tell it where to store content.
@@ -31,7 +31,7 @@ These parameters can be passed to `git annex initremote` to configure rsync:
setups, but not with some hosting providers that do not expose rsynced
filenames to the shell. You'll know you need this option if `git annex get`
from the special remote fails with an error message containing a single
- quote (`'`) character. If that happens, you can re-run initremote
+ quote (`'`) character. If that happens, you can run enableremote
setting shellescape=no.
The `annex-rsync-options` git configuration setting can be used to pass
diff --git a/doc/special_remotes/webdav.mdwn b/doc/special_remotes/webdav.mdwn
index 570b6f949..383fddf75 100644
--- a/doc/special_remotes/webdav.mdwn
+++ b/doc/special_remotes/webdav.mdwn
@@ -16,7 +16,7 @@ the webdav remote.
every clone of the repository to access the encrypted data (use with caution).
Note that additional gpg keys can be given access to a remote by
- rerunning initremote with the new key id. See [[encryption]].
+ running enableremote with the new key id. See [[encryption]].
* `embedcreds` - Optional. Set to "yes" embed the login credentials inside
the git repository, which allows other clones to also access them. This is