From: Heiko Z. <smi...@us...> - 2010-11-04 18:10:21
|
Update of /cvsroot/devil-linux/build/scripts/scripts In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv3106/scripts/scripts Modified Files: install-on-usb.bat Added Files: install-on-usb.ico Log Message: - updated install-on-usb.bat (Dominic Raferd / HZ) --- NEW FILE: install-on-usb.ico --- (This appears to be a binary file; contents omitted.) Index: install-on-usb.bat =================================================================== RCS file: /cvsroot/devil-linux/build/scripts/scripts/install-on-usb.bat,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- install-on-usb.bat 28 Sep 2010 00:23:58 -0000 1.1 +++ install-on-usb.bat 4 Nov 2010 18:10:12 -0000 1.2 @@ -10,26 +10,43 @@ : 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 +: 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 +: Rev 0.3a 2010-11-01 - made it work as bare system no auto-drive searching and copy progress +: - best using it by dragging the drive icon on top of this batchfile +: - or by using as a command line tool, specifying the drive as parameter +: Rev 0.4b 2010-11-01 - restore copy with progress indicator +: - prevent run if a file rather than a drive has been specified +: - tidy messages, add colour, check for admin privileges +: Rev 0.4c 2010-11-03 - tiny but critical bugfix + SETLOCAL ENABLEDELAYEDEXPANSION +CLS +COLOR 1F 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 %~nx0 ECHO. -IF /I "%RESPONSE%"=="q" GOTO :erredexit -IF /I "%RESPONSE%"=="h" GOTO :help + +REM check for presence of drive specification +IF "%1"=="" GOTO :help +SET DRIVE=%1 +REM check for presence of colon +IF "%DRIVE:~1,1%" NEQ ":" SET FATALERR=y&ECHO You must specify a drive as parameter e.g. F:>&2 +REM check that it is only a drive that has been specified, not a file +IF "%DRIVE%" NEQ "%DRIVE:~0,3%" SET FATALERR=y&ECHO You must specify a drive as parameter e.g. F:>&2 +REM strips \ from drive specification +SET DRIVE=%DRIVE:~0,2% +REM drive c: not allowed +IF /I "%DRIVE%"=="c:" SET FATALERR=y&ECHO You cannot install to drive C:>&2 +REM originating drive not allowed +IF /I "%DRIVE%"=="%~d0" SET FATALERR=y&ECHO You cannot install to the drive you are running from ^(%DRIVE%^)>&2 REM check for presence of required files -IF "%1" NEQ "" ( - SET ZIPEXE=%1\7z.exe +IF "%2" NEQ "" ( + SET ZIPEXE=%2\7z.exe ) ELSE ( SET ZIPEXE=C:\PROGRA~1\7-Zip\7z.exe IF NOT EXIST "!ZIPEXE!" ( @@ -41,87 +58,20 @@ ) ) ) -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 +IF NOT EXIST "%~dp0fart.exe" SET FATALERR=y & ECHO Can't locate fart.exe, obtain this from SourceForge>&2 +IF NOT EXIST "%~dp0syslinux.exe" SET FATALERR=y & ECHO Can't locate syslinux.exe, obtain this by extracting from the latest syslinux release at kernel.org>&2 +IF NOT EXIST "%~dp0bootcd.iso" SET FATALERR=y & ECHO Can't locate bootcd.iso>&2 +REM end if there was a fatal error +IF "%FATALERR%" NEQ "" ECHO Aborting, for help run without parameters>&2&GOTO :erredexit +REM check that we have administrator privileges, this is a kludge but it works... +IF EXIST "%windir%\system32\%~nx0-test\nul" RMDIR "%windir%\system32\%~nx0-test" +MKDIR "%windir%\system32\%~nx0-test" 2>nul +IF ERRORLEVEL 1 ECHO This must be run as administrator & GOTO :erredexit +RMDIR "%windir%\system32\%~nx0-test" 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 @@ -129,7 +79,7 @@ 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 @@ -139,11 +89,13 @@ 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 -) +ECHO [h] Help information only +SET /P CONFIGOPT="Please enter 1,2,3 or h (any other key quits): " +IF /I "%CONFIGOPT%" == "h" GOTO :help +IF "%CONFIGOPT%" == "1" SET CONFIG=clean installation +IF "%CONFIGOPT%" == "2" SET CONFIG=pre-saved default configuration +IF "%CONFIGOPT%" == "3" SET CONFIG=pre-saved remote boot configuration +IF "%CONFIG%" == "" ECHO Aborting...&GOTO :erredexit REM Preparatory Action ECHO. @@ -151,28 +103,30 @@ 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 +IF ERRORLEVEL 1 ECHO Error extracting etc-mods.tar.bz2>&2&&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 +IF ERRORLEVEL 1 ECHO Error extracting etc-mods.tar>&2&&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 +IF ERRORLEVEL 1 ECHO Error extracting shadow>&2&&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 +IF "%ERRORLEVEL%" NEQ "1" ECHO Unable to set SSHD to operate at start-up>&2&&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 +IF "%ERRORLEVEL%" NEQ "1" ECHO Unable to set root password>&2&&GOTO :erred REM create autoselect eth0 dhcp network MKDIR "etc-mods\sysconfig\nic\">nul ECHO DEVICE=eth0>etc-mods\sysconfig\nic\ifcfg-eth0 @@ -208,30 +162,28 @@ 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% + +SET /P "dummyvar=Formatting %DRIVE%... "<nul 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% +IF ERRORLEVEL 1 ECHO Unable to format %DRIVE%>&2&&GOTO :erred +ECHO done +CHKDSK %DRIVE%>NUL +IF ERRORLEVEL 1 CHKDSK %DRIVE%&GOTO :erredexit + +SET /P "dummyvar=Installing Syslinux MBR and BootSector on %DRIVE%... "<nul "%~dp0syslinux" -ma %DRIVE% IF ERRORLEVEL 1 GOTO :erred +ECHO done 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 @@ -239,44 +191,79 @@ 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 + +REM put bootcd.iso file on drive, CopyWithProgress provides progress indicator +Call :CopyWithProgress "%~dp0bootcd.iso" %DRIVE% +IF ERRORLEVEL 1 ( + REM if CopyWithProgress failed then try with an ordinary COPY + ECHO. + ECHO Copying large file: bootcd.iso, PLEASE BE PATIENT... + copy "%~dp0bootcd.iso" %DRIVE% + IF ERRORLEVEL 1 GOTO :erred +) ELSE ( + ECHO . done +) + +SET /P "dummyvar=Deleting temporary files.."<nul +RMDIR /S /Q "%TEMP%\boot" 2>nul +DEL "%TEMP%\%~n0-*" 2>nul ECHO . done -RMDIR /S /Q "%TEMP%\boot" -DEL "%TEMP%\%~n0-*" -ECHO Completed successfully, %DRIVE% now contains bootable Devil-Linux %DLVER%. -PAUSE -GOTO :EOF + +REM Checking the drive +ECHO. +ECHO Drive %DRIVE% prepared: +CHKDSK %DRIVE% +IF %ERRORLEVEL% NEQ 0 GOTO :erred + +ECHO. +ECHO Success! %DRIVE% contains bootable Devil-Linux %DLVER% with %CONFIG%. +GOTO :end + +:CopyWithProgress +:: Copy, displaying progress dots +SETLOCAL ENABLEDELAYEDEXPANSION +SET Flagfile=%TEMP%\%RANDOM%.tmp +IF EXIST %Flagfile% DEL %Flagfile% +START /MIN COPY %* ^& ECHO.^>%Flagfile% ^& EXIT +SET LOOP=0 :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 +IF EXIST %Flagfile% Goto :EOF +::Show a period +REM SET /P dummyvar=!LOOP!<NUL +SET /P dummyvar=.<NUL ::Wait c.3 secs -Ping -n 6 127.0.0.1 > NUL -Goto Pcopy1 +ping -n 6 localhost > NUL +::Loop counter should not exceed 100 i.e. c.5 minutes +SET /A LOOP=!LOOP!+1 +IF %LOOP% GTR 100 EXIT /B 1 +GOTO Pcopy + :erred -ECHO. +ECHO.>&2 ECHO Error %ERRORLEVEL% occurred, routine aborted...>&2 + :erredexit -ECHO %~nx0 has ended. +ECHO %~nx0 has ended.>&2 PAUSE RMDIR /S /Q "%TEMP%\boot\" 2>nul DEL "%TEMP%\%~n0-*" 2>nul EXIT /B 1 + :help -ECHO Usage : %~nx0 [7z.exe-location] +ECHO This formats and provisions a USB drive as a Devil-Linux boot disk. +ECHO. +ECHO Usage : %~nx0 DRIVE:[\] [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 Notes : Easy start - drag'n'drop USB drive onto %~nx0. +ECHO Must be run as administrator / with admin privleges +ECHO You are prompted before changes are committed to USB drive. +ECHO The USB drive cannot be drive C: 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. +ECHO. +:end PAUSE \ No newline at end of file |