for %%f in (*.block) do set blockName=%%~nf
if "%BlockName%"=="" set BlockName=[Block name not found]

REM	*********************************************************************************
REM	*		Set up logging folders and file locations			*
REM	*********************************************************************************
if not defined log set log=c:\hp\bin\logS
if not exist %log%\hpu md %log%\hpu
if not defined BlockLog goto COMMANDS
Set CurrentLog=%BlockLog%

echo off
@echo	%date% %time% Copyright (c) Hewlett-Packard Development Company L.P., 2001-2006  > %CurrentLog%
@echo	*******************************************************************************
@echo		Spring '07						>> %CurrentLog%
@echo		install.bat						>> %CurrentLog%
@echo		HP Software Update Stand-Alone				>> %CurrentLog%
@echo		Languages: en,fr,es,it,no,fi,du,da,de,pt,sv,sc,tc,trk,	>> %CurrentLog%
@echo			cz,gr,hu,ja,Ko,pol,rus,				>> %CurrentLog%
@echo		Default Lang: ENGLISH 					>> %CurrentLog%
@echo		
@echo		
@echo		  
@echo	Block Creation Date:	August 3, 2006				>> %CurrentLog%
@echo	*******************************
REM	Notes:
REM	1.  HPSU stand alone should not
REM	be uninstalled with any other CUE
REM	software.
REM	2.  REG file populates reg key
REM	with data to reset launch clock
REM	back to zero.
@echo	3.  Product name is now HP UPDATE				>> %CurrentLog%	
@echo	HP Software Update is deprecated.				>> %CurrentLog%
@echo	***********************************************************  	>> %CurrentLog%
REM	4. New version delivered on 13Sep06.
REM	5. 31Oct..Added PostInstall.bat to be run by HPQware after OOBE
REM		It will reset the lastrun key in registry to '0'
REM		This should fix any issues with the 'Welcome to HP Udate'
REM		popup from appearing on first customer boot. See IMS#58004
REM
REM	Revisions:
REM
REM @echo %date% %time% "BEGIN INSTALLATION ":  Verify environ variable and folders are created ....  >> %CurrentLog%  
 
@echo	%date% %time% "BLOCK INSTALLATION ":  installing block %BlockName% >> %CurrentLog% 
@echo 	%date% %time% "DETERMINE INSTALLATION MODE ": Is this an App Recovery mode? >> %CurrentLog%
if not exist "c:\blocks\allblocks" goto APPRECOV

@echo	%date% %time% "DETERMINE INSTALLATION MODE ": No, so this is the first time through.  >> %CurrentLog%
@echo	%date% %time% "INITIATE FILE COPY ": Begin file copy... >> %CurrentLog%
Xcopy "c:\hp\tmp\src\*.bat" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
Xcopy "c:\hp\tmp\src\*.exe" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
Xcopy "c:\hp\tmp\src\*.ini" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
Xcopy "c:\hp\tmp\src\*.msi" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
Xcopy "c:\hp\tmp\src\*.cab" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
Xcopy "c:\hp\tmp\src\*.mst" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
xcopy "c:\hp\tmp\src\*.reg" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
xcopy "c:\hp\tmp\src\*.cva" "c:\hp\drivers\hpsu" %xflags% >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
REM xcopy "c:\hp\tmp\ReSchedHPSU.*" "c:\hp\drivers\hpsu" /y /i >> %CurrentLog%
REM If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL
xcopy "c:\hp\tmp\Postuser.*" "c:\hp\hpqware\hpudate" /y /i >> %CurrentLog%
If %ERRORLEVEL% GEQ 1 CALL :FILECOPYFAIL

pushd c:\hp\drivers\hpsu
rem @echo	%date% %time% "Rescheduler":  place ReschedHPSU link in all users start menu ... >> %CurrentLog%
rem xcopy "c:\hp\drivers\hpsu\ReSchedHPSU.lnk" "%common startup%" /y /i >> %CurrentLog%

