From: Heiko Z. <smi...@us...> - 2010-09-28 00:24:06
|
Update of /cvsroot/devil-linux/build/scripts/scripts In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv19052/scripts/scripts Added Files: install-on-usb.bat Log Message: added install-on-usb.bat for Windows machines (Dominic Raferd / HZ) --- NEW FILE: install-on-usb.bat --- @ECHO OFF : Devil-Linux Windows USB Installer : must be located in same folder as bootcd.iso, fart.exe, syslinux.exe : dependencies: : bootcd.iso DL CD image : 7z.exe http://www.7-zip.org/ : fart.exe http://sourceforge.net/projects/fart-it/ : syslinux.exe http://www.kernel.org/pub/linux/utils/boot/syslinux/ : History: : Rev 0.1 2010-08-13 - skip unnecessary subdirectories, check drive is big enough, optimize a little : Rev 0.2 2010-08-18 - tested with Windows 7/2008 64-bit : - improved error checking/messaging : - offer options for pre-loaded default and remote login configurations : Rev 0.3 2010-08-20 - improved disk size checking and selection SETLOCAL ENABLEDELAYEDEXPANSION ECHO. ECHO %~nx0 ECHO. ECHO This makes the first partition of a removable drive into Devil-Linux boot disk ECHO using Devil-Linux bootcd.iso. ECHO. SET /P RESPONSE="Press any key to continue, or h for help or q to quit: " ECHO. IF /I "%RESPONSE%"=="q" GOTO :erredexit IF /I "%RESPONSE%"=="h" GOTO :help REM check for presence of required files IF "%1" NEQ "" ( SET ZIPEXE=%1\7z.exe ) ELSE ( SET ZIPEXE=C:\PROGRA~1\7-Zip\7z.exe IF NOT EXIST "!ZIPEXE!" ( SET ZIPEXE=C:\PROGRA~2\7-Zip\7z.exe IF NOT EXIST "!ZIPEXE!" ( ECHO Can't locate 7z.exe, please obtain and install 7-Zip from http://www.7-zip.org>&2 ECHO or, if already installed, provide path to 7z.exe as parameter>&2 GOTO :erredexit ) ) ) IF NOT EXIST "%~dp0fart.exe" ECHO Can't locate fart.exe, aborting...>&2 && GOTO :erredexit IF NOT EXIST "%~dp0syslinux.exe" ECHO Can't locate syslinux.exe, aborting...>&2 && GOTO :erredexit IF NOT EXIST "%~dp0bootcd.iso" ECHO Can't locate bootcd.iso, aborting...>&2 && GOTO :erredexit REM set required space to bootcd.iso+8MB, at time of writing we actually need bootcd.iso+7.01MB FOR /F "tokens=3" %%A IN ('DIR %~dp0bootcd.iso /-c^|findstr -R "bootcd.iso$"') DO SET /A REQDSIZE=%%A+8388608 SET /A REQDSIZEMB=%REQDSIZE%/1048576 REM Obtain Windows Version as number (5.0=2000, 5.1=XP, 5.2=2003, 6.0=Vista, 6.1=7/2008) FOR /F "tokens=2* delims=[]" %%A IN ('VER') DO FOR /F "tokens=2,3 delims=. " %%B IN ("%%A") DO SET WINVER=%%B.%%C REM Create list of logical drives and sizes WMIC LOGICALDISK GET Name,Size>"%TEMP%\%~n0-drives.txt" ECHO The following possible installation drives have been found:>"%TEMP%\%~n0-validdrives.txt" SET VALID=0 REM Obtain list of removable drives FOR %%i in (D: E: F: G: H: I: J: K: L: M: N: O: P: Q: R: S: T: U: V: W: X: Y: Z:) DO ( fsutil fsinfo drivetype %%i>"%TEMP%\%~n0-drivetype.txt" REM The FSUTIL utility requires that you have administrative privileges. IF ERRORLEVEL 1 ( ECHO An error occurred using FSUTIL:>&2 TYPE "%TEMP%\%~n0-drivetype.txt">&2 ECHO.>&2 IF %WINVER% GEQ 6.0 ( ECHO Note: You may need to right-click %~nx0 and>&2 ECHO 'Run as Administrator'>&2 ) ELSE ( ECHO Note: You need administrative privileges to run %~nx0.>&2 ) ECHO.>&2 GOTO :erredexit ) "%~dp0fart.exe" -q "%TEMP%\%~n0-drivetype.txt" "Removable">nul 2>&1 IF ERRORLEVEL 1 ( REM Block installation to the drive from which this batch file is running IF /I %%i NEQ %~d0 ( SET DSIZEMB=0 FOR /F "tokens=2" %%A IN ('TYPE "%TEMP%\%~n0-drives.txt"^|FIND /i "%%i"') DO SET /A DSIZEMB=%%A/1048576 REM Block installation to any drive that is too small IF !DSIZEMB! GTR %REQDSIZEMB% ( SET VALIDDRIVES=!VALIDDRIVES! %%i ECHO %%i ^(!DSIZEMB!MB^)>>"%TEMP%\%~n0-validdrives.txt" SET /A VALID=!VALID!+1 ) ELSE ( IF !DSIZE! EQU 0 ( SET VALIDDRIVES=!VALIDDRIVES! %%i ECHO %%i ^(unknown size^)>>"%TEMP%\%~n0-validdrives.txt" SET /A VALID=!VALID!+1 ) ) ) ELSE ECHO Please copy contents of %%i to a local directory and run from there>&2&&GOTO :erred ) ) IF "%VALIDDRIVES%"=="" ( ECHO No Removable Drives found>&2 ECHO Note: You may need to run %~nx0 as Administrator>&2 ECHO Aborting>&2 GOTO :erredexit ) REM strip leading space SET VALIDDRIVES=%VALIDDRIVES:~1% REM Select installation drive IF %VALID% EQU 1 ( SET DRIVE=%VALIDDRIVES% ECHO Drive !DRIVE! autoselected as the only possible valid installation drive GOTO :skipselection ) TYPE "%TEMP%\%~n0-validdrives.txt" SET /P RESPONSE="Please enter the installation drive letter: " IF "%RESPONSE%"=="" ECHO No drive specified, aborting&& GOTO :erredexit REM add trailing colon if only letter entered IF "%RESPONSE:~1,1%"=="" SET RESPONSE=%RESPONSE%: REM fail if more than 2 chars long IF NOT "%RESPONSE:~2%"=="" ECHO Invalid drive %RESPONSE% specified, aborting&& GOTO :erredexit FOR %%i in (%VALIDDRIVES%) DO IF /I "%RESPONSE%"=="%%i" SET DRIVE=%%i IF "%DRIVE%"=="" ECHO Invalid drive specified, aborting>&2 && GOTO :erredexit ECHO %DRIVE% selected :skipselection REM Get ready REM start with a clean %TEMP%\boot directory RMDIR /S /Q "%TEMP%\boot\" 2>nul MKDIR "%TEMP%\boot\" 2>nul REM extract 3 small files immediately - we need them later anyway, REM getting them now allows us to extract DL version "%ZIPEXE%" e "%~dp0bootcd.iso" -o"%TEMP%\boot" DEVIL-LINUX LICENSE isolinux.cfg>nul IF ERRORLEVEL 1 GOTO :erred REN "%TEMP%\boot\isolinux.cfg" syslinux.cfg IF ERRORLEVEL 1 GOTO :erred SET /P DLVER=""<"%TEMP%\boot\DEVIL-LINUX" ECHO. ECHO This will make %DRIVE% into Devil-Linux %DLVER% boot disk ECHO Please choose configuration: ECHO [1] Clean installation ECHO - best if you plan to store config on different medium or partition ECHO [2] Default configuration on boot partition ECHO - prevents warning messages upon first boot ECHO [3] Remote-boot configuration on boot partition. ECHO - allows immediate remote ssh login for user 'root' with password 'devil' ECHO and suitable for headless machine or remote installation SET /P CONFIGOPT="Please enter 1,2 or 3: " IF "%CONFIGOPT%" NEQ "1" IF "%CONFIGOPT%" NEQ "2" IF "%CONFIGOPT%" NEQ "3" ( ECHO Invalid response, aborting... GOTO :erredexit ) REM Preparatory Action ECHO. ECHO Extracting files REM despite the no recurse instruction, it recurses anyway, but we won't use the subdirectories "%ZIPEXE%" x "%~dp0bootcd.iso" -o"%TEMP%" boot -r->nul IF ERRORLEVEL 1 GOTO :erred REM extract default configuration IF %CONFIGOPT% GEQ 2 "%ZIPEXE%" e "%~dp0bootcd.iso" -o"%TEMP%"\boot config\etc-mods.tar.bz2 -r->nul IF ERRORLEVEL 1 GOTO :erred IF %CONFIGOPT% LEQ 2 GOTO :skip_mod_config REM create easy remote start configuration ECHO Creating Remote-boot configuration REM extract default configuration file "%ZIPEXE%" e "%TEMP%\boot\etc-mods.tar.bz2" -o"%TEMP%"\boot\config * -r->nul IF ERRORLEVEL 1 ECHO Error extracting etc-mods.tar.bz2&&GOTO :erred REM unpack default configuration "%ZIPEXE%" x "%TEMP%\boot\config\etc-mods.tar" -o"%TEMP%\boot\config" * -r->nul IF ERRORLEVEL 1 ECHO Error extracting etc-mods.tar&&GOTO :erred REM extract default shadow (password) file "%ZIPEXE%" e "%~dp0bootcd.iso" -o"%TEMP%"\boot\config\etc-mods etc-cd\shadow -r->nul IF ERRORLEVEL 1 ECHO Error extracting shadow&&GOTO :erred PUSHD "%TEMP%\boot\config" REM switch on sshd "%~dp0fart.exe" -q -- "etc-mods\sysconfig\config" "START_SSHD=no" "START_SSHD=yes" IF "%ERRORLEVEL%" NEQ "1" ECHO Unable to set SSHD to operate at start-up&&GOTO :erred REM set 'devil' password "%~dp0fart.exe" -q -- "etc-mods\shadow" "$1$JHH/CiJE$nDKJJh2hEmE8x2VePkyVP/" "$1$Jrgbm29u$TzBgorXoLccnRS23WWvq10" IF "%ERRORLEVEL%" NEQ "1" ECHO Unable to set root password&&GOTO :erred REM create autoselect eth0 dhcp network MKDIR "etc-mods\sysconfig\nic\">nul ECHO DEVICE=eth0>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO ONBOOT=yes>>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO MODULE="autoselect">>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO DHCP=yes>>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO IP=>>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO NETMASK=>>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO BROADCAST=>>etc-mods\sysconfig\nic\ifcfg-eth0 ECHO ROUTE=>>etc-mods\sysconfig\nic\ifcfg-eth0 REM remove CRs from files "%~dp0fart.exe" -q -C --remove -- "etc-mods\shadow","etc-mods\sysconfig\nic\ifcfg-eth0" "\r" IF %ERRORLEVEL% EQU 0 GOTO :erred REM add/update files in etc-mods.tar "%ZIPEXE%" u etc-mods.tar etc-mods\sysconfig\config etc-mods\sysconfig\nic\ifcfg-eth0 etc-mods\shadow>nul IF ERRORLEVEL 1 GOTO :erred REM rebuild etc-mods.tar.bz2 "%ZIPEXE%" a etc-mods.tar.bz2 etc-mods.tar>nul IF ERRORLEVEL 1 GOTO :erred POPD REM move etc-mods.tar.bz2 to boot directory MOVE /Y "%TEMP%\boot\config\etc-mods.tar.bz2" "%TEMP%\boot\" IF ERRORLEVEL 1 GOTO :erred :skip_mod_config ECHO Configuring files "%~dp0fart.exe" --remove -q -- "%TEMP%\boot\syslinux.cfg","%TEMP%\boot\message" "/boot/" REM fart.exe uses ERRORLEVEL to report number of changes: at time of writing there are 21 file changes, but allow some latitude IF %ERRORLEVEL% LSS 12 (SET ERRORLEVEL=1&&GOTO :erred) ELSE IF %ERRORLEVEL% GEQ 30 SET ERRORLEVEL=1&&GOTO :erred REM Start work on the installation drive SET /P RESPONSE="You will lose current content of %DRIVE% - are you sure? [y/n] " IF /I "%RESPONSE%" NEQ "y" GOTO :erredexit SET /P RESPONSE="Last chance - are you really happy to lose everything on %DRIVE%? [y/n] " IF /I "%RESPONSE%" NEQ "y" GOTO :erredexit ECHO Formatting %DRIVE% ECHO y|FORMAT %DRIVE% /Q /X /FS:FAT32 /V:DEVIL-LINUX>nul REM if formatting fails, try with FAT16 IF ERRORLEVEL 1 ECHO y|FORMAT %DRIVE% /Q /X /FS:FAT /V:DEVIL-LINUX>nul IF ERRORLEVEL 1 ECHO Unable to format %DRIVE%&&GOTO :erred REM check drive size REM create dummy file so that dir reports free bytes ECHO x>%DRIVE%\syslinux.cfg SET DSIZE=0 FOR /F "tokens=3" %%I IN ('DIR %DRIVE%\ /-c') DO SET DSIZE=%%I IF %DSIZE% LSS %REQDSIZE% ( ECHO Drive %DRIVE% is not large enough, minimum size is %REQDSIZEMB%MB ECHO Routine aborted... GOTO :erredexit ) ECHO Installing Syslinux MBR and BootSector on %DRIVE% "%~dp0syslinux" -ma %DRIVE% IF ERRORLEVEL 1 GOTO :erred SET /P "dummyvar=Copying files to %DRIVE%, may take a few minutes"<nul REM xcopy does not work to USB drive under Vista, and we don't need the subdirectories anyway COPY "%TEMP%\boot" %DRIVE%\>nul IF ERRORLEVEL 1 GOTO :erred SET /P "dummyvar=."<nul REM for ease of maintenance put usb-install files on USB too COPY "%~dp0*usb*" %DRIVE%\>nul IF ERRORLEVEL 1 GOTO :erred SET /P "dummyvar=."<nul COPY "%~dp0*.exe" %DRIVE%\>nul IF ERRORLEVEL 1 GOTO :erred SET /P "dummyvar=."<nul REM put bootcd.iso file on drive, pcopy provides progress indicator Call :Pcopy "%~dp0bootcd.iso" %DRIVE% IF ERRORLEVEL 1 GOTO :erred ECHO . done RMDIR /S /Q "%TEMP%\boot" DEL "%TEMP%\%~n0-*" ECHO Completed successfully, %DRIVE% now contains bootable Devil-Linux %DLVER%. PAUSE GOTO :EOF :Pcopy Set Flagfile=%TEMP%.\%RANDOM%.tmp If Exist %Flagfile% Del %Flagfile% Start /Min Copy %* ^& Echo.^>%Flagfile% ^& Exit REM (Set /P i=Copying %1) < NUL :Pcopy1 If Exist %Flagfile% (Goto :EOF) ::Echo period w/o carriage return/line feed (Set /P dummyvar=.) < NUL ::Wait c.3 secs Ping -n 6 127.0.0.1 > NUL Goto Pcopy1 :erred ECHO. ECHO Error %ERRORLEVEL% occurred, routine aborted...>&2 :erredexit ECHO %~nx0 has ended. PAUSE RMDIR /S /Q "%TEMP%\boot\" 2>nul DEL "%TEMP%\%~n0-*" 2>nul EXIT /B 1 :help ECHO Usage : %~nx0 [7z.exe-location] ECHO Dependencies: 7-Zip, syslinux.exe (32bit), fart.exe ECHO Tested on : Windows XP / Vista / 7 32/64-bit ECHO. ECHO Notes : You are prompted before changes are committed to USB drive. ECHO 1st or only partition of USB drive is (re)formatted, but any ECHO existing 2nd partition on USB drive (e.g. holding existing DL ECHO configuration) is not changed. ECHO 7z.exe-location does not normally need to be specified. PAUSE |