User:Dad

From WPKG | Open Source Software Deployment and Distribution

Jump to: navigation, search

Daniel Dehennin


[edit] Using unattended script

I'm using unattened script from Rainer Meier with some modifications:

  • Engine is unattended.cmd
  • Install scripts are called install.cmd
  • Uninstall scripts are called remove.cmd
  • Add msiupdate installtype
  • Execute start commande with /D"%INSTALLER_PATH%": if the %INSTALL_CMD% is located in a subdirectory it may need to locate files relativelly to its path.
  • Automatically call pre/post-install/remove scripts:
    • preinstall.cmd/postinstall.cmd/preremove.cmd/postremove.cmd in installer path
    • preinstall.cmd/postinstall.cmd/preremove.cmd/postremove.cmd in unattended path
    •  %INSTALL_CMD%-preinstall.cmd/%INSTALL_CMD%-postinstall.cmd/%INSTALL_CMD%-preremove.cmd/%INSTALL_CMD%-postremove.cmd
@echo off
 
REM Do not export variables
SETLOCAL
 
set PROGRAM_NAME=Application
 
REM Command to run
set CMD32=installer.exe
set CMD64=%CMD32%
set CMD_PATH=%~dp0
set CMD_OPTS=/SILENT
 
REM Unattended installer
set INSTALLER=unattended.cmd
set INSTALLER_TYPE=custominstall
set INSTALLER_LOC=%~dp0
 
REM :ospath
REM
REM ver | find "version 5.1" > NUL && (
REM     SET CMD_PATH=%CMD_PATH%winxp
REM )
REM
REM ver | find "version 6.0" > NUL && (
REM     SET CMD_PATH=%CMD_PATH%winvista
REM )
REM
REM ver | find "version 6.1" > NUL && (
REM     SET CMD_PATH=%CMD_PATH%win7
REM )
 
:install
echo Installing %PROGRAM_NAME%
 
call "%INSTALLER_LOC%%INSTALLER%" %INSTALLER_TYPE% "%CMD32%" "%CMD64%" "%CMD_PATH%" "%CMD_OPTS%"
set EXIT_CODE=%ERRORLEVEL%
 
 
:end
exit /B %EXIT_CODE%
 
REM End of local variables
ENDLOCAL
 
REM Local Variables:
REM mode: cmd
REM comment-start: "REM "
REM comment-end: ""
REM End:
@echo off
 
REM Usage:
 
REM unattended.cmd <type> <32-bit-installer> <64-bit-installer>
REM                <installer-location> [[custom-options]]
 
REM where type is one of
REM     msiinstall       Install the given MSI package
REM     msiupdate        Update the given MSP package
REM     msiuninstall     Uninstall the given MSI package
REM     install4j        Install4J setup
REM     innoinstall      Inno setup installer
REM     innouninstall    Inno setup uninstaller
REM     installshield    Install shield
REM     nsis             Nullsoft install system (NSIS)
REM     custominstall    Custom installer - options required in this case
REM     custounminstall  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
REM                      directory where install.cmd is
REM custom-options       Replace the default installer options with the ones given
 
REM Do not export variables
SETLOCAL
 
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=%~4
 
REM get unattended path
set SCRIPTS_PATH=%~dp0
 
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/uninstaller system with pre-install/remove
REM
##########################################################################
:installerselection
 
if /i "%TYPE%" == "msiuninstall"    goto preremove
if /i "%TYPE%" == "innouninstall"   goto preremove
if /i "%TYPE%" == "customuninstall" goto preremove
 
:preinstall
REM pre-install
if exist "%INSTALLER_PATH%preinstall.cmd" (
   call "%INSTALLER_PATH%preinstall.cmd"
)
if exist "%SCRIPT_PATH%%preinstall.cmd" (
   call "%SCRIPTS_PATH%preinstall.cmd"
)
if exist "%INSTALL_CMD%-preinstall.cmd" (
   call "%INSTALL_CMD%-preinstall.cmd"
)
 
