enano-bundle.nsi
author Dan
Tue, 08 Dec 2009 02:25:33 -0500
changeset 6 6016fd9e848f
parent 5 85800cb04cc5
child 7 37824b18ff73
permissions -rwxr-xr-x
A couple minor fixes: more flexible version numbering; added a CreateDirectory before uninstaller generation (whoops)

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Enano CMS"
!ifndef PRODUCT_VERSION
!define PRODUCT_VERSION "1.1.6"
!endif
!define PRODUCT_PUBLISHER "Enano CMS Project"
!define PRODUCT_WEB_SITE "http://enanocms.org"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_SHORTNAME "enanocms"
; !define UNINSTALL_DEBUG

!ifndef ENANO_ROOT
!define ENANO_ROOT "Q:\enano-1.1\repo"
!endif

SetCompressor /FINAL /SOLID lzma
CRCCheck force

!include "WinMessages.nsh"

; ExperienceUI 1.3.1 compatible
!ifndef XPUI_SYSDIR
  !define XPUI_SYSDIR "P:\exui\Contrib\ExperienceUI"
!endif
!include "${XPUI_SYSDIR}\XPUI.nsh"

; ExperienceUI GUI parameters
!define XPUI_BGIMAGE
!define XPUI_BGIMAGE_BMP "gfx\enano-bg.bmp"
!define XPUI_TEXT_COLOR "F2F2F2"
!define XPUI_TEXT_BGCOLOR "202020" ; irrelevant but still
!define XPUI_TEXT_LIGHTCOLOR "B4C3EA"
!define XPUI_ABORTWARNING
!define XPUI_BRANDINGTEXT "NSIS Installer ${NSIS_VERSION}"
!define XPUI_BRANDINGTEXT_COLOR_FG "b6d9ff"
!define XPUI_BRANDINGTEXT_COLOR_BG "4c5b6b"
!define XPUI_FASTERSKINNING
!define XPUI_UNINSTALLER

Var wampstack_installed
Var wappstack_installed
Var stack_type
Var stack_instdir
Var stack_portbit
Var db_dbmsname
Var db_rootuser
Var db_rootpass
Var db_needroot
Var db_driver
Var db_port
Var db_user
Var db_password
Var db_name
Var enano_user
Var enano_password
Var admin_email
Var site_name
Var site_desc
Var site_copyright
Var url_scheme
Var start_with
Var skip_install

!include "inst-resources\bitnamiutils.nsh"
!include "inst-resources\dbal.nsh"
!include "inst-resources\mysql.nsh"
!include "inst-resources\postgresql.nsh"
!include "inst-resources\str_replace.nsh"
!include "inst-resources\kickstart.nsh"
!include "inst-resources\apacheconfig.nsh"
!include "inst-resources\applist.nsh"

;
; INSTALL PAGES
;

; Welcome page
${Page} Welcome2

; License page
${LicensePage} "licenses\GPL.txt"

; Stack selection - automatic unless both stacks are installed
!include "pages\StackSelect.nsi"

; Database credentials entry
!include "pages\DatabaseConfig.nsi"

; Site config page
!include "pages\SiteConfig.nsi"

; User credentials page
!include "pages\Login.nsi"

; Components page
${Page} Components

; Instfiles page
${Page} InstFiles

; Finish page
!define XPUI_FINISHPAGE_RUN
!define XPUI_FINISHPAGE_CHECKBOX_RUN "Go to my new $(^Name) website now"
!define XPUI_FINISHPAGE_RUN_FUNCTION OpenBitnamiWebsite
Function OpenBitnamiWebsite
  ExecShell open "http://localhost$stack_portbit/${PRODUCT_SHORTNAME}/"
FunctionEnd
${Page} Finish
${Page} Abort

;
; UNINSTALL PAGES
;

${UnPage} Welcome2
${UnPage} InstFiles
${UnPage} Finish

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; Language files
${Language} "English"

; MUI end ------

Name "${PRODUCT_NAME}"
Caption "${PRODUCT_NAME} ${PRODUCT_VERSION} Bitnami installer"
OutFile "enano-${PRODUCT_VERSION}-bitnami-setup.exe"
InstallDir "$PROGRAMFILES\Enano CMS"
ShowInstDetails show
ShowUnInstDetails show

; File lists
!include "inst-resources\core-files.nsh"
; End file lists

