github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/build/install/windows/gauge-install.nsi (about)

     1  ; This script builds gauge installation package
     2  ; It needs the following arguments to be set before calling compile
     3  ;    PRODUCT_VERSION -> Version of Gauge
     4  ;    GAUGE_DISTRIBUTABLES_DIR -> Directory where gauge distributables are available. It should not end with \
     5  ;    OUTPUT_FILE_NAME -> Name of the setup file
     6  
     7  ; HM NIS Edit Wizard helper defines
     8  !define PRODUCT_NAME "Gauge"
     9  !define PRODUCT_PUBLISHER "ThoughtWorks Inc."
    10  !define PRODUCT_WEB_SITE "http://getgauge.io"
    11  !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\gauge.exe"
    12  !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
    13  !define PRODUCT_UNINST_ROOT_KEY "HKLM"
    14  !define MUI_FINISHPAGE_LINK "Click here to read the Gauge Reference Documentation"
    15  !define MUI_FINISHPAGE_LINK_LOCATION "https://docs.getgauge.io"
    16  !define MUI_FINISHPAGE_NOAUTOCLOSE
    17  !define MUI_COMPONENTSPAGE_TEXT_COMPLIST "Additional plugins can be installed using the command 'gauge install <plugin>'"
    18  !define TELEMETRY_PAGE_TITLE "Gauge Telemetry"
    19  !define TELEMETRY_PAGE_DESCRIPTION "We are constantly looking to make Gauge better, and report usage statistics anonymously over time."
    20  !define TELEMETRY_PAGE_ACTION_DESCRIPTION "If you do not want to participate please uncheck the option below."
    21  ; MUI 1.67 compatible ------
    22  !include "MUI.nsh"
    23  !include "MUI2.nsh"
    24  !include "EnvVarUpdate.nsh"
    25  !include "x64.nsh"
    26  !include "winmessages.nsh"
    27  !include "FileFunc.nsh" ;For GetOptions
    28  !include "WordFunc.nsh"
    29  !include "nsDialogs.nsh"
    30  
    31  !define Explode "!insertmacro Explode"
    32  
    33  !macro  Explode Length  Separator   String
    34    Push    `${Separator}`
    35    Push    `${String}`
    36    Call    Explode
    37    Pop     `${Length}`
    38  !macroend
    39  
    40  var TelemetryEnabled
    41  var TelemetryEnabledDialog
    42  Function TelemetryEnablePage
    43    !insertmacro MUI_HEADER_TEXT "${TELEMETRY_PAGE_TITLE}" ""
    44    nsDialogs::Create 1018
    45    Pop $TelemetryEnabledDialog
    46    ${If} $TelemetryEnabledDialog == error
    47      abort
    48    ${EndIf}
    49    ${NSD_CreateLabel} 20u 0 250u 30u "${TELEMETRY_PAGE_DESCRIPTION}"
    50    ${NSD_CreateLabel} 20u 30u 250u 30u "${TELEMETRY_PAGE_ACTION_DESCRIPTION}"
    51    ${NSD_CreateCheckbox} 20u 60u 100% 10u "&Enable Telemetry"
    52    Pop $TelemetryEnabled
    53    ${NSD_Check} $TelemetryEnabled
    54    nsDialogs::Show
    55  FunctionEnd
    56  
    57  Function TelemetryPageLeave
    58      ${NSD_GetState} $TelemetryEnabled $R5
    59  FunctionEnd
    60  
    61  ; MUI Settings
    62  !define MUI_ABORTWARNING
    63  !define MUI_ICON "gauge.ico"
    64  !define MUI_UNICON "gauge.ico"
    65  !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
    66  ; Welcome page
    67  !insertmacro MUI_PAGE_WELCOME
    68  ; License page
    69  !insertmacro MUI_PAGE_LICENSE "gpl.txt"
    70  ; Plugin options page
    71  !insertmacro MUI_PAGE_COMPONENTS
    72  Page Custom TelemetryEnablePage TelemetryPageLeave
    73  ; Directory page
    74  !insertmacro MUI_PAGE_DIRECTORY
    75  ; Instfiles page
    76  !insertmacro MUI_PAGE_INSTFILES
    77  ; Finish page
    78  !insertmacro MUI_PAGE_FINISH
    79  
    80  ; Uninstaller pages
    81  !insertmacro MUI_UNPAGE_INSTFILES
    82  
    83  ; Language files
    84  !insertmacro MUI_LANGUAGE "English"
    85  
    86  ; MUI end ------
    87  
    88  SpaceTexts none
    89  
    90  BrandingText "${PRODUCT_NAME} ${PRODUCT_VERSION}  |  ${PRODUCT_PUBLISHER}"
    91  
    92  Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
    93  OutFile "${OUTPUT_FILE_NAME}"
    94  InstallDir "$PROGRAMFILES\Gauge"
    95  InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
    96  ShowUnInstDetails show
    97  
    98  Section "Gauge" SEC_GAUGE
    99    CreateDirectory $%temp%\Gauge
   100    SectionIn RO
   101    SetOutPath "$INSTDIR\bin"
   102    SetOverwrite on
   103    File /r "${GAUGE_DISTRIBUTABLES_DIR}\bin\*"
   104  SectionEnd
   105  
   106  SectionGroup /e "Language Plugins" SEC_LANGUAGES
   107    Section /o "Java" SEC_JAVA
   108    SectionEnd
   109    Section /o "C#" SEC_CSHARP
   110    SectionEnd
   111    Section /o "Ruby" SEC_RUBY
   112    SectionEnd
   113  SectionGroupEnd
   114  
   115  SectionGroup /e "Reporting Plugins" SEC_REPORTS
   116    Section "HTML" SEC_HTML
   117      SectionIn RO
   118    SectionEnd
   119    Section /o "XML" SEC_XML
   120    SectionEnd
   121    Section /o "Spectacle" SEC_SPECTACLE
   122    SectionEnd
   123  SectionGroupEnd
   124  
   125  
   126  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
   127    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_GAUGE} "Will install Gauge Core (gauge.exe)."
   128    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_LANGUAGES} "Check to install language runners that needs to be installed. You need at least one language runner to run Gauge specs."
   129    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_JAVA} "Java language runner, enables writing implementations using Java."
   130    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_CSHARP} "C# language runner, enables writing implementations using C#."
   131    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_RUBY} "Ruby language runner, enables writing implementations using Ruby."
   132    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_REPORTS} "Check to install reporting plugins. HTML report plugin is installed by default."
   133    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_HTML} "Generates HTML report of Gauge spec run."
   134    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_XML} "Generates JUnit style XML report of Gauge spec run."
   135    !insertmacro MUI_DESCRIPTION_TEXT ${SEC_SPECTACLE} "Generates static HTML from Spec files, allows filtering/navigation of Specifications."
   136  !insertmacro MUI_FUNCTION_DESCRIPTION_END
   137  
   138  function .onInit
   139    ${If} ${RunningX64}
   140      SetRegView 64
   141      StrCpy $INSTDIR "$PROGRAMFILES64\Gauge"
   142    ${EndIf}
   143    ;Only if it is silent install
   144    ${If} ${Silent}
   145      ${GetParameters} $R0
   146      ;See if PLUGINS to install are specified via cmd line arg
   147      ${GetOptions} $R0 "/PLUGINS" $0
   148      ${IfNot} ${Errors}
   149        ${Explode}  $1  "," $0
   150        ${For} $2 1 $1
   151          Pop $3
   152          ${StrFilter} $3 "-" "" "" $3 ; lowercase
   153          ${If} '$3' == 'ruby'
   154            !insertmacro SelectSection ${SEC_RUBY}
   155          ${EndIf}
   156          ${If} '$3' == 'java'
   157            !insertmacro SelectSection ${SEC_JAVA}
   158          ${EndIf}
   159          ${If} '$3' == 'csharp'
   160            !insertmacro SelectSection ${SEC_CSHARP}
   161          ${EndIf}
   162          ${If} '$3' == 'xml-report'
   163            !insertmacro SelectSection ${SEC_XML}
   164          ${EndIf}
   165          ${If} '$3' == 'spectacle'
   166            !insertmacro SelectSection ${SEC_SPECTACLE}
   167          ${EndIf}
   168        ${Next}
   169      ${EndIF}
   170  
   171      ;See if TELEMETRY is set via cmd line arg
   172      ${GetOptions} $R0 "/TELEMETRY" $0
   173      ${IfNot} ${Errors}
   174        ${If} $0 == "off"
   175          StrCpy $R5 0
   176        ${EndIF}
   177      ${EndIF}
   178    ${EndIf}
   179  functionEnd
   180  
   181  Section -AdditionalIcons
   182    SetOutPath $INSTDIR
   183    CreateDirectory "$SMPROGRAMS\Gauge"
   184    CreateShortCut "$SMPROGRAMS\Gauge\Uninstall.lnk" "$INSTDIR\uninst.exe"
   185  SectionEnd
   186  
   187  Section -Post
   188    WriteUninstaller "$INSTDIR\uninst.exe"
   189    WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\gauge.exe"
   190    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
   191    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
   192    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\bin\gauge.exe"
   193    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
   194    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
   195    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
   196    ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\bin"
   197    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
   198    RMDir /r /REBOOTOK "$%temp%\Gauge"
   199  
   200    ${If} $R5 == 0
   201      DetailPrint "Turning off Telemetry"
   202      nsExec::ExecToLog 'gauge telemetry off'
   203    ${Else}
   204      DetailPrint "Turning on Telemetry"
   205      nsExec::ExecToLog 'gauge telemetry on'
   206    ${EndIf}
   207    
   208    Dialer::GetConnectedState
   209    Pop $R0
   210  
   211    ${If} $R0 == 'online'
   212      SectionGetFlags ${SEC_JAVA} $R0
   213      SectionGetFlags ${SEC_CSHARP} $R1
   214      SectionGetFlags ${SEC_RUBY} $R2
   215      SectionGetFlags ${SEC_XML} $R3
   216      SectionGetFlags ${SEC_SPECTACLE} $R4
   217  
   218      ${If} $R0 == 1
   219        DetailPrint "Installing plugin : java"
   220        nsExec::ExecToLog 'gauge install java'
   221      ${EndIf}
   222  
   223      ${If} $R1 == 1
   224        DetailPrint "Installing plugin : csharp"
   225        nsExec::ExecToLog 'gauge install csharp'
   226      ${EndIf}
   227  
   228      ${If} $R2 == 1
   229        DetailPrint "Installing plugin : ruby"
   230        nsExec::ExecToLog 'gauge install ruby'
   231      ${EndIf}
   232  
   233      ${If} $R3 == 1
   234        DetailPrint "Installing plugin : xml-report"
   235        nsExec::ExecToLog 'gauge install xml-report'
   236      ${EndIf}
   237  
   238      ${If} $R4 == 1
   239        DetailPrint "Installing plugin : spectacle"
   240        nsExec::ExecToLog 'gauge install spectacle'
   241      ${EndIf}
   242    ${Else}
   243      DetailPrint "[WARNING] Internet connection unavailable. Skipping plugins installation"
   244    ${EndIf}
   245  SectionEnd
   246  
   247  Function un.onUninstSuccess
   248    IfSilent +3 0
   249      HideWindow
   250        MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
   251  FunctionEnd
   252  
   253  Function un.onInit
   254    IfSilent +3 0
   255      MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
   256    Abort
   257  FunctionEnd
   258  
   259  Section Uninstall
   260    Delete "$INSTDIR\uninst.exe"
   261    Delete "$INSTDIR\plugin-install.bat"
   262    RMDir /r "$INSTDIR\bin"
   263    Delete "$SMPROGRAMS\Gauge\Uninstall.lnk"
   264    DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
   265    DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
   266    DeleteRegValue ${env_hklm} GAUGE_ROOT
   267    RMDir "$INSTDIR"
   268    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
   269    SetAutoClose true
   270  SectionEnd
   271  
   272  ; Ref: http://nsis.sourceforge.net/Explode
   273  Function Explode
   274    ; Initialize variables
   275    Var /GLOBAL explString
   276    Var /GLOBAL explSeparator
   277    Var /GLOBAL explStrLen
   278    Var /GLOBAL explSepLen
   279    Var /GLOBAL explOffset
   280    Var /GLOBAL explTmp
   281    Var /GLOBAL explTmp2
   282    Var /GLOBAL explTmp3
   283    Var /GLOBAL explArrCount
   284  
   285    ; Get input from user
   286    Pop $explString
   287    Pop $explSeparator
   288  
   289    ; Calculates initial values
   290    StrLen $explStrLen $explString
   291    StrLen $explSepLen $explSeparator
   292    StrCpy $explArrCount 1
   293  
   294    ${If}   $explStrLen <= 1          ;   If we got a single character
   295    ${OrIf} $explSepLen > $explStrLen ;   or separator is larger than the string,
   296      Push    $explString             ;   then we return initial string with no change
   297      Push    1                       ;   and set array's length to 1
   298      Return
   299    ${EndIf}
   300  
   301    ; Set offset to the last symbol of the string
   302    StrCpy $explOffset $explStrLen
   303    IntOp  $explOffset $explOffset - 1
   304  
   305    ; Clear temp string to exclude the possibility of appearance of occasional data
   306    StrCpy $explTmp   ""
   307    StrCpy $explTmp2  ""
   308    StrCpy $explTmp3  ""
   309  
   310    ; Loop until the offset becomes negative
   311    ${Do}
   312      ;   If offset becomes negative, it is time to leave the function
   313      ${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}
   314  
   315      ;   Remove everything before and after the searched part ("TempStr")
   316      StrCpy $explTmp $explString $explSepLen $explOffset
   317  
   318      ${If} $explTmp == $explSeparator
   319          ;   Calculating offset to start copy from
   320          IntOp   $explTmp2 $explOffset + $explSepLen ;   Offset equals to the current offset plus length of separator
   321          StrCpy  $explTmp3 $explString "" $explTmp2
   322  
   323          Push    $explTmp3                           ;   Throwing array item to the stack
   324          IntOp   $explArrCount $explArrCount + 1     ;   Increasing array's counter
   325  
   326          StrCpy  $explString $explString $explOffset 0   ;   Cutting all characters beginning with the separator entry
   327          StrLen  $explStrLen $explString
   328      ${EndIf}
   329  
   330      ${If} $explOffset = 0                       ;   If the beginning of the line met and there is no separator,
   331                                                  ;   copying the rest of the string
   332          ${If} $explSeparator == ""              ;   Fix for the empty separator
   333              IntOp   $explArrCount   $explArrCount - 1
   334          ${Else}
   335              Push    $explString
   336          ${EndIf}
   337      ${EndIf}
   338  
   339      IntOp   $explOffset $explOffset - 1
   340    ${Loop}
   341  
   342    Push $explArrCount
   343  "FunctionEnd"