git-annex/Build/NullSoftInstaller.hs

135 lines
3.9 KiB
Haskell
Raw Normal View History

2013-05-14 17:01:45 -05:00
{- Generates a NullSoft installer program for git-annex on Windows.
-
2013-05-14 19:59:14 -05:00
- To build the installer, git-annex should already be built by cabal,
- and ssh and rsync, as well as cygwin libraries, already installed.
2013-05-14 17:15:02 -04:00
-
- This uses the Haskell nsis package (cabal install nsis)
- to generate a .nsi file, which is then used to produce
- git-annex-installer.exe
-
- The installer includes git-annex, and utilities it uses, with the
- exception of git. The user needs to install git separately,
- and the installer checks for that.
-
- Copyright 2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
2013-05-14 17:01:45 -05:00
-}
{-# LANGUAGE OverloadedStrings #-}
import Development.NSIS
2013-05-14 19:59:14 -05:00
import System.FilePath
import Control.Monad
import System.Directory
import Data.String
2013-05-14 17:01:45 -05:00
2013-05-14 19:59:14 -05:00
import Utility.Tmp
import Utility.CopyFile
import Utility.SafeCommand
import Build.BundledPrograms
main = do
withTmpDir "nsis-build" $ \tmpdir -> do
2013-05-16 20:41:20 -04:00
let gitannex = tmpdir </> gitannexprogram
2013-05-14 19:59:14 -05:00
mustSucceed "ln" [File "dist/build/git-annex/git-annex.exe", File gitannex]
2013-05-16 20:41:20 -04:00
let license = tmpdir </> licensefile
2013-05-16 20:04:05 -04:00
mustSucceed "sh" [Param "-c", Param $ "zcat standalone/licences.gz > '" ++ license ++ "'"]
2013-05-16 20:00:31 -04:00
writeFile nsifile $ makeInstaller gitannex license
2013-05-14 19:59:14 -05:00
mustSucceed "C:\\Program Files\\NSIS\\makensis" [File nsifile]
removeFile nsifile -- left behind if makensis fails
where
nsifile = "git-annex.nsi"
mustSucceed cmd params = do
r <- boolSystem cmd params
case r of
True -> return ()
2013-05-16 20:04:05 -04:00
False -> error $ cmd ++ " failed"
2013-05-14 19:59:14 -05:00
2013-05-16 20:41:20 -04:00
gitannexprogram :: FilePath
gitannexprogram = "git-annex.exe"
licensefile :: FilePath
licensefile = "git-annex-licenses.txt"
2013-05-14 19:59:14 -05:00
installer :: FilePath
installer = "git-annex-installer.exe"
2013-05-16 20:41:20 -04:00
uninstaller :: FilePath
uninstaller = "git-annex-uninstall.exe"
2013-05-14 19:59:14 -05:00
gitInstallDir :: Exp FilePath
gitInstallDir = fromString "$PROGRAMFILES\\Git\\cmd"
needGit :: Exp String
needGit = strConcat
[ fromString "You need git installed to use git-annex. Looking at "
, gitInstallDir
, fromString " , it seems to not be installed, "
, fromString "or may be installed in another location. "
, fromString "You can install git from http:////git-scm.com//"
]
2013-05-16 20:00:31 -04:00
makeInstaller :: FilePath -> FilePath -> String
makeInstaller gitannex license = nsis $ do
2013-05-14 17:01:45 -05:00
name "git-annex"
2013-05-14 19:59:14 -05:00
outFile $ str installer
{- Installing into the same directory as git avoids needing to modify
- path myself, since the git installer already does it. -}
installDir gitInstallDir
2013-05-14 17:01:45 -05:00
requestExecutionLevel User
2013-05-14 19:59:14 -05:00
iff (fileExists gitInstallDir)
(return ())
(alert needGit)
2013-05-14 17:01:45 -05:00
-- Pages to display
page Directory -- Pick where to install
2013-05-16 20:32:59 -04:00
page (License license)
2013-05-14 17:01:45 -05:00
page InstFiles -- Give a progress bar while installing
-- Groups of files to install
section "programs" [] $ do
setOutPath "$INSTDIR"
2013-05-14 19:59:14 -05:00
addfile gitannex
2013-05-16 20:00:31 -04:00
addfile license
2013-05-14 19:59:14 -05:00
mapM_ addcygfile cygwinPrograms
2013-05-16 20:41:20 -04:00
writeUninstaller $ str uninstaller
2013-05-16 20:00:31 -04:00
section "libraries" [] $ do
2013-05-14 17:15:02 -04:00
setOutPath "$INSTDIR"
2013-05-14 19:59:14 -05:00
mapM_ addcygfile cygwinDlls
2013-05-16 20:32:59 -04:00
uninstall $
2013-05-16 20:41:20 -04:00
mapM_ (\f -> delete [RebootOK] $ fromString $ "$INSTDIR/" ++ f) $
[ gitannexprogram
, licensefile
, uninstaller
2013-05-16 20:32:59 -04:00
] ++ cygwinPrograms ++ cygwinDlls
2013-05-14 17:01:45 -05:00
where
2013-05-14 19:59:14 -05:00
addfile f = file [] (str f)
addcygfile f = addfile $ "C:\\cygwin\\bin" </> f
cygwinPrograms :: [FilePath]
cygwinPrograms = map (\p -> p ++ ".exe") bundledPrograms
-- These are the dlls needed by Cygwin's rsync, ssh, etc.
cygwinDlls :: [FilePath]
cygwinDlls =
[ "cygwin1.dll"
, "cygasn1-8.dll"
, "cygheimbase-1.dll"
, "cygroken-18.dll"
, "cygcom_err-2.dll"
, "cygheimntlm-0.dll"
, "cygsqlite3-0.dll"
, "cygcrypt-0.dll"
, "cyghx509-5.dll"
, "cygssp-0.dll"
, "cygcrypto-1.0.0.dll"
, "cygiconv-2.dll"
, "cyggcc_s-1.dll"
, "cygintl-8.dll"
, "cygwind-0.dll"
, "cyggssapi-3.dll"
, "cygkrb5-26.dll"
, "cygz.dll"
]