[wpkg-users] WPKG with multiple systems and architectures

Rainer Meier r.meier at wpkg.org
Mon Jan 26 18:33:16 CET 2009


Hi Daniel,

Daniel Dehennin wrote:
> Hello,
> 
> Is there any best practices to setup WPKG for multiple systems and
> architectures: WinXP32, WinXP64, WinVista32, WinVista64... ?
> 
> My idea is to minimise the number of package definition using
> variables and a good software repository layout, something like:
> 
> \\server\wpkg$\software\<OS>\<ARCH>\<applis>
> or
> \\server\wpkg$\software\<applis>\<OS>\<ARCH>
> 
> Any hints ?

Well, the Reply of David reminded me that I did not answer yet.

So here it comes.

For most applications I use a bunch of cmd scripts to install them.
First of all my generic installer ("install.cmd"). Then I use a simple
"unattended.cmd" batch file which makes use of "install.cmd".
For uninstall I am using a script called "unattended-uninstall.cmd".

The contents are quoted below.

Using these scripts the package definition looks almost the same for
every package:

<?xml version="1.0" encoding="utf-8" ?>
<packages>

<package id='Pidgin' name='Pidgin IM' revision='254' priority='50'
reboot='false' >
  <!-- Pidgin Instant Messaging -->
  <check type='uninstall' condition='exists' path='Pidgin' />
  <install cmd='"%SOFTWARE%\Pidgin v.2.5.4\unattended.cmd"' />
  <remove cmd='"%SOFTWARE%\Pidgin v.2.5.4\unattended-uninstall.cmd"' />
  <upgrade cmd='"%SOFTWARE%\Pidgin v.2.5.4\unattended.cmd"' />
  <depends package-id='GTK' />
</package>
</packages>


Of course some programs might require different checks for 64-bit and
32-bit versions but WPKG supports that - just use logical OR expression
and specify both possibilities.

As you can see below my "unattended.cmd" script allows to specify
different installers for 32-bit (CMD32) and 64-bit (CMD64) packages.
Usually (32-bit only programs) they are identical.


Uninstall is a bit more difficult. For MSI packages it's quite easy
because the "install.cmd" script can be used again - this time supplying
the "msiuninstall" argument. You might just use a copy of the
"unattended.cmd" script and rename it to "unattended-uninstall.cmd" as
well. This also allows to add some pre- and post- execution scripts to
be invoked if they exist.

Other uninstall scripts might require invoking an uninstall EXE file
with specific parameters. My scripts take into account 32-bit and 64-bit
operating systems.



br,
Rainer


#########################
#### isnstall.cmd ####
#########################
@echo off

REM Usage:
REM msiinstall.cmd <type> <32-bit-installer> <64-bit-installer>
[installer-location [custom-options]]
REM where type is one of
REM     msiinstall     Install the given MSI package
REM     msiuninstall   Uninstall the given MSI package
REM     install4j      Install4J setup
REM     innosetup      Inno setup
REM     installshield  Install shield
REM     nsis           Nullsoft install system (NSIS)
REM     custom         Custom installer - options required in this case
REM 32-bit-installer   Full file name (including extension) of 32-bit
installer
REM 64-bit-installer   Full file name (including extension) of 64-bit
installer
REM installer-location Path where the installers are stored, if empty
assumes directory where install.cmd is
REM custom-options     Replace the default installer options with the
ones given

REM Global variables
set INSTALL_CMD=
set EXIT_CODE=0

REM Get command type
set TYPE=%~1

REM Get 32-bit installer name
set CMD32=%~2

REM Get 64-bit installer name
set CMD64=%~3

REM get file path
set INSTALLER_PATH=%~dp0
if not "%~4" == "" (
set INSTALLER_PATH=%~4
)

set OPTIONS=
if not "%~5" == "" (
set OPTIONS=%~5
)