@echo	%date% %time% "BEGIN PACKAGE INSTALLATION ": File copy complete. Launch MSI... >> %CurrentLog%
start /w msiexec.exe /i "c:\hp\drivers\hpsu\hp update.msi" /qn INSTALLDIR="%programfiles%\HP" /L*v %PkgInstallLog%
@echo	%date% %time% "ERROR LEVEL ": error level = %ERRORLEVEL% >> %CurrentLog%
if %ERRORLEVEL% GEQ 1 goto MSIINSTALLERROR
@echo	%date% %time% "CLEANUP ":  MSI install complete. Remove Install.bat file... >> %CurrentLog%
if exist c:\hp\drivers\hpsu\install.bat del /q c:\hp\drivers\hpsu\install.bat
popd

rem @echo	%date% %time% "CLEANUP ":  Remove HPU startup from Run key... >> %CurrentLog%
rEM reg delete "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v "HP Software Update" /f >> %CurrentLog%

@echo	%date% %time% "CLEANUP ":  Set HPSU LastRun key to DWORD 0 in registry >> %CurrentLog%
reg add "HKLM\SOFTWARE\Hewlett-Packard\HP Software Update" /f /v LastRun /t REG_DWORD /d "0x00000000" >> %CurrentLog%
@echo	%date% %time% "CLEANUP ":  Set HPSU Notify key to DWORD 1 in registry >> %CurrentLog%
Reg add "HKLM\Software\Hewlett-Packard\HP Software Update" /v "Notify" /t REG_DWORD /d "1" /f >> %CurrentLog%
@echo	%date% %time% "CLEANUP ":  Set HPSU Never key to DWORD 0 in registry >> %CurrentLog%
Reg add "HKLM\Software\Hewlett-Packard\HP Software Update" /v "Never" /t REG_DWORD /d "0" /f >> %CurrentLog%
@echo	%date% %time% "CLEANUP ":  Set HPSU ndays key to DWORD 7 in registry >> %CurrentLog%
Reg add "HKLM\Software\Hewlett-Packard\HP Software Update" /v "ndays" /t REG_DWORD /d "7" /f >> %CurrentLog%

@echo	%date% %time% "EIS SETUP ": Make EIS Registry entries >>%CurrentLog%
@echo	********************************************************* >> %CurrentLog%
@echo	*      4     EASY SETUP REGISTRY ENTRIES 		* >> %CurrentLog%
@echo	********************************************************* >> %CurrentLog%

reg add HKLM\Software\Hewlett-Packard\cpc\PCINTRO\HPSU /f /v OptInPath /d "c:\hp\bin\cloaker.exe" >> %CurrentLog%
reg add HKLM\Software\Hewlett-Packard\cpc\PCINTRO\HPSU /f /v OptInCmdLine /d "c:\hp\drivers\hpsu\HPSU_optin.bat" >> %CurrentLog%
reg add HKLM\Software\Hewlett-Packard\cpc\PCINTRO\HPSU /f /v OptOutPath /d "c:\hp\bin\cloaker.exe" >> %CurrentLog%
reg add HKLM\Software\Hewlett-Packard\cpc\PCINTRO\HPSU /f /v OptOutCmdLine /d "c:\hp\drivers\hpsu\HPSU_optout.bat" >> %CurrentLog%
@echo  %date% %time% "EIS SETUP COMPLETE ": ...registry entries completed. >> %CurrentLog%

goto END

