maintenanceservice_installer.nsi (12459B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 ; Set verbosity to 3 (e.g. no script) to lessen the noise in the build logs 6 !verbose 3 7 8 ; 7-Zip provides better compression than the lzma from NSIS so we add the files 9 ; uncompressed and use 7-Zip to create a SFX archive of it 10 SetDatablockOptimize on 11 SetCompress off 12 CRCCheck on 13 14 RequestExecutionLevel admin 15 16 Unicode true 17 ManifestSupportedOS all 18 ManifestDPIAware true 19 20 !addplugindir ./ 21 22 ; Variables 23 Var TempMaintServiceName 24 Var BrandFullNameDA 25 Var BrandFullName 26 27 ; Other included files may depend upon these includes! 28 ; The following includes are provided by NSIS. 29 !include FileFunc.nsh 30 !include LogicLib.nsh 31 !include MUI.nsh 32 !include WinMessages.nsh 33 !include WinVer.nsh 34 !include WordFunc.nsh 35 36 !insertmacro GetOptions 37 !insertmacro GetParameters 38 !insertmacro GetSize 39 40 ; The test machines use this fallback key to run tests. 41 ; And anyone that wants to run tests themselves should already have 42 ; this installed. 43 !define FallbackKey \ 44 "SOFTWARE\Mozilla\MaintenanceService\3932ecacee736d366d6436db0f55bce4" 45 46 !define CompanyName "Mozilla Corporation" 47 !define BrandFullNameInternal "" 48 49 ; The following includes are custom. 50 !include defines.nsi 51 ; We keep defines.nsi defined so that we get other things like 52 ; the version number, but we redefine BrandFullName 53 !define MaintFullName "Mozilla Maintenance Service" 54 !ifdef BrandFullName 55 !undef BrandFullName 56 !endif 57 !define BrandFullName "${MaintFullName}" 58 59 !include common.nsh 60 !include locales.nsi 61 62 VIAddVersionKey "FileDescription" "${MaintFullName} Installer" 63 VIAddVersionKey "OriginalFilename" "maintenanceservice_installer.exe" 64 65 Name "${MaintFullName}" 66 OutFile "maintenanceservice_installer.exe" 67 68 ; Get installation folder from registry if available 69 InstallDirRegKey HKLM "Software\Mozilla\MaintenanceService" "" 70 71 SetOverwrite on 72 73 ; serviceinstall.cpp also uses this key, in case the path is changed, update 74 ; there too. 75 !define MaintUninstallKey \ 76 "Software\Microsoft\Windows\CurrentVersion\Uninstall\MozillaMaintenanceService" 77 78 ; Always install into the 32-bit location even if we have a 64-bit build. 79 ; This is because we use only 1 service for all Firefox channels. 80 ; Allow either x86 and x64 builds to exist at this location, depending on 81 ; what is the latest build. 82 InstallDir "$PROGRAMFILES32\${MaintFullName}\" 83 ShowUnInstDetails nevershow 84 85 ################################################################################ 86 # Modern User Interface - MUI 87 88 !define MUI_ICON setup.ico 89 !define MUI_UNICON setup.ico 90 !define MUI_WELCOMEPAGE_TITLE_3LINES 91 !define MUI_UNWELCOMEFINISHPAGE_BITMAP wizWatermark.bmp 92 93 ;Interface Settings 94 !define MUI_ABORTWARNING 95 96 ; Uninstaller Pages 97 !insertmacro MUI_UNPAGE_CONFIRM 98 !insertmacro MUI_UNPAGE_INSTFILES 99 100 ################################################################################ 101 # Language 102 103 !insertmacro MOZ_MUI_LANGUAGE 'baseLocale' 104 !verbose push 105 !verbose 3 106 !include "overrideLocale.nsh" 107 !include "customLocale.nsh" 108 !verbose pop 109 110 ; Set this after the locale files to override it if it is in the locale 111 ; using " " for BrandingText will hide the "Nullsoft Install System..." branding 112 BrandingText " " 113 114 Function .onInit 115 ; Remove the current exe directory from the search order. 116 ; This only effects LoadLibrary calls and not implicitly loaded DLLs. 117 System::Call 'kernel32::SetDllDirectoryW(w "")' 118 119 SetSilent silent 120 121 ${Unless} ${AtLeastWin10} 122 Abort 123 ${EndUnless} 124 FunctionEnd 125 126 Function un.onInit 127 ; Remove the current exe directory from the search order. 128 ; This only effects LoadLibrary calls and not implicitly loaded DLLs. 129 System::Call 'kernel32::SetDllDirectoryW(w "")' 130 131 StrCpy $BrandFullNameDA "${MaintFullName}" 132 StrCpy $BrandFullName "${MaintFullName}" 133 FunctionEnd 134 135 Section "MaintenanceService" 136 AllowSkipFiles off 137 138 CreateDirectory $INSTDIR 139 SetOutPath $INSTDIR 140 141 ; If the service already exists, then it will be stopped when upgrading it 142 ; via the maintenanceservice_tmp.exe command executed below. 143 ; The maintenanceservice_tmp.exe command will rename the file to 144 ; maintenanceservice.exe if maintenanceservice_tmp.exe is newer. 145 ; If the service does not exist yet, we install it and drop the file on 146 ; disk as maintenanceservice.exe directly. 147 StrCpy $TempMaintServiceName "maintenanceservice.exe" 148 IfFileExists "$INSTDIR\maintenanceservice.exe" 0 skipAlreadyExists 149 StrCpy $TempMaintServiceName "maintenanceservice_tmp.exe" 150 skipAlreadyExists: 151 152 ; We always write out a copy and then decide whether to install it or 153 ; not via calling its 'install' cmdline which works by version comparison. 154 CopyFiles /SILENT "$EXEDIR\maintenanceservice.exe" "$INSTDIR\$TempMaintServiceName" 155 156 ; The updater.ini file is only used when performing an install or upgrade, 157 ; and only if that install or upgrade is successful. If an old updater.ini 158 ; happened to be copied into the maintenance service installation directory 159 ; but the service was not newer, the updater.ini file would be unused. 160 ; It is used to fill the description of the service on success. 161 CopyFiles /SILENT "$EXEDIR\updater.ini" "$INSTDIR\updater.ini" 162 163 ; Install the application maintenance service. 164 ; If a service already exists, the command line parameter will stop the 165 ; service and only install itself if it is newer than the already installed 166 ; service. If successful it will remove the old maintenanceservice.exe 167 ; and replace it with maintenanceservice_tmp.exe. 168 ClearErrors 169 ${GetParameters} $0 170 ${GetOptions} "$0" "/Upgrade" $0 171 ${If} ${Errors} 172 ExecWait '"$INSTDIR\$TempMaintServiceName" install' 173 ${Else} 174 ; The upgrade cmdline is the same as install except 175 ; It will fail if the service isn't already installed. 176 ExecWait '"$INSTDIR\$TempMaintServiceName" upgrade' 177 ${EndIf} 178 179 WriteUninstaller "$INSTDIR\Uninstall.exe" 180 181 ; Since the Maintenance service can be installed either x86 or x64, 182 ; always use the 64-bit registry. 183 ${If} ${RunningX64} 184 ${OrIf} ${IsNativeARM64} 185 ; Previous versions always created the uninstall key in the 32-bit registry. 186 ; Clean those old entries out if they still exist. 187 SetRegView 32 188 DeleteRegKey HKLM "${MaintUninstallKey}" 189 ; Preserve the lastused value before we switch to 64. 190 SetRegView lastused 191 192 SetRegView 64 193 ${EndIf} 194 195 WriteRegStr HKLM "${MaintUninstallKey}" "DisplayName" "${MaintFullName}" 196 WriteRegStr HKLM "${MaintUninstallKey}" "UninstallString" \ 197 '"$INSTDIR\uninstall.exe"' 198 WriteRegStr HKLM "${MaintUninstallKey}" "DisplayIcon" \ 199 "$INSTDIR\Uninstall.exe,0" 200 WriteRegStr HKLM "${MaintUninstallKey}" "DisplayVersion" "${AppVersion}" 201 WriteRegStr HKLM "${MaintUninstallKey}" "Publisher" "Mozilla" 202 WriteRegStr HKLM "${MaintUninstallKey}" "Comments" "${BrandFullName}" 203 WriteRegDWORD HKLM "${MaintUninstallKey}" "NoModify" 1 204 ${GetSize} "$INSTDIR" "/S=0K" $R2 $R3 $R4 205 WriteRegDWORD HKLM "${MaintUninstallKey}" "EstimatedSize" $R2 206 207 ; Write out that a maintenance service was attempted. 208 ; We do this because on upgrades we will check this value and we only 209 ; want to install once on the first upgrade to maintenance service. 210 ; Also write out that we are currently installed, preferences will check 211 ; this value to determine if we should show the service update pref. 212 WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Attempted" 1 213 WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Installed" 1 214 DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "FFPrefetchDisabled" 215 216 ; Included here for debug purposes only. 217 ; These keys are used to bypass the installation dir is a valid installation 218 ; check from the service so that tests can be run. 219 ; WriteRegStr HKLM "${FallbackKey}\0" "name" "Mozilla Corporation" 220 ; WriteRegStr HKLM "${FallbackKey}\0" "issuer" "DigiCert Trusted G4 Code Signing RSA4096 SHA384 2021 CA1" 221 ${If} ${RunningX64} 222 ${OrIf} ${IsNativeARM64} 223 SetRegView lastused 224 ${EndIf} 225 SectionEnd 226 227 ; By renaming before deleting we improve things slightly in case 228 ; there is a file in use error. In this case a new install can happen. 229 Function un.RenameDelete 230 Pop $9 231 ; If the .moz-delete file already exists previously, delete it 232 ; If it doesn't exist, the call is ignored. 233 ; We don't need to pass /REBOOTOK here since it was already marked that way 234 ; if it exists. 235 Delete "$9.moz-delete" 236 Rename "$9" "$9.moz-delete" 237 ${If} ${Errors} 238 Delete /REBOOTOK "$9" 239 ${Else} 240 Delete /REBOOTOK "$9.moz-delete" 241 ${EndIf} 242 ClearErrors 243 FunctionEnd 244 245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 246 ; NOTE: The maintenance service uninstaller does not currently get updated when 247 ; the service itself does during application updates. Under normal use, only 248 ; running the Firefox installer will generate a new maintenance service 249 ; uninstaller. That means anything added here will not be seen by users until 250 ; they run a new Firefox installer. Fixing this is tracked in 251 ; https://bugzilla.mozilla.org/show_bug.cgi?id=1665193 252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 253 Section "Uninstall" 254 ; Delete the service so that no updates will be attempted 255 ExecWait '"$INSTDIR\maintenanceservice.exe" uninstall' 256 257 Push "$INSTDIR\updater.ini" 258 Call un.RenameDelete 259 Push "$INSTDIR\maintenanceservice.exe" 260 Call un.RenameDelete 261 Push "$INSTDIR\maintenanceservice_tmp.exe" 262 Call un.RenameDelete 263 Push "$INSTDIR\maintenanceservice.old" 264 Call un.RenameDelete 265 Push "$INSTDIR\Uninstall.exe" 266 Call un.RenameDelete 267 Push "$INSTDIR\update\updater.ini" 268 Call un.RenameDelete 269 Push "$INSTDIR\update\updater.exe" 270 Call un.RenameDelete 271 Push "$INSTDIR\logs\maintenanceservice.log" 272 Call un.RenameDelete 273 Push "$INSTDIR\logs\maintenanceservice-1.log" 274 Call un.RenameDelete 275 Push "$INSTDIR\logs\maintenanceservice-2.log" 276 Call un.RenameDelete 277 Push "$INSTDIR\logs\maintenanceservice-3.log" 278 Call un.RenameDelete 279 Push "$INSTDIR\logs\maintenanceservice-4.log" 280 Call un.RenameDelete 281 Push "$INSTDIR\logs\maintenanceservice-5.log" 282 Call un.RenameDelete 283 Push "$INSTDIR\logs\maintenanceservice-6.log" 284 Call un.RenameDelete 285 Push "$INSTDIR\logs\maintenanceservice-7.log" 286 Call un.RenameDelete 287 Push "$INSTDIR\logs\maintenanceservice-8.log" 288 Call un.RenameDelete 289 Push "$INSTDIR\logs\maintenanceservice-9.log" 290 Call un.RenameDelete 291 Push "$INSTDIR\logs\maintenanceservice-10.log" 292 Call un.RenameDelete 293 Push "$INSTDIR\logs\maintenanceservice-install.log" 294 Call un.RenameDelete 295 Push "$INSTDIR\logs\maintenanceservice-uninstall.log" 296 Call un.RenameDelete 297 SetShellVarContext all 298 Push "$APPDATA\Mozilla\logs\maintenanceservice.log" 299 Call un.RenameDelete 300 Push "$APPDATA\Mozilla\logs\maintenanceservice-1.log" 301 Call un.RenameDelete 302 Push "$APPDATA\Mozilla\logs\maintenanceservice-2.log" 303 Call un.RenameDelete 304 Push "$APPDATA\Mozilla\logs\maintenanceservice-3.log" 305 Call un.RenameDelete 306 Push "$APPDATA\Mozilla\logs\maintenanceservice-4.log" 307 Call un.RenameDelete 308 Push "$APPDATA\Mozilla\logs\maintenanceservice-5.log" 309 Call un.RenameDelete 310 Push "$APPDATA\Mozilla\logs\maintenanceservice-6.log" 311 Call un.RenameDelete 312 Push "$APPDATA\Mozilla\logs\maintenanceservice-7.log" 313 Call un.RenameDelete 314 Push "$APPDATA\Mozilla\logs\maintenanceservice-8.log" 315 Call un.RenameDelete 316 Push "$APPDATA\Mozilla\logs\maintenanceservice-9.log" 317 Call un.RenameDelete 318 Push "$APPDATA\Mozilla\logs\maintenanceservice-10.log" 319 Call un.RenameDelete 320 Push "$APPDATA\Mozilla\logs\maintenanceservice-install.log" 321 Call un.RenameDelete 322 Push "$APPDATA\Mozilla\logs\maintenanceservice-uninstall.log" 323 Call un.RenameDelete 324 RMDir /REBOOTOK "$APPDATA\Mozilla\logs" 325 RMDir /REBOOTOK "$APPDATA\Mozilla" 326 RMDir /REBOOTOK "$INSTDIR\logs" 327 RMDir /REBOOTOK "$INSTDIR\update" 328 RMDir /REBOOTOK "$INSTDIR\UpdateLogs" 329 RMDir /REBOOTOK "$INSTDIR" 330 331 ${If} ${RunningX64} 332 ${OrIf} ${IsNativeARM64} 333 SetRegView 64 334 ${EndIf} 335 DeleteRegKey HKLM "${MaintUninstallKey}" 336 DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "Installed" 337 DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "FFPrefetchDisabled" 338 DeleteRegKey HKLM "${FallbackKey}\" 339 ${If} ${RunningX64} 340 ${OrIf} ${IsNativeARM64} 341 SetRegView lastused 342 ${EndIf} 343 SectionEnd