Skip to content

Commit

Permalink
[IMP] packaging: add a new install type for windows
Browse files Browse the repository at this point in the history
In order to be able to use odoo#86723 Odoo needs to be used as a local
proxy. With this commit, a new install type `Local Proxy Mode` is added
to the windows installer. When chosen, this install type does not
install the PostgreSQL server and it adds the `hw_l10n_eg_eta` as a
server wide module. It also generate and sets a proxy token.

While at it, the windows packaging is a bit improved:
* the VM now uses the virtio drivers
* the installer size and speed is improved

X-original-commit: 8586f78
Part-of: odoo#92195
  • Loading branch information
d-fence authored and jco-odoo committed May 24, 2022
1 parent bd3c681 commit 53d00c7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion setup/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def start(self):
"-net", "nic,model=e1000e,macaddr=52:54:00:d3:38:5e",
"-net", "user,hostfwd=tcp:127.0.0.1:10022-:22,hostfwd=tcp:127.0.0.1:18069-:8069,hostfwd=tcp:127.0.0.1:15432-:5432",
"-m", "2048",
"-drive", "file=%s,snapshot=on" % self.image,
"-drive", f"if=virtio,file={self.image},snapshot=on",
"-nographic",
"-serial", "none",
]
Expand Down
100 changes: 74 additions & 26 deletions setup/win32/setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ Unicode True
Name '${DISPLAY_NAME}'
Caption "${PRODUCT_NAME} ${VERSION} Setup"
OutFile "odoo_setup_${VERSION}.exe"
SetCompressor /FINAL lzma
ShowInstDetails show
SetCompressor /SOLID /FINAL lzma
ShowInstDetails hide

BrandingText '${PRODUCT_NAME} ${VERSION}'

Expand All @@ -112,6 +112,11 @@ Var HWNDPostgreSQLPort
Var HWNDPostgreSQLUsername
Var HWNDPostgreSQLPassword

Var ProxyTokenDialog
Var ProxyTokenLabel
Var ProxyTokenText
Var ProxyTokenPwd

!define STATIC_PATH "static"
!define PIXMAPS_PATH "${STATIC_PATH}\pixmaps"

Expand All @@ -133,7 +138,7 @@ Var HWNDPostgreSQLPassword
Page Custom ShowPostgreSQL LeavePostgreSQL
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

Page Custom ShowProxyTokenDialogPage
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_CHECKED
Expand Down Expand Up @@ -167,10 +172,12 @@ LangString DESC_PostgreSQL_Hostname ${LANG_ENGLISH} "Hostname"
LangString DESC_PostgreSQL_Port ${LANG_ENGLISH} "Port"
LangString DESC_PostgreSQL_Username ${LANG_ENGLISH} "Username"
LangString DESC_PostgreSQL_Password ${LANG_ENGLISH} "Password"
LangString Profile_AllInOne ${LANG_ENGLISH} "All In One"
LangString Profile_Server ${LANG_ENGLISH} "Server only"
LangString Profile_AllInOne ${LANG_ENGLISH} "Odoo Server And PostgreSQL Server"
LangString Profile_Server ${LANG_ENGLISH} "Odoo Server Only"
LangString Profile_LocalProxyMode ${LANG_ENGLISH} "Local Proxy Mode"
LangString TITLE_Odoo_Server ${LANG_ENGLISH} "Odoo Server"
LangString TITLE_PostgreSQL ${LANG_ENGLISH} "PostgreSQL Database"
LangString TITLE_LocalProxyMode ${LANG_ENGLISH} "Local Proxy Mode"
LangString DESC_FinishPageText ${LANG_ENGLISH} "Start Odoo"

; French
Expand All @@ -188,17 +195,21 @@ LangString DESC_PostgreSQL_Hostname ${LANG_FRENCH} "Hôte"
LangString DESC_PostgreSQL_Port ${LANG_FRENCH} "Port"
LangString DESC_PostgreSQL_Username ${LANG_FRENCH} "Utilisateur"
LangString DESC_PostgreSQL_Password ${LANG_FRENCH} "Mot de passe"
LangString Profile_AllInOne ${LANG_FRENCH} "All In One"
LangString Profile_Server ${LANG_FRENCH} "Seulement le serveur"
LangString Profile_AllInOne ${LANG_FRENCH} "Serveur Odoo Et Serveur PostgreSQL"
LangString Profile_Server ${LANG_FRENCH} "Seulement Le Serveur Odoo"
LangString Profile_LocalProxyMode ${LANG_FRENCH} "Mode Proxy Local"
LangString TITLE_Odoo_Server ${LANG_FRENCH} "Serveur Odoo"
LangString TITLE_PostgreSQL ${LANG_FRENCH} "Installation du serveur de base de données PostgreSQL"
LangString TITLE_LocalProxyMode ${LANG_FRENCH} "Mode Proxy Local"
LangString DESC_FinishPageText ${LANG_FRENCH} "Démarrer Odoo"