:APPRECOV
Set CurrentLog=%BlockReinstall%
@echo	%date% %time% "DETERMINE INSTALLATION MODE ": Beginning Application Recovery for HPU. > %CurrentLog%
@echo	********************************************************* >> %CurrentLog%
pushd c:\hp\drivers\hpsu
@echo	%date% %time% "BEGIN PACKAGE INSTALLATION ": Begin execution of MSI installer... >> %CurrentLog%
@echo	%date% %time% "BEGIN PACKAGE INSTALLATION ": Reinstalling from c:\hp\drivers\hpsu folder... >> %CurrentLog%
@echo	%date% %time% "BEGIN PACKAGE INSTALLATION ": Verify source files exist.  >> %CurrentLog%
If not exist c:\hp\drivers\hpsu goto NOSOURCEFILES
start /w msiexec.exe /i "c:\hp\drivers\hpsu\hp update.msi" /qn INSTALLDIR="%programfiles%\HP" /L*v %PkgReinstallLog%
@echo	%date% %time% "ERROR LEVEL ": error level = %ERRORLEVEL% >> %CurrentLog%
if %ERRORLEVEL% GEQ 1 goto MSIREINSTALLERROR
@echo   %date% %time% "OPT-IN SET ": Since this is recovery mode, automatically opt-in. >> %CurrentLog%
call c:\hp\bin\cloaker.exe c:\hp\drivers\hpsu\hpsu_optin.bat >> %CurrentLog%
popd
@echo	%date% %time% "HPU RECOVERY COMPLETE ":  Recovery of HPU completed successfully. >> %CurrentLog%

:END

@echo	%date% %time% "END PROCESS ": the %BlockName% block has installed successfully. >> %CurrentLog%
@echo		*********************************************************************** >> %CurrentLog%
@echo			Verify source files  >> %CurrentLog%
@echo			in c:\hp\drivers\hpsu  >> %CurrentLog%
@echo		*******************************  >> %CurrentLog%
EXIT /b

REM	*************************************************************************
REM	*			ERROR TRAPS					*
REM	*************************************************************************

:COMMANDS
@echo Commands not running. If no other errors, type INSTALL at next prompt.
call c:\hp\bin\commands /LW:lg.ini
if %ERRORLEVEL% GEQ 1 goto FATALERROR
exit

:FATALERROR
@echo %date% %time% "FATAL ERROR ": Error Lever = %ErrorLevel% 
@echo %date% %time% "FATAL ERROR ":  Commands still not running.
@echo %date% %time% "FATAL ERROR ":  Either Commands or HPBI or both are missing. 
@echo %date% %time% "FATAL ERROR ":  Copy these files to the hp\bin folder before continuing.
@echo %date% %time% "FATAL ERROR ":  Then try again.
@echo **************************************************************************
pause 
exit

:BLOCKFAIL
@echo ************************************************************************** >> %CurrentLog%
@echo	%date% %time% "ERROR LEVEL ": error level = %ERRORLEVEL% >> %CurrentLog%
@echo %date% %time% "FATAL ERROR ":  Block installation terminated prematurely. Installation not successful. >> %CurrentLog%
@echo ************************************************************************** >> %CurrentLog%
exit /b

:FILECOPYFAIL
@echo %date% %time% "FILE COPY ERROR ": HPU file copy failed in %BlockName%. Notify component owner. >> %CurrentLog%
exit /b

:MSIINSTALLERROR
@echo %date% %time% "MSI INSTALL ERROR": Error Lever = %ErrorLevel% >> %CurrentLog%
@echo %date% %time% "MSI INSTALL ERROR": notify %BlockName% component owner >> %CurrentLog%
@echo %date% %time% "FATAL ERROR ":  Block installation terminated prematurely. Installation not successful. >> %CurrentLog%
@echo ************************************************************************** >> %CurrentLog%
exit /b

:MSIREINSTALLERROR
@echo %date% %time% "MSI INSTALL ERROR": notify %BlockName% component owner >> %CurrentLog%
@echo %date% %time% "FATAL ERROR ":  Block installation terminated prematurely. Installation not successful. >> %CurrentLog%
@echo ************************************************************************** >> %CurrentLog%
exit /b

:NOSOURCEFILES
@echo %date% %time% "NO SOURCE FILES ERROR": Source files have been removed from system. >> %CurrentLog%
@echo %date% %time% "FATAL ERROR ":  Reinstallation terminated prematurely. Reinstallation not successful. >> %CurrentLog%
@echo ************************************************************************** >> %CurrentLog%
exit /b
