Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e56561

Browse files
committed
Fixed silent mode. Now installer checks exist installation in the silent mode. And added options in ini file for silent mode: servicesccount, servicepassword, serviceid, islibc.
1 parent 9527e72 commit 5e56561

File tree

1 file changed

+93
-19
lines changed

1 file changed

+93
-19
lines changed

nsis/postgresql.nsi

+93-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
; PostgeSQL install Script
32
; Written by Postgres Professional, Postgrespro.ru
43
; used plugins: AccessControl, UserMgr,
@@ -245,14 +244,20 @@ Section $(componentClient) secClient
245244

246245
;MessageBox MB_OK|MB_ICONINFORMATION "pg_old_dir: $PG_OLD_DIR"
247246
;Call ChecExistInstall ;get port number for psql
247+
IfSilent 0 +2
248+
Call ChecExistInstall
249+
248250
var /GLOBAL isStopped
249251
StrCpy $isStopped 0
250252

251253

254+
;MessageBox MB_OK|MB_ICONINFORMATION "pg_old_dir: $PG_OLD_DIR"
255+
252256
${if} $PG_OLD_DIR != "" ; exist PG install
253-
MessageBox MB_YESNO|MB_ICONQUESTION "$(MESS_STOP_SERVER)" IDYES doitStop IDNO noyetStop
257+
MessageBox MB_YESNO|MB_ICONQUESTION "$(MESS_STOP_SERVER)" /SD IDYES IDYES doitStop IDNO noyetStop
254258
noyetStop:
255-
Return
259+
;Return
260+
Abort
256261
doitStop:
257262
DetailPrint "Stop the server ..."
258263
${if} $OLD_DATA_DIR != ""
@@ -357,25 +362,41 @@ SectionEnd
357362
Section $(componentServer) sec1
358363

359364

365+
;MessageBox MB_OK|MB_ICONINFORMATION "componentServer"
366+
IfSilent 0 +2
367+
Call CheckDataDir
368+
369+
;MessageBox MB_OK|MB_ICONINFORMATION "OLD_DATA_DIR=$OLD_DATA_DIR"
370+
371+
FileOpen $LogFile $INSTDIR\install.log w ;Opens a Empty File an fills it
372+
360373
${if} $PG_OLD_DIR != "" ; exist PG install
361374
${if} $isStopped == 0
362-
MessageBox MB_YESNO|MB_ICONQUESTION "$(MESS_STOP_SERVER)" IDYES doitStop IDNO noyetStop
375+
MessageBox MB_YESNO|MB_ICONQUESTION "$(MESS_STOP_SERVER)" /SD IDYES IDYES doitStop IDNO noyetStop
363376
noyetStop:
364-
Return
377+
;Return
378+
FileClose $LogFile
379+
Abort
365380
doitStop:
366-
DetailPrint "Stop the server ..."
367381
${if} $OLD_DATA_DIR != ""
382+
DetailPrint "Stop the server ..."
383+
FileWrite $LogFile "Stop the server ...$\r$\n"
384+
FileWrite $LogFile '"$PG_OLD_DIR\bin\pg_ctl.exe" stop -D "$OLD_DATA_DIR" -m fast -w$\r$\n'
368385
nsExec::Exec '"$PG_OLD_DIR\bin\pg_ctl.exe" stop -D "$OLD_DATA_DIR" -m fast -w'
369386
pop $0
387+
FileWrite $LogFile "pg_ctl.exe stop return $0 $\r$\n"
370388
DetailPrint "pg_ctl.exe stop return $0"
371389
${endif}
372390
${endif}
373391

374392
;unregister
393+
FileWrite $LogFile "Unregister the service ...$\r$\n"
375394
DetailPrint "Unregister the service ..."
376395
${if} $OldServiceID_text != ""
396+
FileWrite $LogFile '"$PG_OLD_DIR\bin\pg_ctl.exe" unregister -N "$OldServiceID_text"$\r$\n'
377397
nsExec::Exec '"$PG_OLD_DIR\bin\pg_ctl.exe" unregister -N "$OldServiceID_text"'
378398
pop $0
399+
FileWrite $LogFile "pg_ctl.exe unregister return $0 $\r$\n"
379400
DetailPrint "pg_ctl.exe unregister return $0"
380401
${endif}
381402
${endif}
@@ -395,7 +416,7 @@ Section $(componentServer) sec1
395416

396417
;File "License.txt"
397418

398-
FileOpen $LogFile $INSTDIR\install.log w ;Opens a Empty File an fills it
419+
;FileOpen $LogFile $INSTDIR\install.log w ;Opens a Empty File an fills it
399420

400421

401422
CreateDirectory "$INSTDIR\scripts"
@@ -411,7 +432,7 @@ Section $(componentServer) sec1
411432
WriteUninstaller "$INSTDIR\Uninstall.exe"
412433

413434
; write uninstall strings
414-
FileWrite $LogFile "Write to register\r$\n"
435+
FileWrite $LogFile "Write to register$\r$\n"
415436

416437
Call writeUnistallReg
417438

@@ -526,10 +547,10 @@ Section $(componentServer) sec1
526547
pop $0
527548

528549
!insertmacro MUI_STARTMENU_WRITE_END
529-
; Create data dir begin
530-
FileWrite $LogFile "Create data dir begin$\r$\n"
531550

532551
${if} $isDataDirExist == 0
552+
; Create data dir begin
553+
FileWrite $LogFile "Create data dir begin$\r$\n"
533554
CreateDirectory "$DATA_DIR"
534555
;AccessControl::GrantOnFile "$DATA_DIR" "(BU)" "FullAccess" ;GenericWrite
535556
;Pop $0 ;"ok" or "error" + error details
@@ -616,8 +637,8 @@ Section $(componentServer) sec1
616637
${EndIf}
617638
${endif}
618639
; Create data dir end
619-
FileWrite $LogFile "Create postgresql.conf $\r$\n"
620640
${if} $isDataDirExist == 0
641+
FileWrite $LogFile "Create postgresql.conf $\r$\n"
621642
${if} $checkNoLocal_state == ${BST_CHECKED}
622643
!insertmacro _ReplaceInFile "$DATA_DIR\postgresql.conf" "#listen_addresses = 'localhost'" "listen_addresses = '*'"
623644
; Add line to pg_hba.conf
@@ -1362,25 +1383,21 @@ Function nsDialogServerExist
13621383
nsDialogs::Show
13631384
FunctionEnd
13641385

1365-
Function ChecExistDataDir
1366-
${Unless} ${SectionIsSelected} ${sec1}
1367-
Abort
1368-
${EndUnless}
1386+
;check existing datadir function
1387+
Function CheckDataDir
13691388
${If} ${FileExists} "$DATA_DIR\*.*"
13701389
StrCpy $isDataDirExist 1
13711390
${ElseIf} ${FileExists} "$DATA_DIR"
13721391
StrCpy $isDataDirExist -1
13731392
${Else}
13741393
StrCpy $isDataDirExist 0
1375-
Abort
13761394
${EndIf}
1377-
1395+
13781396
${If} ${FileExists} "$DATA_DIR\postgresql.conf"
13791397
ClearErrors
13801398
${ConfigRead} "$DATA_DIR\postgresql.conf" "port" $R0
13811399
${if} ${Errors}
13821400
StrCpy $isDataDirExist 0
1383-
Abort
13841401
${EndIf}
13851402
${StrRep} '$0' '$R0' '=' ''
13861403
${StrRep} '$1' '$0' ' ' ''
@@ -1392,9 +1409,50 @@ Function ChecExistDataDir
13921409
StrCpy $TextPort_text $0
13931410
${Else}
13941411
StrCpy $isDataDirExist 0
1395-
Abort
13961412
${EndIf}
13971413

1414+
1415+
FunctionEnd
1416+
1417+
;check existing datadir dialog
1418+
Function ChecExistDataDir
1419+
${Unless} ${SectionIsSelected} ${sec1}
1420+
Abort
1421+
${EndUnless}
1422+
1423+
Call CheckDataDir
1424+
${if} $isDataDirExist = 0
1425+
Abort
1426+
${endif}
1427+
;${If} ${FileExists} "$DATA_DIR\*.*"
1428+
; StrCpy $isDataDirExist 1
1429+
;${ElseIf} ${FileExists} "$DATA_DIR"
1430+
; StrCpy $isDataDirExist -1
1431+
;${Else}
1432+
; StrCpy $isDataDirExist 0
1433+
; Abort
1434+
;${EndIf}
1435+
1436+
;${If} ${FileExists} "$DATA_DIR\postgresql.conf"
1437+
; ClearErrors
1438+
; ${ConfigRead} "$DATA_DIR\postgresql.conf" "port" $R0
1439+
; ${if} ${Errors}
1440+
; StrCpy $isDataDirExist 0
1441+
; Abort
1442+
; ${EndIf}
1443+
; ${StrRep} '$0' '$R0' '=' ''
1444+
; ${StrRep} '$1' '$0' ' ' ''
1445+
1446+
; StrCpy $0 $1 5
1447+
1448+
; ${StrRep} '$1' '$0' '$\t' ''
1449+
;${StrRep} '$0' '$1' '#' ''
1450+
; StrCpy $TextPort_text $0
1451+
;${Else}
1452+
; StrCpy $isDataDirExist 0
1453+
; Abort
1454+
;${EndIf}
1455+
13981456
${if} $PG_OLD_DIR != "" ;exist PG install
13991457
Abort
14001458
${endif}
@@ -2274,6 +2332,22 @@ ${EndIf}
22742332
StrCpy $isDataChecksums "$1"
22752333
${endif}
22762334

2335+
ReadINIStr $1 $0 options servicesccount
2336+
${if} "$1" != ""
2337+
StrCpy $ServiceAccount_text "$1"
2338+
${endif}
2339+
ReadINIStr $1 $0 options servicepassword
2340+
${if} "$1" != ""
2341+
StrCpy $servicePassword_text "$1"
2342+
${endif}
2343+
ReadINIStr $1 $0 options serviceid
2344+
${if} "$1" != ""
2345+
StrCpy $ServiceID_text "$1"
2346+
${endif}
2347+
ReadINIStr $1 $0 options islibc
2348+
${if} "$1" != ""
2349+
StrCpy $Collation_text "libc"
2350+
${endif}
22772351

22782352

22792353
FunctionEnd

0 commit comments

Comments
 (0)