REM Detect which system is used
if not "%ProgramFiles(x86)%" == "" goto 64bit
goto 32bit


REM
##########################################################################
REM 64-bit system detected
REM
##########################################################################
:64bit
REM Determine 64-bit installer to be used
echo 64-bit system detected.
REM set INSTALLER64=
if not "%CMD64%" == "" (
set INSTALLER64=%CMD64%
) else (
REM Use 32-bit installer if available, no 64-bit installer available.
if not "%CMD32%" == "" (
echo Using 32-bit installer, no 64-bit installer specified.
set INSTALLER64=%CMD32%
) else (
echo Neither 64-bit nor 32-bit installer specified. Exiting.
goto usage
)
)

REM Check if installer is valid
if exist "%INSTALLER_PATH%%INSTALLER64%" (
set INSTALL_CMD=%INSTALLER_PATH%%INSTALLER64%
) else (
echo Installer "%INSTALLER_PATH%%INSTALLER64%" cannot be found! Exiting.
exit /B 97
)
goto installerselection


REM
##########################################################################
REM 32-bit system detected
REM
##########################################################################
:32bit
REM Determine 32-bit installer to be used
echo 32-bit system detected.
set INSTALLER32=
if not "%CMD32%" == "" (
set INSTALLER32=%CMD32%
) else (
echo No 32-bit installer specified. Exiting.
exit /B 96
)


REM Check if installer is valid
if exist "%INSTALLER_PATH%%INSTALLER32%" (
set INSTALL_CMD=%INSTALLER_PATH%%INSTALLER32%
) else (
echo Installer "%INSTALLER_PATH%%INSTALLER32%" cannot be found! Exiting.
exit /B 95
)
goto installerselection



REM
##########################################################################
REM select installer system
REM
##########################################################################
:installerselection
if /i "%TYPE%" == "msiinstall"    goto msiinstaller
if /i "%TYPE%" == "msiuninstall"  goto msiuninstaller
if /i "%TYPE%" == "install4j"     goto install4j
if /i "%TYPE%" == "innosetup"     goto innoinstaller
if /i "%TYPE%" == "installshield" goto installshieldinstaller
if /i "%TYPE%" == "nsis"          goto nsisinstaller
if /i "%TYPE%" == "custom"        goto custominstaller
goto usage



:msiinstaller
echo Installing "%INSTALL_CMD%"
if "%OPTIONS%" == "" (
set OPTIONS=/qn /norestart
)
start /wait "Software installation" msiexec /i "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end


:msiuninstaller
echo Uninstalling "%INSTALL_CMD%"
if "%OPTIONS%" == "" (
set OPTIONS=/qn /norestart
)
start /wait "Software uninstallation" msiexec /x "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end


:install4j
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" -q %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end


:innoinstaller
echo Installing "%INSTALL_CMD%"
REM if "%OPTIONS%" == "" (
REM set OPTIONS=/verysilent /norestart /sp-
REM )
start /wait "Software installation" "%INSTALL_CMD%" /verysilent
/norestart /sp- %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end


:installshieldinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" /s %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end


:nsisinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" /S %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end

:custominstaller
if "%OPTIONS%" == "" goto usage
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEEL%
goto end

:usage
echo Usage:
echo "%~nx0 <type> <32-bit-installer> <64-bit-installer>
[installer-location [custom-options]]"
echo where type is one of
echo     msiinstall        Install the given MSI package
echo     msiuninstall      Uninstall the given MSI package
echo     innosetup         Inno setup
echo     installshield     Install shield
echo     nsis              Nullsoft install system (NSIS)
echo     custom            Custom installer - options required in this case
echo 32-bit-installer      Full file name (including extension) of
32-bit installer
echo 64-bit-installer      Full file name (including extension) of
64-bit installer
echo installer-location    Path where the installers are stored
echo custom-options        Replace the default installer options with
the ones given
exit /B 99

:end
exit /B %EXIT_CODE%

