Skip to content

Commit

Permalink
Allow upgrade on windows
Browse files Browse the repository at this point in the history
Now we check if bareos is already installed on the windows machine.
If so, we call the uninstaller of the previous version and install
ourselves afterwards.

The newer uninstaller keep the configuration files as the uninstaller is
called accordingly.

The dialogs for parametrizing the configuration and the dialog
for the config snipped are not shown, as the existing configuration
files will be used.

Still the user has to choose the same components during the upgrade
as were installed before.

fixes #225: Windows installer can't upgrade in place
  • Loading branch information
pstorz authored and Marco van Wieringen committed Feb 17, 2015
1 parent 8ca972e commit 1658a64
Showing 1 changed file with 98 additions and 71 deletions.
169 changes: 98 additions & 71 deletions platforms/win32/winbareos.nsi
Expand Up @@ -70,6 +70,12 @@ Var hwnd

Var SilentKeepConfig

# are we doing an upgrade or fresh install?
# if we are doing an upgrade we automatically
# keep the existing config files silently and skip
# the param dialogs and the config snippet dialog
Var Upgrading

!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "Sections.nsh"
Expand All @@ -82,6 +88,7 @@ Var SilentKeepConfig
# call functions once to have them included
${StrCase}
${StrTrimNewLines}
${StrRep}

; MUI 1.67 compatible ------
!include "MUI.nsh"
Expand Down Expand Up @@ -118,7 +125,6 @@ Page custom getDirectorParameters
!insertmacro MUI_PAGE_INSTFILES
; Finish page


; Custom page shows director config snippet
Page custom displayDirconfSnippet

Expand Down Expand Up @@ -152,102 +158,90 @@ FunctionEnd
# the conf file
#
!macro InstallConfFile fname

# This is important to have $APPDATA variable
# point to ProgramData folder
# instead of current user's Roaming folder
SetShellVarContext all
# This is important to have $APPDATA variable
# point to ProgramData folder
# instead of current user's Roaming folder
SetShellVarContext all

${If} ${FileExists} "$APPDATA\${PRODUCT_NAME}\${fname}"

StrCmp $SilentKeepConfig "yes" keep

MessageBox MB_YESNO|MB_ICONQUESTION \
"Existing config file found: $APPDATA\${PRODUCT_NAME}\${fname}$\r$\nKeep existing config file?" \
/SD IDNO IDYES keep IDNO move
move:
Rename "$APPDATA\${PRODUCT_NAME}\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.old"
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}"
MessageBox MB_OK|MB_ICONINFORMATION \
"Existing config file saved as $APPDATA\${PRODUCT_NAME}\${fname}.old" \
/SD IDOK
StrCmp $SilentKeepConfig "yes" keep # in silent install keep configs silently if desired
StrCmp $Upgrading "yes" keep # during upgrade also keep configs silently

MessageBox MB_YESNO|MB_ICONQUESTION \
"Existing config file found: $APPDATA\${PRODUCT_NAME}\${fname}$\r$\nKeep existing config file?" \
/SD IDNO IDYES keep IDNO move
move:
Rename "$APPDATA\${PRODUCT_NAME}\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.old"
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}"
MessageBox MB_OK|MB_ICONINFORMATION \
"Existing config file saved as $APPDATA\${PRODUCT_NAME}\${fname}.old" \
/SD IDOK
GOTO +3
keep:
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.new"
MessageBox MB_OK|MB_ICONINFORMATION \
"New config file stored $APPDATA\${PRODUCT_NAME}\${fname}.new" \
/SD IDOK
keep:
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}.new"
StrCmp $Upgrading "yes" skipmsgbox # during upgrade keep existing file without messagebox
MessageBox MB_OK|MB_ICONINFORMATION \
"New config file stored $APPDATA\${PRODUCT_NAME}\${fname}.new" \
/SD IDOK
skipmsgbox:
${Else}
Rename "$PLUGINSDIR\${fname}" "$APPDATA\${PRODUCT_NAME}\${fname}"
${EndIf}
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Edit ${fname}.lnk" "write.exe" '"$APPDATA\${PRODUCT_NAME}\${fname}"'


# for traymonitor.conf, set access and ownership to users
${If} ${fname} == "tray-monitor.conf"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Edit ${fname}.lnk" "write.exe" '"$APPDATA\${PRODUCT_NAME}\${fname}"'

# disable file access inheritance
# for traymonitor.conf, set access and ownership to users
${If} ${fname} == "tray-monitor.conf"
# Disable file access inheritance
AccessControl::DisableFileInheritance "$APPDATA\${PRODUCT_NAME}\${fname}"
Pop $R0
DetailPrint `AccessControl result: $R0`
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}

# set file owner to administrator
# Set file owner to administrator
AccessControl::SetFileOwner "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-545)" # user
Pop $R0
DetailPrint `AccessControl result: $R0`
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}

# set fullaccess only for administrators (S-1-5-32-544)
# Set fullaccess only for administrators (S-1-5-32-544)
AccessControl::ClearOnFile "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-545)" "FullAccess"
Pop $R0
DetailPrint `AccessControl result: $R0`
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}


# all other config files admin owner and only access
${Else}
# disable file access inheritance
${Else}
# All other config files admin owner and only access
# Disable file access inheritance
AccessControl::DisableFileInheritance "$APPDATA\${PRODUCT_NAME}\${fname}"
Pop $R0
DetailPrint `AccessControl result: $R0`
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}

# set file owner to administrator
# Set file owner to administrator
AccessControl::SetFileOwner "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-544)" # administratoren
Pop $R0
DetailPrint `AccessControl result: $R0`
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}

