2012-09-26 20:50:04 +00:00
|
|
|
{- Assistant installation
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-09-26 20:50:04 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-09-26 20:50:04 +00:00
|
|
|
-}
|
|
|
|
|
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
|
2013-04-23 15:38:52 +00:00
|
|
|
import Config.Files
|
2012-09-26 21:19:45 +00:00
|
|
|
import Utility.FileMode
|
2013-02-13 18:30:04 +00:00
|
|
|
import Utility.Shell
|
2013-05-12 23:19:28 +00:00
|
|
|
import Utility.Tmp
|
2013-05-11 22:23:41 +00:00
|
|
|
import Utility.Env
|
2013-12-21 00:58:36 +00:00
|
|
|
import Utility.SshConfig
|
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
|
2013-12-15 21:10:24 +00:00
|
|
|
import Assistant.Install.Menu
|
2018-04-25 19:31:25 +00:00
|
|
|
import Utility.UserInfo
|
|
|
|
import Utility.Android
|
2012-09-28 23:18:08 +00:00
|
|
|
#endif
|
2012-09-26 20:50:04 +00:00
|
|
|
|
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
|
2014-04-20 22:38:59 +00:00
|
|
|
- daemon, as well as writing the programFile, and putting the
|
|
|
|
- git-annex-shell and git-annex-wrapper wrapper scripts 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.
|
2014-03-22 19:51:30 +00:00
|
|
|
-
|
2014-07-21 19:27:24 +00:00
|
|
|
- File manager hook script installation is done even for
|
|
|
|
- packaged apps, since it has to go into the user's home directory.
|
2012-09-26 20:50:04 +00:00
|
|
|
-}
|
|
|
|
ensureInstalled :: IO ()
|
2016-04-27 18:05:46 +00:00
|
|
|
ensureInstalled = ifM (isJust <$> getEnv "GIT_ANNEX_PACKAGE_INSTALL")
|
|
|
|
( go Nothing
|
|
|
|
, go =<< standaloneAppBase
|
|
|
|
)
|
2012-10-31 06:34:03 +00:00
|
|
|
where
|
2014-07-21 19:27:24 +00:00
|
|
|
go Nothing = installFileManagerHooks "git-annex"
|
2012-10-31 06:34:03 +00:00
|
|
|
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
|
2020-11-03 22:34:27 +00:00
|
|
|
createDirectoryIfMissing True $
|
|
|
|
fromRawFilePath (parentDir (toRawFilePath programfile))
|
2012-10-31 06:34:03 +00:00
|
|
|
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
|
2018-04-25 19:31:25 +00:00
|
|
|
installAutoStart program autostartfile
|
2012-09-28 23:08:13 +00:00
|
|
|
#else
|
2018-04-25 19:31:25 +00:00
|
|
|
ifM osAndroid
|
|
|
|
( do
|
|
|
|
-- Integration with the Termux:Boot app.
|
|
|
|
home <- myHomeDir
|
2018-04-25 21:51:50 +00:00
|
|
|
let bootfile = home </> ".termux" </> "boot" </> "git-annex"
|
2018-04-25 19:31:25 +00:00
|
|
|
unlessM (doesFileExist bootfile) $ do
|
|
|
|
createDirectoryIfMissing True (takeDirectory bootfile)
|
|
|
|
writeFile bootfile "git-annex assistant --autostart"
|
|
|
|
, do
|
|
|
|
menufile <- desktopMenuFilePath "git-annex" <$> userDataDir
|
|
|
|
icondir <- iconDir <$> userDataDir
|
|
|
|
installMenu program menufile base icondir
|
|
|
|
autostartfile <- autoStartPath "git-annex" <$> userConfigDir
|
|
|
|
installAutoStart program autostartfile
|
|
|
|
)
|
2012-09-28 23:08:13 +00:00
|
|
|
#endif
|
2012-09-26 20:50:04 +00:00
|
|
|
|
2012-10-31 06:34:03 +00:00
|
|
|
sshdir <- sshDir
|
2014-04-20 22:38:59 +00:00
|
|
|
let runshell var = "exec " ++ base </> "runshell " ++ var
|
|
|
|
let rungitannexshell var = runshell $ "git-annex-shell -c \"" ++ var ++ "\""
|
|
|
|
|
|
|
|
installWrapper (sshdir </> "git-annex-shell") $ unlines
|
2018-10-13 05:36:06 +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"
|
2014-04-20 22:38:59 +00:00
|
|
|
, rungitannexshell "$SSH_ORIGINAL_COMMAND"
|
2013-03-12 11:12:39 +00:00
|
|
|
, "else"
|
2014-04-20 22:38:59 +00:00
|
|
|
, rungitannexshell "$@"
|
2013-03-12 11:12:39 +00:00
|
|
|
, "fi"
|
2012-10-31 06:34:03 +00:00
|
|
|
]
|
2014-04-20 22:38:59 +00:00
|
|
|
installWrapper (sshdir </> "git-annex-wrapper") $ unlines
|
2018-10-13 05:36:06 +00:00
|
|
|
[ shebang
|
2014-04-20 22:38:59 +00:00
|
|
|
, "set -e"
|
|
|
|
, runshell "\"$@\""
|
|
|
|
]
|
2012-11-27 21:05:29 +00:00
|
|
|
|
2014-07-21 19:27:24 +00:00
|
|
|
installFileManagerHooks program
|
2014-03-22 19:51:30 +00:00
|
|
|
|
2014-04-20 22:38:59 +00:00
|
|
|
installWrapper :: FilePath -> String -> IO ()
|
|
|
|
installWrapper file content = do
|
|
|
|
curr <- catchDefaultIO "" $ readFileStrict file
|
|
|
|
when (curr /= content) $ do
|
2020-11-03 22:34:27 +00:00
|
|
|
createDirectoryIfMissing True (fromRawFilePath (parentDir (toRawFilePath file)))
|
2014-04-20 22:38:59 +00:00
|
|
|
viaTmp writeFile file content
|
2020-11-06 18:10:58 +00:00
|
|
|
modifyFileMode (toRawFilePath file) $
|
|
|
|
addModes [ownerExecuteMode]
|
2014-04-20 22:38:59 +00:00
|
|
|
|
2014-07-21 19:27:24 +00:00
|
|
|
installFileManagerHooks :: FilePath -> IO ()
|
2014-03-22 19:51:30 +00:00
|
|
|
#ifdef linux_HOST_OS
|
2018-04-25 21:47:49 +00:00
|
|
|
installFileManagerHooks program = unlessM osAndroid $ do
|
2014-11-14 18:55:21 +00:00
|
|
|
let actions = ["get", "drop", "undo"]
|
|
|
|
|
2014-07-21 19:27:24 +00:00
|
|
|
-- Gnome
|
|
|
|
nautilusScriptdir <- (\d -> d </> "nautilus" </> "scripts") <$> userDataDir
|
|
|
|
createDirectoryIfMissing True nautilusScriptdir
|
2014-11-14 18:55:21 +00:00
|
|
|
forM_ actions $
|
|
|
|
genNautilusScript nautilusScriptdir
|
2014-07-21 19:27:24 +00:00
|
|
|
|
|
|
|
-- KDE
|
2017-10-18 12:14:37 +00:00
|
|
|
userdata <- userDataDir
|
|
|
|
let kdeServiceMenusdir = userdata </> "kservices5" </> "ServiceMenus"
|
2014-07-21 19:27:24 +00:00
|
|
|
createDirectoryIfMissing True kdeServiceMenusdir
|
|
|
|
writeFile (kdeServiceMenusdir </> "git-annex.desktop")
|
2014-11-14 18:55:21 +00:00
|
|
|
(kdeDesktopFile actions)
|
2014-03-22 19:51:30 +00:00
|
|
|
where
|
2014-07-21 19:27:24 +00:00
|
|
|
genNautilusScript scriptdir action =
|
2014-03-22 19:51:30 +00:00
|
|
|
installscript (scriptdir </> scriptname action) $ unlines
|
2018-10-13 05:36:06 +00:00
|
|
|
[ shebang
|
2014-03-22 19:51:30 +00:00
|
|
|
, autoaddedcomment
|
2014-03-23 05:28:28 +00:00
|
|
|
, "exec " ++ program ++ " " ++ action ++ " --notify-start --notify-finish -- \"$@\""
|
2014-03-22 19:51:30 +00:00
|
|
|
]
|
|
|
|
scriptname action = "git-annex " ++ action
|
|
|
|
installscript f c = whenM (safetoinstallscript f) $ do
|
|
|
|
writeFile f c
|
2020-11-06 18:10:58 +00:00
|
|
|
modifyFileMode (toRawFilePath f) $ addModes [ownerExecuteMode]
|
2014-03-22 19:51:30 +00:00
|
|
|
safetoinstallscript f = catchDefaultIO True $
|
|
|
|
elem autoaddedcomment . lines <$> readFileStrict f
|
2014-07-21 19:27:24 +00:00
|
|
|
autoaddedcomment = "# " ++ autoaddedmsg ++ " (To disable, chmod 600 this file.)"
|
|
|
|
autoaddedmsg = "Automatically added by git-annex, do not edit."
|
|
|
|
|
|
|
|
kdeDesktopFile actions = unlines $ concat $
|
|
|
|
kdeDesktopHeader actions : map kdeDesktopAction actions
|
|
|
|
kdeDesktopHeader actions =
|
|
|
|
[ "# " ++ autoaddedmsg
|
|
|
|
, "[Desktop Entry]"
|
|
|
|
, "Type=Service"
|
|
|
|
, "ServiceTypes=all/allfiles"
|
|
|
|
, "MimeType=all/all;"
|
|
|
|
, "Actions=" ++ intercalate ";" (map kdeDesktopSection actions)
|
|
|
|
, "X-KDE-Priority=TopLevel"
|
|
|
|
, "X-KDE-Submenu=Git-Annex"
|
|
|
|
, "X-KDE-Icon=git-annex"
|
|
|
|
, "X-KDE-ServiceTypes=KonqPopupMenu/Plugin"
|
|
|
|
]
|
|
|
|
kdeDesktopSection command = "GitAnnex" ++ command
|
|
|
|
kdeDesktopAction command =
|
|
|
|
[ ""
|
|
|
|
, "[Desktop Action " ++ kdeDesktopSection command ++ "]"
|
|
|
|
, "Name=" ++ command
|
|
|
|
, "Icon=git-annex"
|
2014-07-21 19:30:40 +00:00
|
|
|
, unwords
|
2015-04-29 19:53:16 +00:00
|
|
|
[ "Exec=sh -c 'cd \"$(dirname \"$1\")\" &&"
|
2014-07-21 19:30:40 +00:00
|
|
|
, program
|
|
|
|
, command
|
2015-04-29 19:53:16 +00:00
|
|
|
, "--notify-start --notify-finish -- \"$1\"'"
|
|
|
|
, "false" -- this becomes $0 in sh, so unused
|
|
|
|
, "%f"
|
2014-07-21 19:30:40 +00:00
|
|
|
]
|
2014-07-21 19:27:24 +00:00
|
|
|
]
|
2014-03-22 19:51:30 +00:00
|
|
|
#else
|
2014-07-21 19:27:24 +00:00
|
|
|
installFileManagerHooks _ = noop
|
2014-03-22 19:51:30 +00:00
|
|
|
#endif
|
|
|
|
|
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
|
2014-06-10 23:20:14 +00:00
|
|
|
clean environ
|
2012-11-27 21:05:29 +00:00
|
|
|
| null vars = Nothing
|
2014-06-10 23:20:14 +00:00
|
|
|
| otherwise = Just $ catMaybes $ map (restoreorig environ) environ
|
2012-11-27 21:05:29 +00:00
|
|
|
| otherwise = Nothing
|
|
|
|
where
|
2012-11-28 02:57:04 +00:00
|
|
|
vars = words $ fromMaybe "" $
|
2014-06-10 23:20:14 +00:00
|
|
|
lookup "GIT_ANNEX_STANDLONE_ENV" environ
|
|
|
|
restoreorig oldenviron p@(k, _v)
|
|
|
|
| k `elem` vars = case lookup ("ORIG_" ++ k) oldenviron of
|
2013-12-31 18:55:55 +00:00
|
|
|
(Just v')
|
|
|
|
| not (null v') -> Just (k, v')
|
|
|
|
_ -> Nothing
|
2012-11-27 21:05:29 +00:00
|
|
|
| otherwise = Just p
|