@echo off
if "%1" == "" goto usage
echo Warning the bootsector of drive %1 will be restored:
echo the file bootorig.sec will be written to the bootsector of drive %1
echo continue ONLY if bootorig.sec has been saved from drive %1
echo (and if the storage medium is the same)
echo .
echo WARNING: writing wrong bootsectors may result in data loss!!!
echo uninstal.bat restores the bootsector which was changed by install.bat
echo .
echo (press ctrl+c and then y to cancel; any other key to continue)
pause
echo .

rem check if we are outside the drive given by %1
if exist %1\spblinux.tmp del %1\spblinux.tmp
if exist \spblinux.tmp del \spblinux.tmp
echo spbinstallcheck>/spblinux.tmp
if exist %1\spblinux.tmp goto error1
if exist \spblinux.tmp del \spblinux.tmp

echo bootsector of drive %1 will be restored from bootorig.sec>log.txt
if not exist log.txt goto error0
echo read the bootsector of drive %1 ...
dd if=\\.\%1 of=bootorig.tmp bs=512 count=1
if not exist bootorig.sec goto error2
echo write the bootsector from bootorig.sec to drive %1 ...
dd if=bootorig.sec of=\\.\%1 bs=512 count=1
if errorlevel 1 goto error3
echo done. - the original boot sector has been written to drive %1

goto end

:usage
echo usage: uninstal g:
echo restores the bootsector of drive g: from file bootorig.sec
echo continue ONLY if bootorig.sec has been saved from drive g:
echo (and if the storage medium is the same)
echo .
echo WARNING: writing wrong bootsectors may result in data loss!!!
echo uninstal.bat restores the bootsector which was changed by install.bat
pause
goto end

:error0
echo Error: you need write access in
cd
echo The bootsector on drive %1 has not been changed.
goto end

:error1
del %1\spblinux.tmp
echo Error: install.bat must be run from the harddisk
echo (not from the drive where spblinux shall be installed;
echo copy the folder spbsetup to the harddisk)
echo .
echo The bootsector on drive %1 has not been changed.
goto end

:error2
echo Error: the file bootorig.sec was not found.
echo The bootsector on drive %1 has not been changed.
goto end

:error3
echo An error occurred when writing file bootorig.sec
echo to the bootsector of drive %1
goto end

:end
