postgresql提供了安装文件(exe)和压缩包文件(zip),有时我们希望在安装完成后针对某些软件做一些数据库的初始化操作。所以有必要制作一个自己的postgresql安装包。以下说一下nsis制作postgresql的注意事项。
1 官方下载postgresql压缩包(zip),而非exe安装包
2 下载nsis,nsis edit,ZIPDLL(用来解压zip)
其它用代码直接说明。
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "xtuple380"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "seahouse"
!define PRODUCT_WEB_SITE "http://www.cppblog.com/seahouse/"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "ZipDLL.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "F:\xtuple\src\xtuple380\xtuple\guiclient\xTuple.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "F:\infor\Dropbox\Dropbox\xTuple\docs\licence.txt"
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "SimpChinese"
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "xtuple-setup.exe"
InstallDir "$PROGRAMFILES\xtuple380"
ShowInstDetails show
ShowUnInstDetails show
Section "postgresql9.0.7" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "..\develop\postgresql-9.0.7-1-windows-binaries.zip"
File "F:\infor\Dropbox\Dropbox\xTuple\docs\installpackage\initdb.bat"
File "F:\infor\Dropbox\Dropbox\xTuple\docs\installpackage\pw.txt"
File "F:\infor\Dropbox\Dropbox\xTuple\docs\installpackage\uninstall.bat"
File "F:\infor\Dropbox\Dropbox\xTuple\docs\installpackage\userinit.bat"
File "F:\infor\Dropbox\Dropbox\xTuple\docs\installpackage\userinit.txt"
; ZipDLL::extractall "..\develop\postgresql-9.0.7-1-windows-binaries.zip" "c:\output"
; Use ZipDLL plugin
!insertmacro ZIPDLL_EXTRACT "$INSTDIR\postgresql-9.0.7-1-windows-binaries.zip" "$INSTDIR" "<ALL>"
Delete "$INSTDIR\postgresql-9.0.7-1-windows-binaries.zip"
; Set System env
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$0;$INSTDIR\pgsql\bin"
; refresh env
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR::Environment"
; init db by command line
; nsExec::ExecToLog 'cmd.exe pgsql\bin\initdb.exe -D pgsql\data -E UTF-8 --locale=chs -U postgres -W'
; nsExec::ExecToLog 'cmd.exe /c "$INSTDIR\pgsql\bin\httpd.exe" -D "$INSTDIR\pgsql\data" -E UTF-8 --locale=chs -U postgres -W'
; ExecWait 'commandpromt pgsql\bin\initdb.exe -D pgsql\data -E UTF-8 --locale=chs -U postgres -W'
ExecWait 'initdb.bat'
; ReadEnvStr $R0 COMSPEC
; nsExec::Exec 'commandpromt "$INSTDIR\pgsql\bin\initdb.exe" -D "$INSTDIR\pgsql\data" -E UTF-8 --locale=chs -U postgres -W'
; init user role and restore database from qucikstart
ExecWait 'userinit.bat'
SectionEnd
Section "xtuple380" SEC02
File "..\..\xTuple-3.8.0-Windows-release.zip"
; Use ZipDLL plugin
!insertmacro ZIPDLL_EXTRACT "$INSTDIR\xTuple-3.8.0-Windows-release.zip" "$INSTDIR" "<ALL>"
Delete "$INSTDIR\xTuple-3.8.0-Windows-release.zip"
; Set System env
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$0;$INSTDIR\xTuple-3.8.0-Windows-release"
; refresh env
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR::Environment"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateDirectory "$SMPROGRAMS\xtuple380"
CreateShortCut "$SMPROGRAMS\xtuple380\xtuple.lnk" "$INSTDIR\xTuple-3.8.0-Windows-release\xtuple.exe"
CreateShortCut "$SMPROGRAMS\xtuple380\pgAdmin3.lnk" "$INSTDIR\pgsql\bin\pgAdmin3.exe"
CreateShortCut "$SMPROGRAMS\xtuple380\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\xtuple380\Uninstall.lnk" "$INSTDIR\uninst.exe"
; desktop shortcut
CreateShortCut "$desktop\xtuple.lnk" "$INSTDIR\xTuple-3.8.0-Windows-release\xtuple.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SEC01} "数据库服务组件。"
!insertmacro MUI_DESCRIPTION_TEXT ${SEC02} "客户端软件。"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FunctionEnd
Section Uninstall
; etc uninstall system service
ExecWait 'uninstall.bat'
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$SMPROGRAMS\xtuple380\xtuple.lnk"
Delete "$SMPROGRAMS\xtuple380\pgAdmin3.lnk"
Delete "$SMPROGRAMS\xtuple380\Uninstall.lnk"
Delete "$SMPROGRAMS\xtuple380\Website.lnk"
Delete "$desktop\xtuple.lnk"
RMDir "$SMPROGRAMS\xtuple380"
RMDir /r "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd