summaryrefslogtreecommitdiff
path: root/Build/InstallDesktopFile.hs
blob: 3bcaecf9a78fb56223e6419d4a7edbbcb90d6acf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{- Generating and installing a desktop menu entry file
 - and a desktop autostart file.
 -
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Build.InstallDesktopFile where

import Utility.Exception
import Utility.FreeDesktop
import Utility.Path
import Locations.UserConfig

import Control.Applicative
import Control.Monad
import System.Directory
import System.Environment
import System.Posix.User

{- The command can be either just "git-annex", or the full path to use
 - to run it. -}
desktop :: FilePath -> DesktopEntry
desktop command = genDesktopEntry
	"Git Annex"
	"Track and sync the files in your Git Annex"
	False
	(command ++ " webapp")
	["Network", "FileTransfer"]

autostart :: FilePath -> DesktopEntry
autostart command = genDesktopEntry
	"Git Annex Assistant"
	"Autostart"
	False
	(command ++ " assistant --autostart")
	[]

writeDesktop :: FilePath -> IO ()
writeDesktop command = do
	destdir <- catchDefaultIO (getEnv "DESTDIR") ""
	uid <- fromIntegral <$> getRealUserID

	datadir <- if uid /= 0 then userDataDir else return systemDataDir
	writeDesktopMenuFile (desktop command) $
		desktopMenuFilePath "git-annex" datadir

	configdir <- if uid /= 0 then userConfigDir else return systemConfigDir
	writeDesktopMenuFile (autostart command) $
		autoStartPath "git-annex" configdir

	when (uid /= 0) $ do
		programfile <- programFile
		createDirectoryIfMissing True (parentDir programfile)
		writeFile programfile command

main = getArgs >>= go
	where
		go [] = error "specify git-annex command"
		go (command:_) = writeDesktop command