CMDLets Unleashed

Today, I went ahead and redesigned the cmdlet template, to both make my life easier in creating cmdlets, and to make the system a bit more fleshed out.

Let’s take a look at a working template, as an example (file links will be mirrored to bootzilla.org in the final version of the script)-

@echo off
setlocal enableextensions enabledelayedexpansion

:: DO NOT MODIFY WITHOUT READING INSTRUCTIONS BELOW!

:: app= name of local file, url= url of file, ref= [0/1] on/off referer support
:: decomp= decompression needed, xxcopy= xcopy resulting file/directory
:: destination= second-level directory to put files, destdir= [0/1] on/off second-level directory
:: referer= set this to a referer if needed

set app=uvs_v383eng.zip
set url=http://dsrt.dyndns.org/files/uvs_v383eng.zip
set dest=mal
set ref=0

:: These are flags 1 = yes, 2 = no. Both can be set to 1 if a file needs to be decompressed and moved
set decomp=1
:: set xxcopy=

:: If a program needs to go into its own directory, we set it here
set destination=1
set destdir=uVS

:: Supplementary Files
:: These are intended for apps that need additional files to operate
:: Specifically for ccleaner’s winapp2.ini, uVS’s database file, and a handful of other tools
set supp=1
set suppapp=MAIN.zip
set suppurl=http://dsrt.dyndns.org/files/MAIN.zip
:: set suppref=
set suppdest=1
:: set suppreferer=
set suppdecomp=1
:: set suppxxcopy=
set suppdestdir=SHA

echo. %TIME% - Processing %app% >> ..\log.log

:: Wget
if not exist %app% if %ref%==1 ..\wget -referer=%referer% %url% -O%app%
if exist %app% if %ref%==1 ..\wget -referer=%referer% %url% -O%app%
if not exist %app% if %ref%==0 ..\wget %url% -O%app%
if exist %app% if %ref%==0 ..\wget %url% -O%app%

if %errorlevel% EQU 1 echo %TIME% - %app% failed to download >> ..\error.log

:: specify 7z -y e if you don’t want the directory tree from the archive
if %decomp% EQU 1 if %destination%==1 7z -y x %app% -o..\..\%dest%\%destdir%\
if %decomp% EQU 1 if %destination%==0 7z -y x %app% -o..\..\%dest%\

:: If just copying a file use xcopy
if %xxcopy% EQU 1 if %destination% EQU 1 xcopy /Y /IS /R /S %app% ..\..\%dest%\%destdir%\
if %xxcopy% EQU 1 if %destination% EQU 0 xcopy /Y /IS /R /S %app% ..\..\%dest%\
if %supp%==0 goto _log
if %supp%==1 goto _supplements

:_supplements
:: Supplementary file process
echo %TIME% - Processing supplemental files for %app% >> ..\log.log
if not exist %suppapp% if %suppref%==1 ..\wget -referer=%suppreferer% %suppurl% -O%suppapp%
if exist %suppapp% if %ref%==1 ..\wget -referer=%suppreferer% %suppurl% -O%suppapp%
if not exist %suppapp% if %suppref%==0 ..\wget %suppurl% -O%suppapp%
if exist %suppapp% if %suppref%==0 ..\wget %suppurl% -O%suppapp%

if %errorlevel% EQU 1 echo %TIME% - %suppapp% failed to download >> ..\error.log

:: specify 7z -y e if you don’t want the directory tree from the archive
:: if suppdest is not defined, then we process it as if it were the original app.
if %suppdecomp% EQU 1 if %suppdest%==\nul 7z -y x %suppapp% -o..\..\%dest%\%destdir%\
:: Otherwise we process it as its own app
if %suppdecomp% EQU 1 if %suppdest%==1 7z -y x %suppapp% -o..\..\%suppdest%\%suppdestdir%\
:: if %suppdecomp% EQU 1 if %suppdest%==0 7z -y x %suppapp% -o..\..\%dest%\

:: If just copying a file use xcopy
if %xxcopy% EQU 1 if %suppdest% EQU 1 xcopy /Y /IS /R /S %suppapp% ..\..\%dest%\%destdir%\
if %xxcopy% EQU 1 if %suppdest% EQU 0 xcopy /Y /IS /R /S %suppapp% ..\..\%dest%\

:_log
if %errorlevel% EQU 1 echo %TIME% - Failed to fully process %app% >> ..\log.log
endlocal

Lots and lots of new features are included in the template, including:

  • variables!
  • referers support
  • supplementary file support
  • functions!
  • logical if->then statements!

Overall, this is about 5-7 hours more work to try and save as much sanity as I can while developing this next version. The really rewarding part is that once I get this template finalized and fully bugfixed, I can re-write all my previous cmdlets with it, which will ensure consistency between each and every cmdlet - thus reducing wacky bugs that could crop up during the build process.

I feel this system is necessary for the build process to work properly. The added advantage is that the BZBuilder script hasn’t been touched in days, as all this is very modular - no need to fix what isn’t broken, so long as the simple loops work properly in the main builder script.

Next steps include: testing referers, testing supplementary files, and adding some form of proxy support (likely passed as a command argument, since the cmdlets are operating within their own local command prompt session).

No new build today, until I finalize a few more bits to this cmdlet fiasco I’ve got going. Once the format is finalized, I can start re-writing the old scripts using the template, and release a more complete Alpha 2 release.

What is a cmdlet?

Today, I’d like to document the current state of what I’m calling a cmdlet, which is an integral part of the new version of BootZilla’s build process.

First, let me show you the current working template that all cmdlets are based on -

As you can see, I’ve commented the necessary bits and left placeholders in. Each cmdlet is named after the application that it is tied to. This enforces an easy to understand format, allowing additions and deletions to be easily made to the toolset. The main script file, BZBuilder, will loop through all the cmd files in the cmdlets folder automatically, and it will also build a list of found cmdlets in a text file (currently for debugging/logging purposes). You can then easily verify that a script actually executed by looking at the log file. Each cmdlet also has the ability to log a broken download to an error.log file in the cmdlets directory.

Each cmdlet handles every tool separately. This makes it incredibly easy to release patches for the toolkit without having to rewrite a ton of code. In the future, I’d like to make an easy script or application that takes a program name + url + copy or decompress options so that adding or editing tools is a very simple affair. For now, editing the template as needed is good enough for me.

This new system opens up a lot of new functionality that was previously either too clunky or impossible to offer. All using standard NT6 Batch Scripting.

Unfortunately, Windows XP/2003 will not be supported as an OS to build the toolkit on. You will have to use either Windows Vista/7/8/8.1+ to build the toolkit. This is why an ISO and IMG release will be available.

Alpha 1: http://www.bootzilla.org/wp-content/plugins/download-monitor/download.php?id=17

Questions/Comments? Sign up for an account and post away. I may open up anonymous commenting in the future.