feat: remote action

This commit is contained in:
Mahdi Dibaiee
2017-03-05 15:49:09 +03:30
parent 48c1208dc7
commit 3a2e331d1a
12 changed files with 254 additions and 2 deletions

View File

@ -30,6 +30,8 @@ module System.Serverman.Actions.Install (installService, package, dependencies)
package VsFTPd _ = "vsftpd"
package SSHFs _ = "sshfs"
installService :: Service -> OS -> IO ()
installService service os = do
forM_ (dependencies service) (`installService` os)

View File

@ -0,0 +1,38 @@
module System.Serverman.Actions.Remote ( runRemotely
, Address) where
import System.Serverman.Utils
import Data.List
import System.Directory
import System.IO
import System.FilePath
type Host = String
type Port = String
type User = String
data Address = Address Host Port User
runRemotely :: Address -> IO r -> IO ()
runRemotely addr@(Address host port user) action = do
let path = "/tmp/serverman/" </> show addr
createDirectoryIfMissing True path
execute "sshfs" [show addr, path] "" True
return ()
instance Read Address where
readsPrec _ addr
| '@' `elem` addr =
let (user, rest) = span (== '@') addr
(host, port) = readHostPort rest
in [(Address host port user, [])]
| otherwise =
let (host, port) = readHostPort addr
in [(Address host port "", [])]
where
readHostPort str = span (== ':') str
instance Show Address where
show (Address host port user) = user ++ "@" ++ host ++ ":" ++ port