if /i "%TYPE%" == "msiinstall"    goto msiinstaller
if /i "%TYPE%" == "msiupdate"     goto msiupdate
if /i "%TYPE%" == "install4j"     goto install4j
if /i "%TYPE%" == "innoinstall"   goto innoinstaller
if /i "%TYPE%" == "installshield" goto installshieldinstaller
if /i "%TYPE%" == "nsis"          goto nsisinstaller
if /i "%TYPE%" == "custominstall" goto custominstaller
goto usage
 
:preremove
REM pre-install
if exist "%INSTALLER_PATH%preremove.cmd" (
   call "%INSTALLER_PATH%preremove.cmd"
)
if exist "%SCRIPTS_PATH%preremove.cmd" (
   call "%SCRIPTS_PATH%preremove.cmd"
)
if exist "%INSTALL_CMD%-preremove.cmd" (
   call "%INSTALL_CMD%-preremove.cmd"
)
 
if /i "%TYPE%" == "msiuninstall"    goto msiuninstaller
if /i "%TYPE%" == "innouninstall"   goto innouninstaller
if /i "%TYPE%" == "customuninstall" goto customuninstaller
goto usage
 
 
:msiinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" /D"%INSTALLER_PATH%" msiexec /qn /norestart /i "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postinstall
 
 
:msiupdate
echo Updating "%INSTALL_CMD%"
start /wait "Software update" /D"%INSTALLER_PATH%" msiexec /qn /norestart /update "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postinstall
 
 
:msiuninstaller
echo Uninstalling "%INSTALL_CMD%"
start /wait "Software uninstallation" /D"%INSTALLER_PATH%" msiexec /qn /norestart /x "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postremove
 
 
:install4j
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" -q %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto end
 
 
:innoinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" /verysilent /norestart /sp- %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postinstall
 
:innouninstaller
echo Uninstalling "%INSTALL_CMD%"
start /wait "Software uninstallation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" /verysilent /norestart /sp- %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postremove
 
 
:installshieldinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" /s %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postinstall
 
 
:nsisinstaller
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" /S %OPTIONS%
set EXIT_CODE=%ERRORLEVEL%
goto postinstall
 
:custominstaller
if "%OPTIONS%" == "" goto usage
echo Installing "%INSTALL_CMD%"
start /wait "Software installation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEEL%
goto postinstall
 
:customuninstaller
if "%OPTIONS%" == "" goto usage
echo Uninstalling "%INSTALL_CMD%"
start /wait "Software uninstallation" /D"%INSTALLER_PATH%" "%INSTALL_CMD%" %OPTIONS%
set EXIT_CODE=%ERRORLEEL%
goto postremove
 
: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     msiupdate        Update the given MSP package
echo     msiuninstall     Uninstall the given MSI package
echo     install4j        Install4J setup
echo     innoinstall      Inno setup installer
echo     innouninstall    Inno setup uninstaller
echo     installshield    Install shield
echo     nsis             Nullsoft install system (NSIS)
echo     custominstall    Custom installer - options required in this case
echo     customuninstall  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, if empty assumes
echo                      directory where install.cmd is
echo custom-options       Replace the default installer options with the ones given
exit /B 99
 
:postinstall
REM post-install
if exist "%INSTALLER_PATH%postinstall.cmd" (
   call "%INSTALLER_PATH%postinstall.cmd"
)
if exist "%SCRIPTS_PATH%postinstall.cmd" (
   call "%SCRIPTS_PATH%postinstall.cmd"
)
if exist "%INSTALL_CMD%-postinstall.cmd" (
   call "%INSTALL_CMD%-postinstall.cmd"
)
goto end
 
:postremove
REM post-remove
if exist "%INSTALLER_PATH%postremove.cmd" (
   call "%INSTALLER_PATH%postremove.cmd"
)
if exist "%SCRIPTS_PATH%postremove.cmd" (
   call "%SCRIPTS_PATH%postremove.cmd"
)
if exist "%INSTALL_CMD%-postremove.cmd" (
   call "%INSTALL_CMD%-postremove.cmd"
)
 
:end
exit /B %EXIT_CODE%
 
REM End of local variables
ENDLOCAL
 
REM Local Variables:
REM mode: cmd
REM comment-start: "REM "
REM comment-end: ""
REM End:
Retrieved from "http://wpkg.org/User:Dad"
Personal tools