InstType /NOCUSTOM
InstType $(Profile_AllInOne)
InstType $(Profile_Server)
InstType $(Profile_LocalProxyMode)

Section $(TITLE_Odoo_Server) SectionOdoo_Server
SectionIn 1 2
SectionIn 1 2 3

# Installing winpython
SetOutPath "$INSTDIR\python"
Expand All @@ -212,7 +223,7 @@ Section $(TITLE_Odoo_Server) SectionOdoo_Server
File /r /x "src" "${TOOLSDIR}\nssm-2.24\*"

SetOutPath "$INSTDIR\server"
File /r /x "wkhtmltopdf" "..\..\*"
File /r /x "wkhtmltopdf" /x "enterprise" "..\..\*"

SetOutPath "$INSTDIR\vcredist"
File /r "${TOOLSDIR}\vcredist\*.exe"
Expand Down Expand Up @@ -246,23 +257,20 @@ Section $(TITLE_Odoo_Server) SectionOdoo_Server
DetailPrint "Installing Windows service"
nsExec::ExecTOLog '"$INSTDIR\python\python.exe" "$INSTDIR\server\odoo-bin" --stop-after-init --logfile "$INSTDIR\server\odoo.log" -s'
${If} ${RunningX64}
nsExec::ExecToLog '"$INSTDIR\nssm\win64\nssm.exe" install ${SERVICENAME} "$INSTDIR\python\python.exe" "\"$INSTDIR\server\odoo-bin\""'
nsExec::ExecToLog '"$INSTDIR\nssm\win64\nssm.exe" set ${SERVICENAME} AppDirectory "$\"$INSTDIR\server$\""'
nsExec::ExecToLog '"$INSTDIR\nssm\win64\nssm.exe" install ${SERVICENAME} "$INSTDIR\python\python.exe"'
nsExec::ExecToLog '"$INSTDIR\nssm\win64\nssm.exe" set ${SERVICENAME} AppDirectory "$\"$INSTDIR\python$\""'
nsExec::ExecToLog '"$INSTDIR\nssm\win64\nssm.exe" set ${SERVICENAME} AppParameters "\"$INSTDIR\server\odoo-bin\" -c "\"$INSTDIR\server\odoo.conf\"'
${Else}
nsExec::ExecToLog '"$INSTDIR\nssm\win32\nssm.exe" install ${SERVICENAME} "$INSTDIR\python\python.exe" "\"$INSTDIR\server\odoo-bin\""'
nsExec::ExecToLog '"$INSTDIR\nssm\win32\nssm.exe" set ${SERVICENAME} AppDirectory "$\"$INSTDIR\server$\""'
nsExec::ExecToLog '"$INSTDIR\nssm\win32\nssm.exe" install ${SERVICENAME} "$INSTDIR\python\python.exe" '
nsExec::ExecToLog '"$INSTDIR\nssm\win32\nssm.exe" set ${SERVICENAME} AppDirectory "$\"$INSTDIR\python$\""'
nsExec::ExecToLog '"$INSTDIR\nssm\win32\nssm.exe" set ${SERVICENAME} AppParameters "\"$INSTDIR\server\odoo-bin\" -c "\"$INSTDIR\server\odoo.conf\"'
${EndIf}

nsExec::Exec "net stop ${SERVICENAME}"
sleep 2

nsExec::Exec "net start ${SERVICENAME}"
sleep 2

Call RestartOdooService
SectionEnd

Section $(TITLE_PostgreSQL) SectionPostgreSQL
SectionIn 1 2
SectionIn 1
SetOutPath '$TEMP'
VAR /GLOBAL postgresql_exe_filename
VAR /GLOBAL postgresql_url
Expand All @@ -276,7 +284,8 @@ Section $(TITLE_PostgreSQL) SectionPostgreSQL
StrCpy $postgresql_url "https://get.enterprisedb.com/postgresql/$postgresql_exe_filename"
nsExec::Exec 'net user openpgsvc /delete'

