2013-07-09 23:56:30 +00:00
|
|
|
{- Generating and installing a desktop menu entry file and icon,
|
2024-04-06 13:50:58 +00:00
|
|
|
- and a desktop autostart file. (And OSX equivalents.)
|
2013-04-17 16:02:44 +00:00
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2013-04-17 16:02:44 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-04-17 16:02:44 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
2015-05-10 20:38:49 +00:00
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
2013-04-17 16:02:44 +00:00
|
|
|
|
|
|
|
module Build.DesktopFile where
|
|
|
|
|
|
|
|
import Utility.Exception
|
|
|
|
import Utility.FreeDesktop
|
|
|
|
import Utility.Path
|
|
|
|
import Utility.Monad
|
2023-03-01 19:55:58 +00:00
|
|
|
import Utility.SystemDirectory
|
2020-10-28 18:53:25 +00:00
|
|
|
import Utility.FileSystemEncoding
|
2013-04-24 14:48:06 +00:00
|
|
|
import Config.Files
|
2013-04-17 16:02:44 +00:00
|
|
|
import Utility.OSX
|
|
|
|
import Assistant.Install.AutoStart
|
2013-04-20 23:35:33 +00:00
|
|
|
import Assistant.Install.Menu
|
2013-04-17 16:02:44 +00:00
|
|
|
|
|
|
|
import System.Environment
|
2019-08-08 16:18:53 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2023-08-01 19:17:43 +00:00
|
|
|
import System.Posix.User
|
2013-04-17 16:02:44 +00:00
|
|
|
import Data.Maybe
|
2016-01-14 14:18:37 +00:00
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
2019-08-08 16:18:53 +00:00
|
|
|
#endif
|
2013-04-17 16:02:44 +00:00
|
|
|
|
|
|
|
systemwideInstall :: IO Bool
|
2013-05-10 21:57:21 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2019-03-18 16:33:56 +00:00
|
|
|
systemwideInstall = isroot <||> (not <$> userdirset)
|
2013-04-17 16:02:44 +00:00
|
|
|
where
|
|
|
|
isroot = do
|
|
|
|
uid <- fromIntegral <$> getRealUserID
|
|
|
|
return $ uid == (0 :: Int)
|
2019-03-18 16:33:56 +00:00
|
|
|
userdirset = isJust <$> catchMaybeIO (getEnv "USERDIR")
|
2013-05-10 20:08:53 +00:00
|
|
|
#else
|
|
|
|
systemwideInstall = return False
|
|
|
|
#endif
|
2013-04-17 16:02:44 +00:00
|
|
|
|
|
|
|
inDestDir :: FilePath -> IO FilePath
|
|
|
|
inDestDir f = do
|
|
|
|
destdir <- catchDefaultIO "" (getEnv "DESTDIR")
|
|
|
|
return $ destdir ++ "/" ++ f
|
|
|
|
|
|
|
|
writeFDODesktop :: FilePath -> IO ()
|
|
|
|
writeFDODesktop command = do
|
2013-07-09 23:56:30 +00:00
|
|
|
systemwide <- systemwideInstall
|
|
|
|
|
|
|
|
datadir <- if systemwide then return systemDataDir else userDataDir
|
2013-07-10 00:50:41 +00:00
|
|
|
menufile <- inDestDir (desktopMenuFilePath "git-annex" datadir)
|
|
|
|
icondir <- inDestDir (iconDir datadir)
|
|
|
|
installMenu command menufile "doc" icondir
|
2013-07-09 23:56:30 +00:00
|
|
|
|
|
|
|
configdir <- if systemwide then return systemConfigDir else userConfigDir
|
2013-04-17 16:02:44 +00:00
|
|
|
installAutoStart command
|
|
|
|
=<< inDestDir (autoStartPath "git-annex" configdir)
|
|
|
|
|
|
|
|
writeOSXDesktop :: FilePath -> IO ()
|
|
|
|
writeOSXDesktop command = do
|
|
|
|
installAutoStart command =<< inDestDir =<< ifM systemwideInstall
|
|
|
|
( return $ systemAutoStart osxAutoStartLabel
|
|
|
|
, userAutoStart osxAutoStartLabel
|
|
|
|
)
|
|
|
|
|
|
|
|
install :: FilePath -> IO ()
|
|
|
|
install command = do
|
|
|
|
#ifdef darwin_HOST_OS
|
|
|
|
writeOSXDesktop command
|
|
|
|
#else
|
|
|
|
writeFDODesktop command
|
|
|
|
#endif
|
|
|
|
ifM systemwideInstall
|
|
|
|
( return ()
|
|
|
|
, do
|
|
|
|
programfile <- inDestDir =<< programFile
|
2020-10-28 18:53:25 +00:00
|
|
|
createDirectoryIfMissing True (fromRawFilePath (parentDir (toRawFilePath programfile)))
|
2013-04-17 16:02:44 +00:00
|
|
|
writeFile programfile command
|
|
|
|
)
|
2015-11-03 14:38:08 +00:00
|
|
|
|
|
|
|
installUser :: FilePath -> IO ()
|
|
|
|
installUser command = ifM systemwideInstall
|
2015-11-03 14:51:21 +00:00
|
|
|
( return ()
|
|
|
|
, install command
|
2015-11-03 14:38:08 +00:00
|
|
|
)
|