#########################
#### /install.cmd ####
#########################


#########################
#### unattended.cmd ####
#########################
@echo off

set PROGRAM_NAME=Application
set CMD32=installer.exe
set CMD64=%CMD32%
set INSTALLER_TYPE=nsis
set INSTALLER=install.cmd
set INSTALLER_LOC=%~dp0
set CMDPATH=%~dpn0


if exist "%INSTALLER_LOC%unattended-preinstall.cmd" (
	call "%INSTALLER_LOC%unattended-preinstall.cmd"
	if "%~n0" == "unattended" goto install
)

if exist "%CMDPATH%-preinstall.cmd" (
	call "%CMDPATH%-preinstall.cmd"
)

:install
echo Installing %PROGRAM_NAME%

set PROGRAM_FILES=%ProgramFiles%
if not "%ProgramFiles(x86)%" == "" set PROGRAM_FILES=%ProgramFiles(x86)%

call "%INSTALLER_LOC%%INSTALLER%" %INSTALLER_TYPE% "%CMD32%" "%CMD64%"
set EXIT_CODE=%ERRORLEVEL%

if exist "%CMDPATH%-postinstall.cmd" (
	call "%CMDPATH%-postinstall.cmd"
	if "%~n0" == "unattended" goto end
)

if exist "%INSTALLER_LOC%unattended-postinstall.cmd" (
	call "%INSTALLER_LOC%unattended-postinstall.cmd"
)

:end
exit /B %EXIT_CODE%
#########################
#### /unattended.cmd ####
#########################


##################################
#### unattended-uninstall.cmd ####
#### script for MSI packages  ####
##################################
@echo off

set PROGRAM_NAME=Program
set CMD32=package.msi
set CMD64=%CMD32%
set INSTALLER=install.cmd
set INSTALLER_LOC=%~dp0

echo Removing %PROGRAM_NAME%

call "%INSTALLER_LOC%%INSTALLER%" msiuninstall "%CMD32%" "%CMD64%"
###################################
#### /unattended-uninstall.cmd ####
#### script for MSI packages   ####
###################################


################################################
#### unattended-uninstall.cmd               ####
#### script for silent uninstaller program  ####
################################################
@echo off

echo Removing Application

set PROGRAM_FILES=%ProgramFiles%
if not "%ProgramFiles(x86)%" == "" set PROGRAM_FILES=%ProgramFiles(x86)%

start /wait "Remove" "%PROGRAM_FILES%\Program\Uninstall.exe" /S
################################################
#### unattended-uninstall.cmd               ####
#### script for silent uninstaller program  ####
################################################


##################################################################
#### unattended-uninstall.cmd                                 ####
#### extended versions for "tricky" installers like VLC which ####
#### forks a child process                                    ####
##################################################################
@echo off

echo Removing Program

set PROGRAM_FILES=%ProgramFiles%
if not "%ProgramFiles(x86)%" == "" set PROGRAM_FILES=%ProgramFiles(x86)%

set APP_DIR=%PROGRAM_FILES%\Program
set UNINSTALLER=%APP_DIR%\uninst.exe
set OPTIONS=/S


if not exist "%UNINSTALLER%" goto good_end
start /wait "Uninstall" "%UNINSTALLER%" %OPTIONS%
REM Unfortunately the uninstaller seems to fork a child process and the
parent
REM process exits immediately. So give it some time to uninstall
for /L %%C IN (1,1,30) DO (
  if not exist "%UNINSTALLER%" goto good_end
  ping -n 2 127.0.0.1 > NUL
)
:bad_end
exit /B 1

:good_end
if exist "%APP_DIR%" rmdir /s /q "%APP_DIR%"
exit /B 0
##################################################################
#### unattended-uninstall.cmd                                 ####
#### extended versions for "tricky" installers like VLC which ####
#### forks a child process                                    ####
##################################################################



More information about the wpkg-users mailing list