1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/installer/windows/nsis/maintenanceservice_installer.nsi Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,288 @@ 1.4 +# This Source Code Form is subject to the terms of the Mozilla Public 1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +; Set verbosity to 3 (e.g. no script) to lessen the noise in the build logs 1.9 +!verbose 3 1.10 + 1.11 +; 7-Zip provides better compression than the lzma from NSIS so we add the files 1.12 +; uncompressed and use 7-Zip to create a SFX archive of it 1.13 +SetDatablockOptimize on 1.14 +SetCompress off 1.15 +CRCCheck on 1.16 + 1.17 +RequestExecutionLevel admin 1.18 + 1.19 +; The commands inside this ifdef require NSIS 3.0a2 or greater so the ifdef can 1.20 +; be removed after we require NSIS 3.0a2 or greater. 1.21 +!ifdef NSIS_PACKEDVERSION 1.22 + Unicode true 1.23 + ManifestSupportedOS all 1.24 + ManifestDPIAware true 1.25 +!endif 1.26 + 1.27 +!addplugindir ./ 1.28 + 1.29 +; Variables 1.30 +Var TempMaintServiceName 1.31 +Var BrandFullNameDA 1.32 +Var BrandFullName 1.33 + 1.34 +; Other included files may depend upon these includes! 1.35 +; The following includes are provided by NSIS. 1.36 +!include FileFunc.nsh 1.37 +!include LogicLib.nsh 1.38 +!include MUI.nsh 1.39 +!include WinMessages.nsh 1.40 +!include WinVer.nsh 1.41 +!include WordFunc.nsh 1.42 + 1.43 +!insertmacro GetOptions 1.44 +!insertmacro GetParameters 1.45 +!insertmacro GetSize 1.46 + 1.47 +; The test slaves use this fallback key to run tests. 1.48 +; And anyone that wants to run tests themselves should already have 1.49 +; this installed. 1.50 +!define FallbackKey \ 1.51 + "SOFTWARE\Mozilla\MaintenanceService\3932ecacee736d366d6436db0f55bce4" 1.52 + 1.53 +!define CompanyName "Mozilla Corporation" 1.54 +!define BrandFullNameInternal "" 1.55 + 1.56 +; The following includes are custom. 1.57 +!include defines.nsi 1.58 +; We keep defines.nsi defined so that we get other things like 1.59 +; the version number, but we redefine BrandFullName 1.60 +!define MaintFullName "Mozilla Maintenance Service" 1.61 +!undef BrandFullName 1.62 +!define BrandFullName "${MaintFullName}" 1.63 + 1.64 +!include common.nsh 1.65 +!include locales.nsi 1.66 + 1.67 +VIAddVersionKey "FileDescription" "${MaintFullName} Installer" 1.68 +VIAddVersionKey "OriginalFilename" "maintenanceservice_installer.exe" 1.69 + 1.70 +Name "${MaintFullName}" 1.71 +OutFile "maintenanceservice_installer.exe" 1.72 + 1.73 +; Get installation folder from registry if available 1.74 +InstallDirRegKey HKLM "Software\Mozilla\MaintenanceService" "" 1.75 + 1.76 +SetOverwrite on 1.77 + 1.78 +!define MaintUninstallKey \ 1.79 + "Software\Microsoft\Windows\CurrentVersion\Uninstall\MozillaMaintenanceService" 1.80 + 1.81 +; The HAVE_64BIT_OS define also means that we have an x64 build, 1.82 +; not just an x64 OS. 1.83 +!ifdef HAVE_64BIT_OS 1.84 + ; See below, we actually abort the install for x64 builds currently. 1.85 + InstallDir "$PROGRAMFILES64\${MaintFullName}\" 1.86 +!else 1.87 + InstallDir "$PROGRAMFILES32\${MaintFullName}\" 1.88 +!endif 1.89 +ShowUnInstDetails nevershow 1.90 + 1.91 +################################################################################ 1.92 +# Modern User Interface - MUI 1.93 + 1.94 +!define MUI_ICON setup.ico 1.95 +!define MUI_UNICON setup.ico 1.96 +!define MUI_WELCOMEPAGE_TITLE_3LINES 1.97 +!define MUI_UNWELCOMEFINISHPAGE_BITMAP wizWatermark.bmp 1.98 + 1.99 +;Interface Settings 1.100 +!define MUI_ABORTWARNING 1.101 + 1.102 +; Uninstaller Pages 1.103 +!insertmacro MUI_UNPAGE_CONFIRM 1.104 +!insertmacro MUI_UNPAGE_INSTFILES 1.105 + 1.106 +################################################################################ 1.107 +# Language 1.108 + 1.109 +!insertmacro MOZ_MUI_LANGUAGE 'baseLocale' 1.110 +!verbose push 1.111 +!verbose 3 1.112 +!include "overrideLocale.nsh" 1.113 +!include "customLocale.nsh" 1.114 +!verbose pop 1.115 + 1.116 +; Set this after the locale files to override it if it is in the locale 1.117 +; using " " for BrandingText will hide the "Nullsoft Install System..." branding 1.118 +BrandingText " " 1.119 + 1.120 +Function .onInit 1.121 + ; Remove the current exe directory from the search order. 1.122 + ; This only effects LoadLibrary calls and not implicitly loaded DLLs. 1.123 + System::Call 'kernel32::SetDllDirectoryW(w "")' 1.124 + 1.125 + SetSilent silent 1.126 + 1.127 +!ifdef HAVE_64BIT_OS 1.128 + ; We plan to eventually enable 64bit native builds to use the maintenance 1.129 + ; service, but for the initial release, to reduce testing and development, 1.130 + ; 64-bit builds will not install the maintenanceservice. 1.131 + Abort 1.132 +!endif 1.133 + 1.134 + ; On Windows 2000 we do not install the maintenance service. 1.135 + ; We won't run this installer from the parent installer, but just in case 1.136 + ; someone tries to execute it on Windows 2000... 1.137 + ${Unless} ${AtLeastWinXP} 1.138 + Abort 1.139 + ${EndUnless} 1.140 +FunctionEnd 1.141 + 1.142 +Function un.onInit 1.143 + ; Remove the current exe directory from the search order. 1.144 + ; This only effects LoadLibrary calls and not implicitly loaded DLLs. 1.145 + System::Call 'kernel32::SetDllDirectoryW(w "")' 1.146 + 1.147 +; The commands inside this ifndef are needed prior to NSIS 3.0a2 and can be 1.148 +; removed after we require NSIS 3.0a2 or greater. 1.149 +!ifndef NSIS_PACKEDVERSION 1.150 + ${If} ${AtLeastWinVista} 1.151 + System::Call 'user32::SetProcessDPIAware()' 1.152 + ${EndIf} 1.153 +!endif 1.154 + 1.155 + StrCpy $BrandFullNameDA "${MaintFullName}" 1.156 + StrCpy $BrandFullName "${MaintFullName}" 1.157 +FunctionEnd 1.158 + 1.159 +Section "MaintenanceService" 1.160 + AllowSkipFiles off 1.161 + 1.162 + CreateDirectory $INSTDIR 1.163 + SetOutPath $INSTDIR 1.164 + 1.165 + ; If the service already exists, then it will be stopped when upgrading it 1.166 + ; via the maintenanceservice_tmp.exe command executed below. 1.167 + ; The maintenanceservice_tmp.exe command will rename the file to 1.168 + ; maintenanceservice.exe if maintenanceservice_tmp.exe is newer. 1.169 + ; If the service does not exist yet, we install it and drop the file on 1.170 + ; disk as maintenanceservice.exe directly. 1.171 + StrCpy $TempMaintServiceName "maintenanceservice.exe" 1.172 + IfFileExists "$INSTDIR\maintenanceservice.exe" 0 skipAlreadyExists 1.173 + StrCpy $TempMaintServiceName "maintenanceservice_tmp.exe" 1.174 + skipAlreadyExists: 1.175 + 1.176 + ; We always write out a copy and then decide whether to install it or 1.177 + ; not via calling its 'install' cmdline which works by version comparison. 1.178 + CopyFiles "$EXEDIR\maintenanceservice.exe" "$INSTDIR\$TempMaintServiceName" 1.179 + 1.180 + ; The updater.ini file is only used when performing an install or upgrade, 1.181 + ; and only if that install or upgrade is successful. If an old updater.ini 1.182 + ; happened to be copied into the maintenance service installation directory 1.183 + ; but the service was not newer, the updater.ini file would be unused. 1.184 + ; It is used to fill the description of the service on success. 1.185 + CopyFiles "$EXEDIR\updater.ini" "$INSTDIR\updater.ini" 1.186 + 1.187 + ; Install the application maintenance service. 1.188 + ; If a service already exists, the command line parameter will stop the 1.189 + ; service and only install itself if it is newer than the already installed 1.190 + ; service. If successful it will remove the old maintenanceservice.exe 1.191 + ; and replace it with maintenanceservice_tmp.exe. 1.192 + ClearErrors 1.193 + ${GetParameters} $0 1.194 + ${GetOptions} "$0" "/Upgrade" $0 1.195 + ${If} ${Errors} 1.196 + nsExec::Exec '"$INSTDIR\$TempMaintServiceName" install' 1.197 + ${Else} 1.198 + ; The upgrade cmdline is the same as install except 1.199 + ; It will fail if the service isn't already installed. 1.200 + nsExec::Exec '"$INSTDIR\$TempMaintServiceName" upgrade' 1.201 + ${EndIf} 1.202 + 1.203 + WriteUninstaller "$INSTDIR\Uninstall.exe" 1.204 + WriteRegStr HKLM "${MaintUninstallKey}" "DisplayName" "${MaintFullName}" 1.205 + WriteRegStr HKLM "${MaintUninstallKey}" "UninstallString" \ 1.206 + '"$INSTDIR\uninstall.exe"' 1.207 + WriteRegStr HKLM "${MaintUninstallKey}" "DisplayIcon" \ 1.208 + "$INSTDIR\Uninstall.exe,0" 1.209 + WriteRegStr HKLM "${MaintUninstallKey}" "DisplayVersion" "${AppVersion}" 1.210 + WriteRegStr HKLM "${MaintUninstallKey}" "Publisher" "Mozilla" 1.211 + WriteRegStr HKLM "${MaintUninstallKey}" "Comments" \ 1.212 + "${BrandFullName} ${AppVersion} (${ARCH} ${AB_CD})" 1.213 + WriteRegDWORD HKLM "${MaintUninstallKey}" "NoModify" 1 1.214 + ${GetSize} "$INSTDIR" "/S=0K" $R2 $R3 $R4 1.215 + WriteRegDWORD HKLM "${MaintUninstallKey}" "EstimatedSize" $R2 1.216 + 1.217 + ; Write out that a maintenance service was attempted. 1.218 + ; We do this because on upgrades we will check this value and we only 1.219 + ; want to install once on the first upgrade to maintenance service. 1.220 + ; Also write out that we are currently installed, preferences will check 1.221 + ; this value to determine if we should show the service update pref. 1.222 + ; Since the Maintenance service can be installed either x86 or x64, 1.223 + ; always use the 64-bit registry for checking if an attempt was made. 1.224 + ${If} ${RunningX64} 1.225 + SetRegView 64 1.226 + ${EndIf} 1.227 + WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Attempted" 1 1.228 + WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Installed" 1 1.229 + DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "FFPrefetchDisabled" 1.230 + 1.231 + ; Included here for debug purposes only. 1.232 + ; These keys are used to bypass the installation dir is a valid installation 1.233 + ; check from the service so that tests can be run. 1.234 + ; WriteRegStr HKLM "${FallbackKey}\0" "name" "Mozilla Corporation" 1.235 + ; WriteRegStr HKLM "${FallbackKey}\0" "issuer" "DigiCert Assured ID Code Signing CA-1" 1.236 + ${If} ${RunningX64} 1.237 + SetRegView lastused 1.238 + ${EndIf} 1.239 +SectionEnd 1.240 + 1.241 +; By renaming before deleting we improve things slightly in case 1.242 +; there is a file in use error. In this case a new install can happen. 1.243 +Function un.RenameDelete 1.244 + Pop $9 1.245 + ; If the .moz-delete file already exists previously, delete it 1.246 + ; If it doesn't exist, the call is ignored. 1.247 + ; We don't need to pass /REBOOTOK here since it was already marked that way 1.248 + ; if it exists. 1.249 + Delete "$9.moz-delete" 1.250 + Rename "$9" "$9.moz-delete" 1.251 + ${If} ${Errors} 1.252 + Delete /REBOOTOK "$9" 1.253 + ${Else} 1.254 + Delete /REBOOTOK "$9.moz-delete" 1.255 + ${EndIf} 1.256 + ClearErrors 1.257 +FunctionEnd 1.258 + 1.259 +Section "Uninstall" 1.260 + ; Delete the service so that no updates will be attempted 1.261 + nsExec::Exec '"$INSTDIR\maintenanceservice.exe" uninstall' 1.262 + 1.263 + Push "$INSTDIR\updater.ini" 1.264 + Call un.RenameDelete 1.265 + Push "$INSTDIR\maintenanceservice.exe" 1.266 + Call un.RenameDelete 1.267 + Push "$INSTDIR\maintenanceservice_tmp.exe" 1.268 + Call un.RenameDelete 1.269 + Push "$INSTDIR\maintenanceservice.old" 1.270 + Call un.RenameDelete 1.271 + Push "$INSTDIR\Uninstall.exe" 1.272 + Call un.RenameDelete 1.273 + Push "$INSTDIR\update\updater.ini" 1.274 + Call un.RenameDelete 1.275 + Push "$INSTDIR\update\updater.exe" 1.276 + Call un.RenameDelete 1.277 + RMDir /REBOOTOK "$INSTDIR\update" 1.278 + RMDir /REBOOTOK "$INSTDIR" 1.279 + 1.280 + DeleteRegKey HKLM "${MaintUninstallKey}" 1.281 + 1.282 + ${If} ${RunningX64} 1.283 + SetRegView 64 1.284 + ${EndIf} 1.285 + DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "Installed" 1.286 + DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "FFPrefetchDisabled" 1.287 + DeleteRegKey HKLM "${FallbackKey}\" 1.288 + ${If} ${RunningX64} 1.289 + SetRegView lastused 1.290 + ${EndIf} 1.291 +SectionEnd