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
|
2013-02-13 18:30:04 +00:00
|
|
|
import Utility.Shell
|
2013-03-12 11:12:39 +00:00
|
|
|
import Utility.TempFile
|
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-10-31 06:34:03 +00:00
|
|
|
where
|
|
|
|
go Nothing = noop
|
|
|
|
go (Just base) = do
|
2012-11-28 20:17:13 +00:00
|
|
|
let program = base </> "git-annex"
|
2012-10-31 06:34:03 +00:00
|
|
|
programfile <- programFile
|
|
|
|
createDirectoryIfMissing True (parentDir programfile)
|
|
|
|
writeFile programfile program
|
2012-09-26 20:50:04 +00:00
|
|
|
|
2012-09-28 23:08:13 +00:00
|
|
|
#ifdef darwin_HOST_OS
|
2012-10-31 06:34:03 +00:00
|
|
|
autostartfile <- userAutoStart osxAutoStartLabel
|
2012-09-28 23:08:13 +00:00
|
|
|
#else
|
2012-10-31 06:34:03 +00:00
|
|
|
autostartfile <- autoStartPath "git-annex" <$> userConfigDir
|
2012-09-28 23:08:13 +00:00
|
|
|
#endif
|
2012-10-31 06:34:03 +00:00
|
|
|
installAutoStart program autostartfile
|
2012-09-26 20:50:04 +00:00
|
|
|
|
2012-10-31 06:34:03 +00:00
|
|
|
{- This shim is only updated if it doesn't
|
2013-03-12 11:12:39 +00:00
|
|
|
- already exist with the right content. -}
|
2012-10-31 06:34:03 +00:00
|
|
|
sshdir <- sshDir
|
|
|
|
let shim = sshdir </> "git-annex-shell"
|
2013-03-12 11:12:39 +00:00
|
|
|
let runshell var = "exec " ++ base </> "runshell" ++
|
|
|
|
" git-annex-shell -c \"" ++ var ++ "\""
|
2012-10-31 06:34:03 +00:00
|
|
|
let content = unlines
|
2013-02-13 18:30:04 +00:00
|
|
|
[ shebang
|
2012-10-31 06:34:03 +00:00
|
|
|
, "set -e"
|
2013-03-12 11:12:39 +00:00
|
|
|
, "if [ \"x$SSH_ORIGINAL_COMMAND\" != \"x\" ]; then"
|
|
|
|
, runshell "$SSH_ORIGINAL_COMMAND"
|
|
|
|
, "else"
|
|
|
|
, runshell "$@"
|
|
|
|
, "fi"
|
2012-10-31 06:34:03 +00:00
|
|
|
]
|
2013-03-12 11:12:39 +00:00
|
|
|
|
2012-10-31 06:34:03 +00:00
|
|
|
curr <- catchDefaultIO "" $ readFileStrict shim
|
|
|
|
when (curr /= content) $ do
|
|
|
|
createDirectoryIfMissing True (parentDir shim)
|
2013-03-12 11:12:39 +00:00
|
|
|
viaTmp writeFile shim content
|
2012-10-31 06:34:03 +00:00
|
|
|
modifyFileMode shim $ addModes [ownerExecuteMode]
|
2012-11-27 21:05:29 +00:00
|
|
|
|
|
|
|
{- Returns a cleaned up environment that lacks settings used to make the
|
|
|
|
- standalone builds use their bundled libraries and programs.
|
|
|
|
- Useful when calling programs not included in the standalone builds.
|
|
|
|
-
|
|
|
|
- For a non-standalone build, returns Nothing.
|
|
|
|
-}
|
|
|
|
cleanEnvironment :: IO (Maybe [(String, String)])
|
|
|
|
cleanEnvironment = clean <$> getEnvironment
|
|
|
|
where
|
|
|
|
clean env
|
|
|
|
| null vars = Nothing
|
|
|
|
| otherwise = Just $ catMaybes $ map (restoreorig env) env
|
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
2012-11-28 02:57:04 +00:00
|
|
|
vars = words $ fromMaybe "" $
|
|
|
|
lookup "GIT_ANNEX_STANDLONE_ENV" env
|
|
|
|
restoreorig oldenv p@(k, _v)
|
|
|
|
| k `elem` vars = case lookup ("ORIG_" ++ k) oldenv of
|
|
|
|
Nothing -> Nothing
|
|
|
|
(Just v') -> Just (k, v')
|
2012-11-27 21:05:29 +00:00
|
|
|
| otherwise = Just p
|