# set fullaccess only for administrators (S-1-5-32-544)
# Set fullaccess only for administrators (S-1-5-32-544)
AccessControl::ClearOnFile "$APPDATA\${PRODUCT_NAME}\${fname}" "(S-1-5-32-544)" "FullAccess"
Pop $R0
DetailPrint `AccessControl result: $R0`
${If} $R0 == error
Pop $R0
DetailPrint `AccessControl error: $R0`
${EndIf}

${EndIf}

${EndIf}
!macroend


Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
Expand All @@ -273,10 +267,10 @@ SectionEnd

Section -SetPasswords
SetShellVarContext all
# Write sed file to replace the preconfigured variables by the configured values
#
# File Daemon and Tray Monitor configs
#
# Write sed file to replace the preconfigured variables by the configured values
#
# File Daemon and Tray Monitor configs
#
FileOpen $R1 $PLUGINSDIR\config.sed w
#FileOpen $R1 config.sed w

Expand All @@ -301,10 +295,9 @@ Section -SetPasswords

#Delete config.sed


#
# config files for bconsole and bat to access remote director
#
#
# config files for bconsole and bat to access remote director
#
FileOpen $R1 $PLUGINSDIR\bconsole.sed w

FileWrite $R1 "s#XXX_REPLACE_WITH_BASENAME_XXX-dir#$DirectorName#g$\r$\n"
Expand Down Expand Up @@ -586,14 +579,48 @@ Function .onInit


# check if software is already installed
ClearErrors
ReadRegStr $2 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"
ReadRegStr $0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion"
StrCmp $2 "" +3
MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_NAME} version $0 $\r$\nseems to be already installed on your system.$\r$\nPlease uninstall first."
# ClearErrors
# ReadRegStr $2 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"
# ReadRegStr $0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion"
# StrCmp $2 "" +3
# MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_NAME} version $0 $\r$\nseems to be already installed on your system.$\r$\nPlease uninstall first."
# Abort
#

# UPGRADE: if already installed allow to uninstall installed version
# inspired by http://nsis.sourceforge.net/Auto-uninstall_old_before_installing_new
strcpy $Upgrading "no"

ReadRegStr $2 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName"
ReadRegStr $0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion"
ReadRegStr $R0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
StrCmp $R0 "" done
strcpy $Upgrading "yes"
${StrRep} $INSTDIR $R0 "uninst.exe" "" # find current INSTDIR by cutting uninst.exe out of uninstall string

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT_NAME} version $0 is already installed in $\r$\n \
'$INSTDIR' on your system.$\r$\n$\n \
`OK` executes the uninstaller before installing the new version$\r$\n \
`Cancel` cancels this upgrade. $\r$\n $\r$\n \
It is recommended that you make a copy of your configuration files before upgrading.$\r$\n \
" \
/SD IDCANCEL IDOK uninst
Abort

;Run the uninstaller
uninst:
ClearErrors
ExecWait '$R0 /S /SILENTKEEPCONFIG _?=$INSTDIR'
;Silent Uninstall, Keep Configuration files, Do not copy the uninstaller to a temp file

IfErrors no_remove_uninstaller done
# Exec $INSTDIR\uninst.exe

no_remove_uninstaller:
MessageBox MB_OK|MB_ICONEXCLAMATION "Error during uninstall of ${PRODUCT_NAME} version $0. Aborting"
abort

done:
# Parameters:
# Needed for Client and Tray-Mon:
#
Expand All @@ -613,12 +640,11 @@ Function .onInit

var /GLOBAL cmdLineParams

# Installer Options
# Installer Options
${GetParameters} $cmdLineParams
ClearErrors


# /? param (help)
# /? param (help)
ClearErrors
${GetOptions} $cmdLineParams '/?' $R0
IfErrors +3 0
Expand Down Expand Up @@ -759,14 +785,13 @@ SectionSetFlags ${SEC_TRAYMON} ${SF_SELECTED} # SF_SELECTED
StrCpy $DirectorPassword "DIRECTORPASSWORD"
FunctionEnd




#
# Client Configuration Dialog
#
Function getClientParameters
Push $R0
push $R0
# skip if we are upgrading
strcmp $Upgrading "yes" skip

# prefill the dialog fields with our passwords and other
# information
Expand All @@ -790,8 +815,7 @@ ${If} ${SectionIsSelected} ${SEC_CLIENT}
${EndIf}
# MessageBox MB_OK "$ClientName$\r$\n$ClientPassword$\r$\n$ClientMonitorPassword "



skip:
Pop $R0
FunctionEnd

Expand All @@ -800,6 +824,7 @@ FunctionEnd
#
Function getDirectorParameters
Push $R0
strcmp $Upgrading "yes" skip
# prefill the dialog fields
WriteINIStr "$PLUGINSDIR\directordialog.ini" "Field 2" "state" $DirectorAddress
WriteINIStr "$PLUGINSDIR\directordialog.ini" "Field 3" "state" $DirectorPassword
Expand All @@ -812,6 +837,7 @@ ${If} ${SectionIsSelected} ${SEC_BCONSOLE}

# MessageBox MB_OK "$DirectorAddress$\r$\n$DirectorPassword"
${EndIf}
skip:
Pop $R0
FunctionEnd

Expand All @@ -820,6 +846,7 @@ FunctionEnd
#
Function displayDirconfSnippet

strcmp $Upgrading "yes" skip
#
# write client config snippet for director
#
Expand Down Expand Up @@ -849,7 +876,7 @@ Function displayDirconfSnippet
Pop $hwnd

nsDialogs::Show

skip:
FunctionEnd


Expand Down

0 comments on commit 1658a64

Please sign in to comment.