Jump to content

HowTo: Unattended Installation using FTP


Recommended Posts

Unattended Installation using FTP - Last Update: 9/20/04

This script can be used for post installation of applications, udpates, drivers, & just about anything you want. You can run this @ GUIRUNONCE, RUNONCEEX, whenever you choose. What this does is download "packages" from the specified FTP server & then builds the installation script for those packages. The advantage of doing it this way is that you don't have to reburn your installation cd everytime you want to add/update something. All you will have to do is make/edit a package & put it on the ftp server. You could even put this on a bootable floppy/cd & have it do a complete unattended setup with minor editing. I tried to give this post more detailed instructions on usage, let me know if this is enough. I might just put up a page on my site, but I'm not sure if enough people are interested or not.

Changes:

  • 9/20/04 - Script now obtains its variables from an INI file. NOTE: Now the script is called like: ftp.cmd [path to ini]
  • 9/20/04 - Fixed a missing BYE command in the ftp login test.
  • 9/12/04 - Fixed missing bin & prom commands while downloading required EXEs.
  • 9/10/04 - Removed the DEVCON.EXE section for now.
  • 9/10/04 - Now downloads any required EXEs before anything else.
  • 9/10/04 - Fixed some typos, must be the lack of sleep.
  • 9/06/04 - Added more variables to give better control over the whole process.
  • 9/06/04 - Changed the way the FTP script is generated.
  • 9/05/04 - Added /I swith to the IF Y/N commands so it's no longer case sensitive *greenmachine
  • 9/04/04 - Added definitions for all the variables, will hopefully make editing the script for your own use easier.
  • 9/02/04 - Now tests the FTP server un/pw specified in the batch, if it's incorrect it will prompt user for input.
  • 8/29/04 - Detects ATI or NVIDIA video card & downloads appropriate package.
  • 8/29/04 - Added DRIVERS folder for device drivers
  • 8/29/04 - Added MODS folder for modified files (uxtheme.dll etc.)
  • 8/28/04 - Packages structure is easier to manage, just put commands.txt in the folder & rar it up.
  • 8/28/04 - Now tests for existance of FTP server.
  • 8/28/04 - All necessary tools are downloaded (NO EXTRA FILES REQUIRED ON YOUR INSTALL CD)

Requirments:

  • Network Access (Use the LANPack to make sure)
  • FTP Server to serve up packages.
  • UNRAR.EXE

What it Does:

  1. Checks for existance of ftp server.
  2. Checks username/password on server & prompts for user input if it can't login.
  3. Downloads "packages" via ftp.exe
  4. Extracts the packages
  5. Creates an installation script for the packages (based off commands.txt)
  6. Applies registry tweaks
  7. Installs packages

Creating Packages:

To dowload & install applications, updates, etc.. you will need to make each of them into individual "packages".

Making packages is a pretty straightforward process. The video drivers are the only exception to the rule really, you need to set the name of these packages in the variables later on.

  1. Create folder named after your application.
  2. Put setup.exe for your application into the folder
  3. Create a text file named commands.txt in the folder
  4. Edit commands.txt & put in your applications silent install commands.
  5. Compress the folder using winRAR to a file with the same name.

Example Package: DOWNLOAD

COMMANDS.TXT EXAMPLE: (Note: The first line of the commands.txt file needs to be blank.) example

ECHO.
ECHO Installing Winrar v3.30 ...
start /wait %APP_DIR%\winrar330\setup.exe /s
REGEDIT /S %APP_DIR%\winrar330\cascade.reg

FTP Server Setup:

Create the following directory structure on your ftp server:

  • /unattend
  • /unattend/apps
  • /unattend/mods
  • /unattend/updates
  • /unattend/drivers
  • /unattend/tweaks
  • /unattend/tools