Section "-pre"
  StrCpy $INSTDIR "$stack_instdir"
  StrCpy $skip_install 0
  
  StrCmp $db_needroot 0 0 SkipManualCheck
    ; If we were given our own DB credentials and there's already a config, the installation needs to be skipped
    IfFileExists "$INSTDIR\apps\${PRODUCT_SHORTNAME}\htdocs\config.php" 0 SkipManualCheck
      StrCpy $skip_install 1
      Return
      
  SkipManualCheck:
  
  IfFileExists "$INSTDIR\apps\${PRODUCT_SHORTNAME}\htdocs\config.php" 0 +2
    Delete "$INSTDIR\apps\${PRODUCT_SHORTNAME}\htdocs\config.php"
SectionEnd

Section "-DatabaseSetup"
  StrCmp $db_needroot 1 +2
    Return
    
  ; Create database
  ${db_create} $R0 "$db_rootuser" "$db_rootpass" "$db_name" "$db_user" "$db_password"
  IntCmp $R0 0 DatabaseCreateSuccess
    !insertmacro XPUI_HEADER_TEXT "Installation failed" "Could not create the database."
    DetailPrint "Database creation failed."
    MessageBox MB_OK|MB_ICONEXCLAMATION "Setup failed to create the database for $(^Name).$\r$\n\
                                         $\r$\n\
                                         It's possible that your authentication details were rejected or that there \
                                         is a bug in the installer. Try removing any special characters (especially \
                                         quote symbols and backslashes) from your password. Make sure to use only \
                                         letters, numbers, and underscores in the database name and username."
    Abort
  DatabaseCreateSuccess:
SectionEnd

Section "Enano Core" SEC01
  SectionIn RO
  CreateDirectory "$INSTDIR\apps\${PRODUCT_SHORTNAME}"
  WriteUninstaller "$INSTDIR\apps\${PRODUCT_SHORTNAME}\uninstall.exe"
  !insertmacro Core_Install
SectionEnd

Section "Enable GMP in PHP" SecGMP
  ClearErrors
  IfFileExists "$stack_instdir\php\ext\php_gmp.dll" +3
  
    ; No GMP
    MessageBox MB_OK|MB_ICONEXCLAMATION "The stack you selected does not contain the GMP extension, so it cannot be enabled. Logins will be several seconds slower. Please consider upgrading your stack."
    Return
  
  WriteINIStr "$stack_instdir\php\php.ini" "GMP" "extension" "php_gmp.dll"
  IfErrors 0 +2
    MessageBox MB_OK|MB_ICONEXCLAMATION "GMP was not automatically enabled in PHP. Logins will be several seconds slower."
SectionEnd

Section "YubiKey auth plugin" SEC02
SectionEnd

Section "AjIM2" SEC03
SectionEnd

Section "Admin Alerts" SEC04
SectionEnd

Section "RSS Feeds" SEC06
SectionEnd

Section "News Portal" SEC08
SectionEnd

Section "Code syntax highlighting" SEC11
SectionEnd

Section "Wiki functionality extensions" SEC12
SectionEnd

Section -ConfigureApache
  DetailPrint "Configuring Apache web server"
  Call write_apache_config
  DetailPrint "Restarting Apache"
  nsExec::Exec '"$SYSDIR\net.exe" stop "$stack_typestackApache"'
  nsExec::Exec '"$SYSDIR\net.exe" start "$stack_typestackApache"'
  StrCmp $skip_install 1 0 +2
    Return
  
  Call enano_write_kickstart_script
  Call enano_run_kickstart_script
  
  SetOutPath "$INSTDIR\apps\${PRODUCT_SHORTNAME}\scripts"
  File "inst-resources\selfdestruct.php"
SectionEnd

Section -InsertApplistEntry
  ; Skip if this is WAPPStack, it doesn't have an applications.html. (!)
  StrCmp $stack_type "WAPP" 0 +2
    Return
  
  Call enano_add_to_applist
SectionEnd

Section -AdditionalIcons
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateDirectory "$SMPROGRAMS\Enano CMS"
  CreateShortCut "$SMPROGRAMS\Enano CMS\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\Enano CMS\Uninstall.lnk" "$INSTDIR\apps\${PRODUCT_SHORTNAME}\uninstall.exe"
SectionEnd