inetc::get "$postgresql_url" "$TEMP/$postgresql_exe_filename" /POPUP
DetailPrint "Downloading PostgreSQl"
inetc::get "$postgresql_url" "$TEMP/$postgresql_exe_filename" /POPUP
pop $0

ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
Expand All @@ -286,6 +295,7 @@ Section $(TITLE_PostgreSQL) SectionPostgreSQL
ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
done:
Rmdir /r "$INSTDIR\PostgreSQL"
DetailPrint "Installing PostgreSQL"
ExecWait '"$TEMP\$postgresql_exe_filename" \
--mode unattended \
--prefix "$INSTDIR\PostgreSQL" \
Expand All @@ -296,6 +306,18 @@ Section $(TITLE_PostgreSQL) SectionPostgreSQL
--serverport $TextPostgreSQLPort'
SectionEnd

Section $(TITLE_LocalProxyMode) LocalProxy
SectionIn 3
DetailPrint "Configuring Local Proxy Mode"
WriteIniStr "$INSTDIR\server\odoo.conf" "options" "server_wide_modules" "base,web,hw_l10n_eg_eta"
WriteIniStr "$INSTDIR\server\odoo.conf" "options" "list_db" "False"
WriteIniStr "$INSTDIR\server\odoo.conf" "options" "max_cron_thread" "0"
nsExec::ExecToStack '"$INSTDIR\python\python.exe" "$INSTDIR\server\odoo-bin" genproxytoken'
pop $0
pop $ProxyTokenPwd
Call RestartOdooService
SectionEnd

Section -Post
WriteRegExpandStr HKLM "${UNINSTALL_REGISTRY_KEY}" "UninstallString" "$INSTDIR\Uninstall.exe"
WriteRegExpandStr HKLM "${UNINSTALL_REGISTRY_KEY}" "InstallLocation" "$INSTDIR"
Expand Down Expand Up @@ -399,11 +421,9 @@ Function PostgreSQLOnBack
FunctionEnd

Function ShowPostgreSQL
SectionGetFlags ${SectionOdoo_Server} $0
IntOp $0 $0 & ${SF_SELECTED}
IntCmp $0 ${SF_SELECTED} LaunchPostgreSQLConfiguration
Abort
LaunchPostgreSQLConfiguration:
GetCurInstType $R0
IntCmp $R0 1 bypassPostgresConfig
Intcmp $R0 2 bypassPostgresConfig

nsDialogs::Create /NOUNLOAD 1018
Pop $0
Expand Down Expand Up @@ -437,6 +457,7 @@ Function ShowPostgreSQL
Pop $HWNDPostgreSQLPassword

nsDialogs::Show
bypassPostgresConfig:
FunctionEnd

Function LeavePostgreSQL
Expand Down Expand Up @@ -469,6 +490,27 @@ Function LeavePostgreSQL
${EndIf}
FunctionEnd

Function ShowProxyTokenDialogPage
GetCurInstType $R0
IntCmp $R0 2 doProxyToken bypassProxyToken
doProxyToken:
nsDialogs::Create 1018
Pop $ProxyTokenDialog
${IF} $ProxyTokenDialog == !error
Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 25% "Here is your access token for the Odoo Local Proxy, please write it down in a safe place, you will need it to configure the proxy"
Pop $ProxyTokenLabel

${NSD_CreateText} 0 30% 100% 13u $ProxyTokenPwd
Pop $ProxyTokenText
${NSD_Edit_SetreadOnly} $ProxyTokenText 1
${NSD_AddStyle} $ProxyTokenText ${SS_CENTER}
nsDialogs::Show
bypassProxyToken:
FunctionEnd

Function ComponentLeave
SectionGetFlags ${SectionOdoo_Server} $0
IntOp $0 $0 & ${SF_SELECTED}
Expand All @@ -487,3 +529,9 @@ FunctionEnd
Function LaunchLink
ExecShell "open" "http://localhost:8069/"
FunctionEnd

Function RestartOdooService
DetailPrint "Restarting Odoo Service"
ExecWait "net stop ${SERVICENAME}"
ExecWait "net start ${SERVICENAME}"
FunctionEnd

0 comments on commit 53d00c7

Please sign in to comment.