-
Notifications
You must be signed in to change notification settings - Fork 79
/
microsoft_offline_update_launcher.bat
131 lines (103 loc) · 5.57 KB
/
microsoft_offline_update_launcher.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
:: Purpose: Installs a pre-downloaded Microsoft offline update package, generated by the WSUS Offline Update tool ( http://download.wsusoffline.net/ )
:: Requirements: 1. Run this script with Administrator rights
:: 2. The script expects one command-line argument when it's run (via command line/PDQ deploy/SCCM/etc) which is the patch set to apply:
:: Valid patch sets:
:: office_2k7-2k16
:: windows_7_and_server_2008-R2
:: windows_8.1_and_server_2012-R2
:: windows_server_2003
::
:: If the argument is missing, the installation will fail with error code 1
:: If the variables below point to non-existent sources, the installation will fail error code 2
::
:: Example:
:: microsoft_offline_update_launcher.bat windows_7_and_server_2008-R2
::
:: 3. Set the repository variable to point to where the Microsoft offline update packages are.
:: The final variable that gets passed to the copy operation is built like this:
:: \\server\share_name\product\PATCH_DATE
:: e.g.
:: \\server\microsoft_offline_updates\windows_7_and_server_2008-R2\2018-01-18
::
:: Author: vocatus on reddit.com/r/sysadmin ( vocatus.gate@gmail.com ) // PGP key ID: 0x07d1490f82a211a2
:: Version: 1.7.1 / Minor comment fix
:: 1.7.0 * Remove requirement to pass patch date. This was kind of pointless since we're always wanting to be on the latest patch set anyway
:: / Rename REMOTE_REPOSITORY to REPOSITORY
:: / Rename LOCAL_REPOSITORY to WORKING_DIRECTORY
:: 1.6.2 * Fix incorrect references to %LOGFILENAME% (should be %LOGFILE%). Thanks to reddit.com/user/tastyratz
:: 1.6.1 + Add cleanup of WORKING_DIRECTORY after finishing patch process
:: <remove outdated changelog comments>
:: 1.0 + Initial write
:::::::::::::::
:: VARIABLES :: --------------- Set these to your desired values. -------------------------- ::
:::::::::::::::
:: Rules for variables:
:: * NO quotes! (bad: "c:\directory\path" )
:: * NO trailing slashes on the path! (bad: c:\directory\ )
:: * Spaces are okay (okay: c:\my folder\with spaces )
:: * Network paths are okay (okay: \\server\share name )
:: ( \\172.16.1.5\share name )
:: Log location and name. Do not use trailing slashes (\)
:: Log max size is in bytes. If it exceeds the max then it gets rotated. 1048576 bytes is one megabyte
set LOGPATH=%SystemDrive%\Logs
set LOGFILE=microsoft_offline_updates.log
set LOG_MAX_SIZE=2097152
:: Specify the network location where the Microsoft offline update packages are. ( Default: \\server\share\microsoft_offline_updates )
:: Specify a local directory on the target machine to store the updates in while they install. ( Default: %TEMP%\microsoft_offline_updates )
set REMOTE_REPOSITORY=\\YOUR-SERVER-NAME\repo\microsoft_offline_updates
set WORKING_DIRECTORY=%TEMP%\microsoft_offline_updates
:: -------------------------- Don't edit anything below this line -------------------------- ::
:::::::::::::::::::::
:: Prep and checks ::
:::::::::::::::::::::
@echo off
set SCRIPT_VERSION=1.7.1
set SCRIPT_UPDATED=2015-09-15
:: Get the date into ISO 8601 standard date format (yyyy-mm-dd) so we can use it
FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
set CUR_DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%
:: This is useful if we start from a network share; converts CWD to a drive letter
pushd "%~dp0" 2>NUL
cls
:: These lines build the final source and destination
set PRODUCT=%1
set UPDATE_PACKAGE=%REMOTE_REPOSITORY%\%PRODUCT%
set WORKING_FOLDER=%WORKING_DIRECTORY%\%PRODUCT%
:: Error checks. Throw error if it fails
echo.
if '%1%'=='' echo ERROR You didn't specify a product name. Edit this batch file with a text editor to configure it correctly. && exit /B 1
if not exist %UPDATE_PACKAGE% echo ERROR Couldn't find the update package you specified, check your path. && exit /B 2
:::::::::::::::::::::::
:: LOG FILE HANDLING ::
:::::::::::::::::::::::
:: Make the logfile if it doesn't exist
if not exist "%LOGPATH%" mkdir "%LOGPATH%"
if not exist %LOGPATH%\%LOGFILE% echo. > %LOGPATH%\%LOGFILE%
:: Check log size. If it's less than our max, then jump to the cleanup section
for %%R in (%LOGPATH%\%LOGFILE%) do IF %%~zR LSS %LOG_MAX_SIZE% goto installation
:: If the log was too big, go ahead and rotate it.
pushd %LOGPATH%
del %LOGFILE%.oldest 2>NUL
rename %LOGFILE%.older %LOGFILE%.oldest 2>NUL
rename %LOGFILE%.old %LOGFILE%.older 2>NUL
rename %LOGFILE% %LOGFILE%.old 2>NUL
popd
::::::::::::::::::
:: INSTALLATION ::
::::::::::::::::::
:installation
:: Preclear the download area
IF EXIST %WORKING_DIRECTORY% rmdir /S /Q %WORKING_DIRECTORY%
:: Pull down the update package from the server and store it locally (on the target system)
robocopy "%UPDATE_PACKAGE%" "%WORKING_FOLDER%" /FFT /MIR /Z /NP /LOG+:"%LOGPATH%\%LOGFILE%"
:: Log file formatting
echo. >> "%LOGPATH%\%LOGFILE%"
:: Install the package from the local directory
call "%WORKING_FOLDER%\cmd\DoUpdate.cmd" >> "%LOGPATH%\%LOGFILE%"
:: Pop back to original directory. This isn't necessary in stand-alone runs of the script, but is needed when called from another script
popd
:: Clean up
rmdir /s /q "%WORKING_DIRECTORY%"
:: Return exit code to SCCM/PDQ Deploy/etc
exit /B %EXIT_CODE%
:eof