summaryrefslogtreecommitdiff
path: root/Command/EnableTor.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Command/EnableTor.hs')
-rw-r--r--Command/EnableTor.hs27
1 files changed, 14 insertions, 13 deletions
diff --git a/Command/EnableTor.hs b/Command/EnableTor.hs
index c581fa1d4..d24ecb2dc 100644
--- a/Command/EnableTor.hs
+++ b/Command/EnableTor.hs
@@ -8,27 +8,28 @@
module Command.EnableTor where
import Command
+import P2P.Address
import Utility.Tor
+import Annex.UUID
-- This runs as root, so avoid making any commits or initializing
--- git-annex, as that would create root-owned files.
+-- git-annex, or doing other things that create root-owned files.
cmd :: Command
cmd = noCommit $ dontCheck repoExists $
- command "enable-tor" SectionSetup ""
- "userid uuid" (withParams seek)
+ command "enable-tor" SectionSetup "enable tor hidden service"
+ "uid" (withParams seek)
seek :: CmdParams -> CommandSeek
seek = withWords start
-start :: CmdParams -> CommandStart
-start (suserid:uuid:[]) = case readish suserid of
- Nothing -> error "Bad userid"
+start :: [String] -> CommandStart
+start ps = case readish =<< headMaybe ps of
+ Nothing -> giveup "Bad params"
Just userid -> do
- (OnionAddress onionaddr, onionport) <- liftIO $
- addHiddenService userid uuid
- liftIO $ putStrLn $
- "tor-annex::" ++
- onionaddr ++ ":" ++
- show onionport ++ " "
+ uuid <- getUUID
+ when (uuid == NoUUID) $
+ giveup "This can only be run in a git-annex repository."
+ (onionaddr, onionport) <- liftIO $
+ addHiddenService userid (fromUUID uuid)
+ storeP2PAddress $ TorAnnex onionaddr onionport
stop
-start _ = error "Bad params"