summaryrefslogtreecommitdiff
path: root/Build/InstallDesktopFile.hs
blob: ab2773bf1125b8e69805a0b34277a98d25e6a9f2 (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
{- 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 Control.Applicative
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 :: String -> 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