Section -Post
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\apps\${PRODUCT_SHORTNAME}\uninstall.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} "Core components of Enano CMS, necessary to run Enano"
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC02} "Adds support for Yubikey authentication"
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC03} "An AJAX chatbox sidebar gadget for Enano"
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC04} "Provides a sidebar block that alerts you about unapproved comments, inactive users, and pages with requested deletion."
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC06} "Provides the ability to generate RSS feeds based on the latest page edits and comments. It also has a plugin API so plugins can add their own feeds."
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC08} "Provides a portal with news and static content combined onto one page."
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC11} "Parser extension that adds syntax highlighting support using the GeSHi highlighting engine."
  !insertmacro MUI_DESCRIPTION_TEXT ${SEC12} "Adds several parser extensions that provide MediaWiki-like behavior, including references (footnotes) and Table of Contents support."
  !insertmacro MUI_DESCRIPTION_TEXT ${SecGMP} "Enables PHP's GMP extension, which speeds up cryptographic operations."
!insertmacro MUI_FUNCTION_DESCRIPTION_END

Function .onInit
  !ifdef UNINSTALL_DEBUG
    WriteUninstaller "$EXEDIR\uninstall.exe"
    MessageBox MB_OKCANCEL "Uninstaller written. OK to run installer, Cancel to quit" IDOK +2
      Abort
  !endif
  Call BNSetWAMPInstalledFlag
  Call BNSetWAPPInstalledFlag
  
  ; If neither WAMP nor WAPP is installed, die
  StrCmp $wampstack_installed 0 "" FoundStack
  StrCmp $wampstack_installed 0 "" FoundStack

    MessageBox MB_OK|MB_ICONEXCLAMATION "Setup could not find any BitNami stacks on your server.$\r$\n\
                                         $\r$\n\
                                         Please install a BitNami stack and re-run setup. You can download a BitNami stack for free from http://www.bitnami.org."
    Abort

  FoundStack:
FunctionEnd

Function un.onInit
  
  StrCpy $stack_instdir "$INSTDIR\..\.."
  ; this is probably a bad way to determine the stack type
  ClearErrors
  StrCpy $stack_type "wamp"
  ReadINIStr $0 "$stack_instdir\properties.ini" "MySQL" "mysql_port"
  IfErrors 0 +2
    StrCpy $stack_type "wapp"
    
FunctionEnd

Section Uninstall
  
  ; Confirm uninstall
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you really sure you want to uninstall ${PRODUCT_NAME}?$\r$\n\
                                                 $\r$\n\
                                                 Removing ${PRODUCT_NAME} will delete everything that it installed, including your database. If you do not want to \
                                                 lose data, cancel this uninstaller and back up your database before uninstalling.$\r$\n\
                                                 $\r$\n\
                                                 The ${PRODUCT_NAME} uninstaller also deletes any uploaded files, plugins and themes that you may have installed." IDYES +2
    Abort
  
  Delete "$INSTDIR\apps\${PRODUCT_SHORTNAME}\${PRODUCT_NAME}.url"

  ; Remove from Apache config
  DetailPrint "Removing ${PRODUCT_NAME} from Apache configuration"
  Call un.disable_in_apache_config
  
  ; Remove from applications.html
  ; SON OF A BITCH. BitNami, please, PLEASE make applications.html a PHP script that includes all files in a directory.
  DetailPrint "Removing ${PRODUCT_NAME} from applications.html"
  Call un.disable_in_applications_html
  
  ; Restart Apache
  DetailPrint "Restarting Apache"
  nsExec::Exec '"$SYSDIR\net.exe" stop "$stack_typestackApache"'
  nsExec::Exec '"$SYSDIR\net.exe" start "$stack_typestackApache"'
  
  DetailPrint "Uninstalling database"
  nsExec::ExecToLog '"$stack_instdir\php\php.exe" "$INSTDIR\scripts\selfdestruct.php"'
  
  DetailPrint "Deleting files..."
  SetDetailsPrint listonly
  !insertmacro Core_Uninstall
  SetDetailsPrint both

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  SetAutoClose true
SectionEnd

; Version Information

VIProductVersion "${PRODUCT_VERSION}.0"
VIAddVersionKey /LANG=1033 "ProductName" "Enano CMS"
VIAddVersionKey /LANG=1033 "Setup Information" "Enano CMS installer module for Windows Apache stacks"
VIAddVersionKey /LANG=1033 "Comments" "This installer contains a beta build of Enano CMS, use with caution!"
VIAddVersionKey /LANG=1033 "Publisher Name" "Neal Gompa (King InuYasha), Enano CMS Project"
VIAddVersionKey /LANG=1033 "LegalCopyright" "©2009 Enano CMS Project"
VIAddVersionKey /LANG=1033 "FileDescription" "Enano - The CMS that focuses on what matters most: content."
VIAddVersionKey /LANG=1033 "FileVersion" "${PRODUCT_VERSION}"