2012-09-26 20:50:04 +00:00
|
|
|
{- Assistant installation
|
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2012-09-28 23:08:13 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2012-09-26 20:50:04 +00:00
|
|
|
module Assistant.Install where
|
|
|
|
|
2012-09-26 21:19:45 +00:00
|
|
|
import Assistant.Common
|
|
|
|
import Assistant.Install.AutoStart
|
|
|
|
import Assistant.Ssh
|
2012-09-26 20:50:04 +00:00
|
|
|
import Locations.UserConfig
|
2012-09-26 21:19:45 +00:00
|
|
|
import Utility.FileMode
|
2012-09-28 23:18:08 +00:00
|
|
|
|
|
|
|
#ifdef darwin_HOST_OS
|
2012-09-26 20:50:04 +00:00
|
|
|
import Utility.OSX
|
2012-09-28 23:18:08 +00:00
|
|
|
#else
|
|
|
|
import Utility.FreeDesktop
|
|
|
|
#endif
|
2012-09-26 20:50:04 +00:00
|
|
|
|
|
|
|
import System.Posix.Env
|
|
|
|
|
2012-09-28 23:08:13 +00:00
|
|
|
standaloneAppBase :: IO (Maybe FilePath)
|
|
|
|
standaloneAppBase = getEnv "GIT_ANNEX_APP_BASE"
|
2012-09-27 20:47:52 +00:00
|
|
|
|
2012-09-28 23:08:13 +00:00
|
|
|
{- The standalone app does not have an installation process.
|
2012-09-26 20:50:04 +00:00
|
|
|
- So when it's run, it needs to set up autostarting of the assistant
|
2012-09-26 21:19:45 +00:00
|
|
|
- daemon, as well as writing the programFile, and putting a
|
|
|
|
- git-annex-shell wrapper into ~/.ssh
|
2012-09-26 20:50:04 +00:00
|
|
|
-
|
|
|
|
- Note that this is done every time it's started, so if the user moves
|
|
|
|
- it around, the paths this sets up won't break.
|
|
|
|
-}
|
|
|
|
ensureInstalled :: IO ()
|
2012-09-28 23:08:13 +00:00
|
|
|
ensureInstalled = go =<< standaloneAppBase
|
2012-09-27 20:47:52 +00:00
|
|
|
where
|
|
|
|
go Nothing = noop
|
|
|
|
go (Just base) = do
|
2012-09-28 23:08:13 +00:00
|
|
|
let program = base ++ "runshell git-annex"
|
2012-09-26 20:50:04 +00:00
|
|
|
programfile <- programFile
|
|
|
|
createDirectoryIfMissing True (parentDir programfile)
|
|
|
|
writeFile programfile program
|
|
|
|
|
2012-09-28 23:08:13 +00:00
|
|
|
#ifdef darwin_HOST_OS
|
|
|
|
autostartfile <- userAutoStart osxAutoStartLabel
|
|
|
|
#else
|
|
|
|
autostartfile <- autoStartPath "git-annex"
|
|
|
|
<$> userConfigDir
|
|
|
|
#endif
|
2012-09-26 20:50:04 +00:00
|
|
|
installAutoStart program autostartfile
|
|
|
|
|
2012-09-26 21:19:45 +00:00
|
|
|
{- This shim is only updated if it doesn't
|
|
|
|
- already exist with the right content. This
|
|
|
|
- ensures that there's no race where it would have
|
|
|
|
- worked, but is unavailable due to being updated. -}
|
|
|
|
sshdir <- sshDir
|
|
|
|
let shim = sshdir </> "git-annex-shell"
|
|
|
|
let content = unlines
|
|
|
|
[ "#!/bin/sh"
|
|
|
|
, "set -e"
|
2012-09-26 22:59:18 +00:00
|
|
|
, "exec", base </> "runshell" ++
|
|
|
|
" git-annex-shell -c \"$SSH_ORIGINAL_COMMAND\""
|
2012-09-26 21:19:45 +00:00
|
|
|
]
|
2012-09-28 23:08:13 +00:00
|
|
|
curr <- catchDefaultIO "" $ readFileStrict shim
|
2012-09-26 21:19:45 +00:00
|
|
|
when (curr /= content) $ do
|
|
|
|
createDirectoryIfMissing True (parentDir shim)
|
|
|
|
writeFile shim content
|
|
|
|
modifyFileMode shim $ addModes [ownerExecuteMode]
|