Copy your packages to their perspective folders & put your .reg files in the /tweaks folder. (Note: I have my reg tweaks in seperate files (enable_rdp.reg, disable_error_report.reg, etc.)

/unattend/tools Needs to contain devcon.exe & unrar.exe

Editing The INI File:

You will need to edit some of the variables in FTP_VAR.INI to fit your setup. If you follow my setup you should really only have to edit FTP_ADDY, FTP_USER, FTP_PASS, & TOP_DIR. There is a full list of the variables & their functions listed below, as you can see you can change just about everything, from temp files it creates to the name of the installation script it generates.

FTP_VAR.INI Variable Settings:

  • FTP_ADDY = 192.168.1.25 (ip of your ftp server)
  • FTP_USER = username (ftp username)
  • FTP_PASS = password (ftp password)
  • FTP_CANC = undefined (part of ftp server testing **DO NOT EDIT**)
  • PAK_DIR = unattend (base folder for packages on ftp server)
  • TOP_DIR = %SYSTEMDRIVE%\install (Local download directory)
  • FTP_SCR = c:\install\ftp_scr.txt (generated ftp script)
  • FTP_TSCR = c:\install\ftp_tscr.txt (generated ftp testing script)
  • FTP_OUT = c:\install\ftp_out.txt (generated ftp testing output)
  • INSTALL_SCR = c:\install\install.cmd (generated package installation script)
  • PACK_SCR = commands.txt (filename containing package install commands)
  • TOOL_SCR = generated ftp script to download tools
  • TOOL_DIR = c:\windows\system32 (location commandline tools will be downloaded to)
  • APP_DIR = c:\install\apps (Local directory for apps)
  • UPD_DIR = c:\install\updates (local directory for updates/patches)
  • TWK_DIR = c:\install\tweaks (local directory for .reg tweaks)
  • MOD_DIR = c:\install\mods (local directory for modded files)
  • DRV_DIR = c:\install\drivers (local directory for drivers)

FTP_VAR.INI

# Format: VariableName=VariableValue
# Do not use spaces around the equal sign.
FTP_ADDY=192.168.1.25
FTP_USER=test
FTP_PASS=test
FTP_CANC=undefined
PAK_DIR=unattend
TOP_DIR=c:\install
FTP_SCR=c:\install\ftp_scr.txt
FTP_TSCR=c:\install\ftp_tscr.txt
FTP_OUT=c:\install\ftp_out.txt
INSTALL_SCR=c:\install\install.cmd
PACK_SCR=commands.txt
TOOL_SCR=c:\install\tool_scr.txt
TOOL_DIR=c:\windows\system32
APP_DIR=c:\install\apps
UPD_DIR=c:\install\updates
TWK_DIR=c:\install\tweaks
MOD_DIR=c:\install\mods
DRV_DIR=c:\install\drivers

FTP.CMD

@ECHO OFF
SET SCR_VER=PACK_GET.CMD v1.0

if .%1.==.. goto usage
set INI_FILE=%1
set INI_FILE=%INI_FILE:"=%
if not exist "%INI_FILE%" goto missing_ini

ECHO.
ECHO Setting variables defined in %INI_FILE% ...
for /f "eol=# tokens=1* delims==" %%a in ('type %INI_FILE%') do set %%a=%%b

:: CREATING DIRECTORIES FOR PACKAGES
ECHO.
ECHO Creating directories ...
md %TOP_DIR%
md %APP_DIR%
md %UPD_DIR%
md %TWK_DIR%
md %DRV_DIR%
md %MOD_DIR%

::BEGIN FTP SERVER TESTING
:FTP_EXIST
ECHO ping ftp ...
PING %FTP_ADDY% ¦ FIND "TTL" >NUL
IF ERRORLEVEL 0 GOTO FTP_TEST
IF ERRORLEVEL 1 GOTO FTP_INPUT

:FTP_TEST
ECHO. ftp exists ... testing login ...
> %FTP_TSCR% ECHO open %FTP_ADDY%
>>%FTP_TSCR% ECHO %FTP_USER%
>>%FTP_TSCR% ECHO %FTP_PASS%
>>%FTP_TSCR% ECHO bye
%WINDIR%\system32\ftp.exe -s:%FTP_TSCR% > %FTP_OUT%
FIND "User logged in" %FTP_OUT% >NUL
IF ERRORLEVEL 1 GOTO FTP_CHOICE
GOTO FTP_START

:FTP_CHOICE
ECHO.
SET /P FTP_CANC=[Cancel FTP download? Y/N:]
IF /I "%FTP_CANC%" == "Y" goto CANCEL
IF /I "%FTP_CANC%" == "N" goto FTP_INPUT
GOTO FTP_CHOICE

:FTP_INPUT
if exist %FTP_OUT% del %FTP_OUT%
if exist %FTP_TSCR% del %FTP_TSCR%
SET /P FTP_ADDY=[FTP Address:]
SET /P FTP_USER=[FTP Username:]
SET /P FTP_PASS=[FTP Password:]
SET /P PAK_DIR=[Base Package Directory:]
ECHO.
ECHO You specified:
ECHO FTP Address: %FTP_ADDY%
ECHO FTP Username: %FTP_USER%
ECHO FTP Password: %FTP_PASS%
ECHO FTP Package Directory: %PAK_DIR%
:FTP_CONFIRM
ECHO.
SET /P FTP_CONF=[Is this correct? Y/N:]
IF /I "%FTP_CONF%" == "Y" GOTO FTP_EXIST
IF /I "%FTP_CONF%" == "N" GOTO FTP_INPUT
GOTO FTP_CONFIRM
::END FTP SERVER TESTING

::BEGIN BUILDING FTP SCRIPT
:FTP_START
del %FTP_OUT%
del %FTP_TSCR%
ECHO Getting Required files ...

> %TOOL_SCR% ECHO open %FTP_ADDY%
>>%TOOL_SCR% ECHO %FTP_USER%
>>%TOOL_SCR% ECHO %FTP_PASS%
>>%TOOL_SCR% ECHO bin
>>%TOOL_SCR% ECHO prom
>>%TOOL_SCR% ECHO lcd %TOOL_DIR%
>>%TOOL_SCR% ECHO cd unattend
>>%TOOL_SCR% ECHO cd tools
>>%TOOL_SCR% ECHO mget *.*
>>%TOOL_SCR% ECHO bye
%WINDIR%\system32\ftp.exe -s:%TOOL_SCR%
del %TOOL_SCR%

ECHO Building FTP Script ...
> %FTP_SCR% ECHO open %FTP_ADDY%
>>%FTP_SCR% ECHO %FTP_USER%
>>%FTP_SCR% ECHO %FTP_PASS%
>>%FTP_SCR% ECHO bin
>>%FTP_SCR% ECHO prom
>>%FTP_SCR% ECHO cd %PAK_DIR%
>>%FTP_SCR% ECHO lcd %APP_DIR%
>>%FTP_SCR% ECHO cd apps
>>%FTP_SCR% ECHO mget *.rar
>>%FTP_SCR% ECHO lcd %UPD_DIR%
>>%FTP_SCR% ECHO cd ../updates
>>%FTP_SCR% ECHO mget *.rar
>>%FTP_SCR% ECHO lcd %TWK_DIR%
>>%FTP_SCR% ECHO cd ../tweaks
>>%FTP_SCR% ECHO mget *.reg
>>%FTP_SCR% ECHO lcd %MOD_DIR%
>>%FTP_SCR% ECHO cd ../mods
>>%FTP_SCR% ECHO mget *.rar
>>%FTP_SCR% ECHO lcd %DRV_DIR%
>>%FTP_SCR% ECHO cd ../drivers
>>%FTP_SCR% ECHO mget *.rar
:FTP_DONE
>>%FTP_SCR% ECHO bye
::END BUILDING FTP SCRIPT

ECHO.
ECHO Downloading per FTP_CMD.TXT ....
%WINDIR%\system32\ftp.exe -s:%FTP_SCR%
del %FTP_SCR%

ECHO.
ECHO Extracting Packages ...
for %%i in (%APP_DIR%\*.rar) do UNRAR x %%i %APP_DIR%
for %%i in (%UPD_DIR%\*.rar) do UNRAR x %%i %UPD_DIR%
for %%i in (%DRV_DIR%\*.rar) do UNRAR x %%i %DRV_DIR%
for %%i in (%MOD_DIR%\*.rar) do UNRAR x %%i %MOD_DIR%
for %%i in (%APP_DIR%\*.rar %UPD_DIR%\*.rar %DRV_DIR%\*.rar %MOD_DIR%\*.rar) do DEL %%i

ECHO.
ECHO Applying various registry tweaks ...
for %%i in (%TWK_DIR%\*.reg) do REGEDIT /S %%i
for %%i in (%TWK_DIR%\*.reg) do DEL %%i

ECHO.
ECHO Building installation script ...
for /d %%i in (%APP_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%
for /d %%i in (%UPD_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%
for /d %%i in (%DRV_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%
for /d %%i in (%MOD_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%

call %INSTALL_SCR%
GOTO CLEANUP

:CANCEL
ECHO Package installation was canceled.
GOTO CLEANUP

:MISSING_INI
ECHO %SCR_VER% - ERROR!
ECHO The specified INI does not exist.
GOTO END

:USAGE
ECHO %SCR_VER% - ERROR!
ECHO You must specify the location of the INI file containing variables.
ECHO.
ECHO Syntax:
ECHO ftp_ini.cmd [path to ini file]
ECHO.
ECHO Usage:
ECHO ftp_ini.cmd z:\config\ftp_var.ini
ECHO.
GOTO END

:CLEANUP
ECHO.
ECHO Cleaning up ...
rd /s /q %TOP_DIR%
SHUTDOWN -r -t 10
:END

Link to comment
Share on other sites


I'm getting ready to do this and I am going over it and I can't figure out how the script knows what PACK_EXT is I don't see a mention of it anywhere else. I will probably just go ahead and put static names in there I think unless I'm missing somethign or maybe just don't understand something about it? Really I don't quite understand any of the for %%i lines.

Link to comment
Share on other sites

I bypassed the ftp test by pointing it at the ftp_start command early on and it works ok until it tries to unrar the packages and then it just wasn't doing anything so I changed %PACK_EXT% to rar and it unpacks the files and makes the script ok. I of course took out the part where it would install for now.

Link to comment
Share on other sites

I bypassed the ftp test by pointing it at the ftp_start command early on and it works ok until it tries to unrar the packages and then it just wasn't doing anything so I changed %PACK_EXT% to rar and it unpacks the files and makes the script ok. I of course took out the part where it would install for now.

Sorry bout that, I posted my "in progress" version that lets you use something other than unrar.exe (pkunzip.exe or whatever you want). As far as the FTP_TEST section, it seems to be working fine here, try the code again, there could've been more problems with the version I had up.

Link to comment
Share on other sites

also, i really like this script...but I also wanna have the option of downloading from web, so, if you give me permission, im changing your ftp script to be used for web...so far Ive got it almost done, just need to set up the script WEB_SCR (im not very imaginative lol) for use with wget...other than that, I think ive got it down.

Link to comment
Share on other sites

also, i really like this script...but I also wanna have the option of downloading from web, so, if you give me permission, im changing your ftp script to be used for web...so far Ive got it almost done, just need to set up the script WEB_SCR (im not very imaginative lol) for use with wget...other than that, I think ive got it down.

I've been thinking about doing the same thing, you can probably add this with minor editing, I will edit the entire post to include this option. If you want to edit it feel free, just be sure to post what you come up with :) I just whipped this up after reading your post, so no guarantees :P

:WEB_GET
rem set variables for url lists
set WEB_TOOL=http://bender/unattend/tools/url_list.txt
set WEB_APP=http://bender/unattend/apps/url_list.txt
set WEB_UPD=http://bender/unattend/updates/url_list.txt
set WEB_DRV=http://bender/unattend/drivers/url_list.txt
set WEB_MOD=http://bender/unattend/mod/url_list.txt

rem downloading url lists
wget -P%TOOL_DIR% %WEB_TOOL%
wget -P%APP_DIR% %WEB_APP%
wget -P%UPD_DIR% %WEB_UPD%
wget -P%DRV_DIR% %WEB_DRV%
wget -P%MOD_DIR% %WEB_MOD%

rem downoading packages from url lists
wget -P%TOOL_DIR% -i%TOOL_DIR%\url_list.txt
wget -P%APP_DIR% -i%APP_DIR%\url_list.txt
wget -P%APP_DIR% -i%UPD_DIR%\url_list.txt
wget -P%APP_DIR% -i%DRV_DIR%\url_list.txt
wget -P%APP_DIR% -i%MOD_DIR%\url_list.txt

Link to comment
Share on other sites

I did notice an error with ftp.cmd....you dont download the tools until after the script is done, so how can you run devcon in its location??

Yep, you're right, that should be fixed now. I've been running it off a winPE cd to test and had devcon.exe in my path already :P

Link to comment
Share on other sites

well, this is what I have so far for the web...

@ECHO OFF
ECHO.
ECHO Setting variables ...

:: SET VARIABLES TO REFLECT YOUR SETUP
set PAK_DIR=unattend

set TOP_DIR=%SYSTEMDRIVE%\install
set WEB_SCR=%TOP_DIR%\WEB_SCR.CMD
set INSTALL_SCR=%TOP_DIR%\install.cmd
set PACK_SCR=commands.txt

set TOOL_DIR=%WINDIR%\system32
set APP_DIR=%TOP_DIR%\apps
set UPD_DIR=%TOP_DIR%\updates
set TWK_DIR=%TOP_DIR%\tweaks
set MOD_DIR=%TOP_DIR%\mods
set DRV_DIR=%TOP_DIR%\drivers

:: CREATING DIRECTORIES FOR PACKAGES
ECHO.
ECHO Creating directories ...
rem md %TOP_DIR%
md %APP_DIR%
md %UPD_DIR%
md %TWK_DIR%
md %DRV_DIR%
md %MOD_DIR%

:WEB_INPUT
SET /P WEB_ADDY=[Web Address: (include http://)]
ECHO.
ECHO You specified:
ECHO WEB Address: %WEB_ADDY%
:WEB_CONFIRM
ECHO.
SET /P WEB_CONF=[Is this correct? Y/N:]
IF /I "%WEB_CONF%" == "Y" GOTO WEB_EXIST
IF /I "%WEB_CONF%" == "N" GOTO WEB_INPUT
GOTO WEB_CONFIRM
::END WEB SERVER TESTING

::BEGIN WEB SERVER TESTING
:WEB_EXIST
ECHO ping web ...
PING %WEB_ADDY% ¦ FIND "TTL" >NUL
IF ERRORLEVEL 0 GOTO WEB_START
IF ERRORLEVEL 1 GOTO WEB_INPUT

:WEB_CHOICE
ECHO.
SET /P WEB_CANC=[Cancel WEB download? Y/N:]
IF /I "%WEB_CANC%" == "Y" goto CANCEL
IF /I "%WEB_CANC%" == "N" goto WEB_INPUT
GOTO WEB_CHOICE

::BEGIN BUILDING WEB SCRIPT
:WEB_START
ECHO Downloading TOOLS...
wget -P%TOOL_DIR%\ %WEB_ADDY%/%PAK_DIR%/tools/url_list.txt
wget -P%TOOL_DIR%\ -i%TOOL_DIR%\url_list.txt

ECHO Building WEB Script ...
>%WEB_SCR% ECHO @ECHO OFF
>>%WEB_SCR% ECHO wget -P%APP_DIR%\ %WEB_ADDY%/%PAK_DIR%/apps/url_list.txt
>>%WEB_SCR% ECHO wget -P%UPD_DIR%\ %WEB_ADDY%/%PAK_DIR%/updates/url_list.txt
>>%WEB_SCR% ECHO wget -P%TWK_DIR%\ %WEB_ADDY%/%PAK_DIR%/tweaks/url_list.txt
>>%WEB_SCR% ECHO wget -P%MOD_DIR%\ %WEB_ADDY%/%PAK_DIR%/mods/url_list.txt
>>%WEB_SCR% ECHO wget -P%DRV_DIR%\ %WEB_ADDY%/%PAK_DIR%/drivers/url_list.txt
>>%WEB_SCR% ECHO wget -P%TOP_DIR%\ -i%APP_DIR%\url_list.txt
>>%WEB_SCR% ECHO wget -P%TOP_DIR%\ -i%UPD_DIR%\url_list.txt
>>%WEB_SCR% ECHO wget -P%TOP_DIR%\ -i%TWK_DIR%\url_list.txt
>>%WEB_SCR% ECHO wget -P%TOP_DIR%\ -i%MOD_DIR%\url_list.txt
>>%WEB_SCR% ECHO wget -P%TOP_DIR%\ -i%DRV_DIR%\url_list.txt
:WEB_DONE
>>%WEB_SCR% ECHO END
::END BUILDING WEB SCRIPT

ECHO.
ECHO Downloading per WEB_SCR.CMD ....
CALL %WEB_SCR%

ECHO.
ECHO Extracting Packages ...
for %%i in (%APP_DIR%\*.rar) do UNRAR x %%i %APP_DIR%
for %%i in (%UPD_DIR%\*.rar) do UNRAR x %%i %UPD_DIR%
for %%i in (%DRV_DIR%\*.rar) do UNRAR x %%i %DRV_DIR%
for %%i in (%MOD_DIR%\*.rar) do UNRAR x %%i %MOD_DIR%
for %%i in (%APP_DIR%\*.rar %UPD_DIR%\*.rar %DRV_DIR%\*.rar %MOD_DIR%\*.rar) do DEL %%i

ECHO.
ECHO Applying various registry tweaks ...
for %%i in (%TWK_DIR%\*.reg) do REGEDIT /S %%i
rem for %%i in (%TWK_DIR%\*.reg) do DEL %%i

ECHO.
ECHO Building installation script ...
for /d %%i in (%APP_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%
for /d %%i in (%UPD_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%
for /d %%i in (%DRV_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%
for /d %%i in (%MOD_DIR%\*.*) do type "%%i\%PACK_SCR%" >> %INSTALL_SCR%

call %INSTALL_SCR%
GOTO CLEANUP

:CANCEL
ECHO. Package installation was canceled.

:CLEANUP
ECHO.
ECHO Cleaning up ...
rd /s /q %TOP_DIR%
SHUTDOWN -r -t 10
:END

I didnt invlude devcon, cuz devcon doesnt even work for my pc...it finds both ati and nvidia, and actually, it doesnt even find my video card...its an all-in-wonder...and in devcon, it doesnt have ati in the name...so I dont know how useful devcon is gonna be in anyones case...

Link to comment
Share on other sites

I didnt invlude devcon, cuz devcon doesnt even work for my pc...it finds both ati and nvidia, and actually, it doesnt even find my video card...its an all-in-wonder...and in devcon, it doesnt have ati in the name...so I dont know how useful devcon is gonna be in anyones case...

I've only tested the devcon method on about 12 pcs... they all worked fine, but I dont doubt that it doesn't work on others. Nice work btw, once you're finished I will put it all together @ the top of the post. I'm currently trying to merge this script & another script I used to install XP from inside winPE & a method for WEB d/l would be great. I will go ahead and remove the devcon section for now until someone can tell me a reliable way to test for this.

Link to comment
Share on other sites

well, this is where i need your help or whoevers...as far as I can see, its now done...I did have to make some changes after posting, but to me, it looks complete...but, I dont know about the cleanup...and also, dont really know if it all flows (ie, if it will work, it should in theory...)...as for the cleanup, there might be some strangling url files somewhere...like in system32 dir...but other than that, I think its done...give it a test, I guess...I would test it, but I dont have a web server up yet....Also, another thing, if using runonceex, most people are gonna have $OEM$...so why not dump devcon and unrar in the system32 folder in there...$$\system32?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...