Rockbox Technical Forums

Rockbox General => Rockbox General Discussion => Topic started by: Shiftlock on April 20, 2010, 03:08:42 AM

Title: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 20, 2010, 03:08:42 AM
This Windows batch script will download the current build for your player, and install it.  Note that this isn't the "stable" release version that Rockbox Installer defaults to, it's the current build which is updated daily with the latest changes.  It's pretty good at telling you what it's doing while it's doing it, like giving you the percent complete while it's downloading, and displaying the old version of Rockbox on your player, and the new version it's installing.  I set this script to run automatically each night so my player is always running the latest build. 

All you have to do is run it, and it will do the rest.  It will detect the drive letter and model of your player, and download the correct version for your model, then install it.  If you prefer, or if there's a problem with the player determining the location and player model, you can define these settings manually in the beginning of the script.

This script requires two utilities in order to run properly.  They may be on your system already (one of them should be included with Vista and Windows 7) but if they're not, the script will help you download them.

Sometimes Windows throws an error when the script tries to look for the DAP on a removable media drive that doesn't have media in it (like the memory expansion slot on the side of some players).  I can't figure out a way to trap that error, but it can be ignored by pressing the "Continue" button, which is what the script instructs you to do. 

The script makes a directory under c:\Program Files (or wherever your "Program Files" directory is located) called RockboxUpdate where it downloads Rockbox and unzips it before installing.

If anybody tries this script, I would be interested in hearing about any problems, comments, suggestions, or even if it just worked successfully for you.  I think I pushed myself and Windows Batch to the very limit of our respective abilities with this script.

You can copy the code below into a .bat file yourself, or download it from here: http://www.mediafire.com/file/ozoyzowdmrz/RockboxUpdate.bat

Code: [Select]
::
::     This Windows batch script will update your player to the most current build of Rockbox.
::
::     If desired, change the following "set" definitions to reflect your configuration.  If
::     left blank, the script will automatically determine the correct settings.

:: *** This script will automatically determine the correct URL for your model player unless it's specified here
set RockboxURL=

:: *** This script will automatically locate your player unless the drive letter is specified here
Set DAPLetter=

:: -------------------------------------------------------------------------------------------

@echo off
setlocal enableextensions

if exist %Systemroot%\System32\bitsadmin.exe GoTo FindDAPLetter
if exist %systemroot%\MPSReports\MSUS\bin\bitsadmin.exe GoTo FindDAPLetter
if exist %Systemroot%\bitsadmin.exe GoTo FindDAPLetter
GoTo BitsAdminNotFound

:FindDAPLetter
cls
if defined DAPLetter GoTo FindRockboxURL
echo Locating Your Player...
echo.
echo *****************************************************************************
echo ***                                                                       ***
echo ***  If a Windows error box pops up, simply choose "Continue". This will  ***
echo ***  not have a negative effect on locating or updating your player.      ***
echo ***                                                                       ***
echo *****************************************************************************
FOR %%g 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 IF EXIST %%g:\.rockbox\rockbox-info.txt SET DAPLetter=%%g
if (%DAPLetter%)==() GoTo DAPNotFound

:FindRockboxURL
cls
if defined RockboxURL GoTo CheckDir
for /f "delims=" %%h in ('qgrep -e "Target:" %DAPLetter%:\.rockbox\rockbox-info.txt') do @set TargetDefine=%%h
set PlayerType=%TargetDefine:~8%
Set RockboxURL=http://build.rockbox.org/data/rockbox-%PlayerType%.zip

:CheckDir
cls
echo Checking for RockboxUpdate Directory...
if exist "%programfiles%\RockboxUpdate" GoTo CheckForUnzip
mkdir "%programfiles%\RockboxUpdate"

:CheckForUnzip
set path=%path%;%systemroot%\MPSReports\MSUS\bin;%programfiles%\RockboxUpdate
cls
echo Checking For unzip.exe to Extract Rockbox Files...
if exist "%programfiles%\RockboxUpdate\unzip.exe" GoTo Begin

cls
bitsadmin /RawReturn /Reset
bitsadmin /RawReturn /Create DownloadUnzip
bitsadmin /RawReturn /AddFile DownloadUnzip http://stahlworks.com/dev/unzip.exe "%programfiles%\RockboxUpdate\unzip.exe"
bitsadmin /RawReturn /Resume DownloadUnzip

:StatusLoop1
for /f "delims=" %%d in ('bitsadmin /RawReturn /GetState DownloadUnzip') do @set DownloadUnzipStatus=%%d
for /f "delims=" %%e in ('bitsadmin /RawReturn /GetBytesTotal DownloadUnzip') do @set DownloadUnzipBytesTotal=%%e
for /f "delims=" %%f in ('bitsadmin /RawReturn /GetBytesTransferred DownloadUnzip') do @set DownloadUnzipBytesTransferred=%%f
Set /A DownloadUnzipPercentDone = (%DownloadUnzipBytesTransferred% * 100) / %DownloadUnzipBytesTotal%

cls
echo Downloading unzip.exe to Extract Rockbox Files
echo Status: %DownloadUnzipStatus%
echo File Transfer is %DownloadUnzipPercentDone%%% Complete

ping 224.0.0.0 -n 1 -w 500 > NUL
if %DownloadUnzipStatus% EQU TRANSIENT_ERROR GoTo ErrorDownloadingUnzip
if %DownloadUnzipStatus% NEQ TRANSFERRED GoTo StatusLoop1
bitsadmin /Complete DownloadUnzip

:Begin

cls
echo Deleting Old Rockbox Files...
del /F /Q "%programfiles%\RockboxUpdate\Rockbox_Current.zip"
rd /S /Q "%programfiles%\RockboxUpdate\.rockbox"

cls
echo Starting Transfer of Latest Rockbox Build For: %PlayerType%
bitsadmin /RawReturn /Reset
bitsadmin /RawReturn /Create rockbox
bitsadmin /RawReturn /AddFile rockbox %RockboxURL% "%programfiles%\RockboxUpdate\Rockbox_Current.zip"
bitsadmin /RawReturn /Resume rockbox

:StatusLoop2
for /f "delims=" %%a in ('bitsadmin /RawReturn /GetState rockbox') do @set status=%%a
for /f "delims=" %%b in ('bitsadmin /RawReturn /GetBytesTotal rockbox') do @set BytesTotal=%%b
for /f "delims=" %%c in ('bitsadmin /RawReturn /GetBytesTransferred rockbox') do @set BytesTransferred=%%c
Set /A PercentDone = (%BytesTransferred% * 100) / %BytesTotal%

cls
echo Downloading Latest Rockbox Build For: %PlayerType%
echo Status: %status%
echo File Transfer is %PercentDone%%% Complete

ping 224.0.0.0 -n 1 -w 500 > NUL
if %Status% EQU TRANSIENT_ERROR GoTo ErrorDownloadingRockbox
if %status% NEQ TRANSFERRED GoTo StatusLoop2
bitsadmin /Complete rockbox

:unzip
cls
echo Unzipping Latest Rockbox Build...
unzip -o -qq "%programfiles%\RockboxUpdate\Rockbox_Current.zip" -d "%programfiles%\RockboxUpdate"

::Determine Old Version
for /f "delims=" %%i in ('qgrep -e "Version:" %DAPLetter%:\.rockbox\rockbox-info.txt') do @set OldVersion=%%i
set OldVersion=%OldVersion:~9,-7%

::Determine New Version
for /f "delims=" %%j in ('qgrep -e "Version:" "%programfiles%\RockboxUpdate\.rockbox\rockbox-info.txt"') do @set NewVersion=%%j
set NewVersion=%NewVersion:~9,-7%

cls
echo Updating Your Player with the Latest Rockbox Build For: %PlayerType%
echo.
echo Old Rockbox Version: %OldVersion%
echo New Rockbox Version: %NewVersion%
echo.
echo Please Wait...
xcopy "%programfiles%\RockboxUpdate\.rockbox" %DAPLetter%:\.rockbox /C /E /H /I /R /Y /Q

bitsadmin /Reset
cls

echo Your %PlayerType% Has Been Updated With Rockbox Version %NewVersion%
echo.
echo This Window Will Close Momentarily...
ping 224.0.0.0 -n 1 -w 5000 > NUL

endlocal
exit


::------------------
::Error Handling
::------------------

:ErrorDownloadingUnzip
cls
echo.
echo The following error occurred while downloading unzip.exe:
echo.
bitsadmin /GetError DownloadUnzip
echo.
echo Please restart this script, or try again later.
echo.
pause
bitsadmin /Reset
endlocal
exit

:ErrorDownloadingRockbox
cls
echo.
echo The following error occurred while downloading Rockbox:
echo.
bitsadmin /GetError Rockbox
echo.
echo Please restart this script, or try again later.
echo.
pause
bitsadmin /Reset
endlocal
exit

:DAPNotFound
cls
echo.
echo The script could not locate your player. Make sure it's plugged in and run
echo this script again. If it is plugged in, then manually edit script and modify
echo "Set DAPLetter= " to reflect your player's drive letter.
echo.
pause
bitsadmin /Reset
endlocal
exit

:BitsAdminNotFound
cls
echo.
echo This script requires the Microsoft BITS Administration utility in order to
echo download files. This utility could not be found on your system. You will now
echo be forwarded to a Microsoft URL to download the MS Support Services Reporting
echo Tool, which includes the needed BitsAdmin utility. Run this script again after
echo you have downloaded and installed it.
echo.
pause
cmd /c start http://download.microsoft.com/download/b/b/1/bb139fcb-4aac-4fe5-a579-30b0bd915706/MPSRPT_SUS.EXE
endlocal
exit
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: evilnick on April 20, 2010, 06:57:08 AM
I guess that this would be more useful in the Wiki rather than on the forums.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 20, 2010, 01:29:03 PM
Oh, okay.  It didn't occur to me to put it in the wiki.  I've never contributed to it.  I'll look into that tonight.  For now, if anyone wants the companion executables (bitsadmin.exe, sleep,exe, and unzip.exe) I zipped them together with this batch file and it can be downloaded here:

Edit: I removed the link because someone suggested it may be a licensing violation.  Sorry.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Llorean on April 20, 2010, 01:30:39 PM
What are the licenses on those?
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 20, 2010, 02:35:06 PM
What are the licenses on those?

unzip.exe - "Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely."

bitsadmin.exe - This is already part of Vista and Windows 7, and is included with XP Service Pack 2 Support Tools, which can be downloaded from MS.  I can't find any specific licensing information, but I think anyone running Windows will already have a copy of this somewhere on their system.

sleep.exe - I don't know where this came from.  It's such a simple program, there are quite a few different programs called "sleep.exe" floating around the net that all do the same thing.  I suppose I could just re-write this myself.

If it's an issue, I'll remove the link, or just delete the info in this thread entirely.  I certainly didn't intend to steal anyone's software.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Llorean on April 20, 2010, 02:50:12 PM
If you don't have permission to redistribute them (which you seem not to for the latter two) you shouldn't, so the link should at least be removed.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 20, 2010, 05:12:43 PM
Link removed.  Try Google, or PM me if you need help finding these files, and I'll point you in the right direction.  They can all be legally downloaded from the owners' sites without violating any copyrights.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: torne on April 21, 2010, 04:41:49 AM
You could just link to the authors' sites, that's a perfectly legitimate thing to do...
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: pondlife on April 21, 2010, 05:20:15 AM
A hacky way to wait for one second, assuming that's what "sleep 1" does:

Code: [Select]
ping 224.0.0.0 -n 1 -w 1000
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: gulak on April 21, 2010, 01:48:02 PM
Link removed.  Try Google, or PM me if you need help finding these files, and I'll point you in the right direction.  They can all be legally downloaded from the owners' sites without violating any copyrights.
A link never violates a copyright.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: torne on April 21, 2010, 02:08:03 PM
Indeed, but we don't want people to link to copyright-infringing files. Linking to a site which has *permission* to distribute something is fine, as I already said.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 22, 2010, 03:08:17 AM
I edited the original post in this thread.  I modified the script to use the "ping" trick suggested by pondlife, so sleep.exe is no longer necessary.  I also added download links for the other two files.  These links point to the authors' own sites, so there is no copyright violation.

Again, I'm sorry for creating a potential copyright issue.  It wasn't intentional.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: torne on April 22, 2010, 04:29:35 AM
A much simpler replacement for BitsAdmin, which is using the complex MS background downloader service, is wget, which is available for pretty much any OS and works in the foreground, so you don't need the status polling loop. wget is GPLed and thus you can redistribute it if you wish.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 24, 2010, 04:32:02 AM
I made some major changes to this batch script, so I edited the original post in this thread with the updated code and info.  Is anybody interested in testing it?  It's quite a bit more complex now. I'm sure there are better ways to do a lot of this, seeing that this is the first programming I've messed with since BASIC on the Commodore 64 over 25 years ago, so please, no laughter if my routines and syntax are backasswards. <grin>

The script will now:


The only variable that needs to be manually defined is the URL for the player's Rockbox build.  I haven't figured out a way to determine that yet, although looking in the .rockbox/rockbox-info.txt file might be the answer.

Question: The only DAP I've installed Rockbox on is the Sansa Fuze V1 and V2.  Is the process of installing a new compiled build the same on other players (i.e. copy the .rockbox folder)?
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: bluebrother on April 24, 2010, 04:47:11 AM
The only variable that needs to be manually defined is the URL for the player's Rockbox build.  I haven't figured out a way to determine that yet, although looking in the .rockbox/rockbox-info.txt file might be the answer.

Yes, that's a possible way. Rockbox Utility uses this file (amonst other measures) to detect the player, and if that file is found the detection is unique (various other methods used for detecting the player are not).

Quote
Question: The only DAP I've installed Rockbox on is the Sansa Fuze V1 and V2.  Is the process of installing a new compiled build the same on other players (i.e. copy the .rockbox folder)?

yes.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 24, 2010, 04:18:54 PM
Question: The only DAP I've installed Rockbox on is the Sansa Fuze V1 and V2.  Is the process of installing a new compiled build the same on other players (i.e. copy the .rockbox folder)?

yes.

Great, then this script should work with any player.  I would like to make it auto-detect the type of player.  In the .rockbox\rockbox-info.txt file, my V1 Fuze says:

Target: sansafuze
Target id: 53
Target define: -DSANSA_FUZE

And my V2 Fuze says:

Target: sansafuzev2
Target id: 68
Target define: -DSANSA_FUZEV2

Does anybody know where I can get a list of "Target" information for all DAP models that have Rockbox builds?
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: bluebrother on April 25, 2010, 03:41:06 AM
Does anybody know where I can get a list of "Target" information for all DAP models that have Rockbox builds?

As (indirectly) said earlier, check out how Rockbox Utility handles things: http://svn.rockbox.org/viewvc.cgi/trunk/rbutil/rbutilqt/rbutil.ini?view=markup
Basically, the "Target" line holds the unique target name that is also used for download file names. Note this line in the file I've linked above:
Code: [Select]
http://build.rockbox.org/data/rockbox-%MODEL%.zip
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 30, 2010, 02:13:46 AM
Well, I think I've finished this script.  Nothing needs to be manually changed or modified, just run the batch file and it will update any player that already has Rockbox installed to the current build (not the stable release build, but the current build with the latest changes that is updated daily).

The script will now determine the model of player, and download/install the correct build.  It will also determine the drive letter of your player.  It will check your system for the needed supporting programs (unzip and BITSAdmin download utility) and if they're not on your system, it will help you download/install them.  It will display download progress, as well as the old version on your player and the new version it's installing.

I edited the original post in this thread to reflect the changes, new code, as well as the URL to download the script if you prefer to get it that way.  If anybody tries it, I would be interested to hear how it works for you.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Llorean on April 30, 2010, 02:30:53 AM
I'm curious, why all this effort? What lacking functionality of RBUtil is this to address?
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: fml2 on April 30, 2010, 02:42:53 AM
I don't like the fact that the script (IIUC) creates some folders on the computer.

But the main question, as Llorean said, is: why would you need it? RBUtility already does it, and has some advantages:


The good feature of the script is that it can run unattended. I think we could/should add some command line switches to RBUtility so that it can do that too.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Llorean on April 30, 2010, 02:45:23 AM
There's been some effort toward a console interface for RBUtil as it is, since it can also be easier for some blind users to use.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 30, 2010, 03:18:01 AM
I'm curious, why all this effort? What lacking functionality of RBUtil is this to address?

The main reason was because I wanted something I could run as a scheduled task, so I needed a program that would update the player with no user input.  Also, I have more than one player, so I wanted something that would detect which one is currently plugged into the computer.  Actually, I'm using a slightly different version of the script that scans for multiple drive letters/models, and updates all the players plugged into the computer with the proper build.  It does this with a single click (or a single execution from the Task Manager).  With RBUtil, I had to manually go through and change the settings to update each player, which was rather time consuming with six different players to update, and there was no way to schedule an update for even a single player from the Task Manager.  Now I can just plug them all in at night, and I know they'll always have the current build.

Someone mentioned the visually impaired, which is another potential use.

Regarding the script creating a directory, well, where was it supposed to download the file to without creating a directory?  I could have made it use the default Windows temp directory, but I figured it was better if it worked under its own directory where all the activity could be monitored.  The directory it creates is under the default %programfiles% directory, where most software packages install themselves and work.

I guess what it comes down to is that, once setup, it's just easier to use than RBUtil.  If RBUtil had command-line switches so that I could set it to automatically run the way I wanted, then close, that would be ideal.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Llorean on April 30, 2010, 03:20:34 AM
Just as a note - the current build is updated multiple times a day (any time the source code changes) and blindly updating to a development build can also leave you with an unusable player throughout the day.

But fml2 is basically right - most of this could've been accomplished by improving RBUtil (and a lot of this is in areas we'd like to see it improved in, I think).
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: Shiftlock on April 30, 2010, 03:36:22 AM
But fml2 is basically right - most of this could've been accomplished by improving RBUtil (and a lot of this is in areas we'd like to see it improved in, I think).

Agreed.  But I'm no programmer, and Windows Batch already stretches the limit of my knowledge and ability.

There's one more thing about this script that I find useful, which is kind of hard to explain, but I'll try.  The script will unzip the .rockbox directory to the same location on my harddrive as the old .rockbox directory, without deleting any files that it doesn't overwrite.  That way, when I copy the .rockbox directory to the player, it will install the new version along with any config files that were saved under the .rockbox directory on the hard drive.  One of my players is a Fuze V2, which does not yet have write support, so this way I can install the new build along with all of my settings.

Similarly, I can update all four of my Fuze V1 players with exactly the same settings by copying the .rockbox directory tree with the config files in it to all of my players.  This was the other reason for the script creating a directory, where the .rockbox directory tree(s) could live on the hard drive with the config files in them.

This may be an obscure benefit that only I would find useful, but I do.  Granted, the code I posted doesn't do this, because I didn't think anyone else would want to use it that way, but simply removing the line that deletes the .rockbox directory on the hard drive would do it. 

I hope that was comprehensible.  Sorry if it wasn't.

Regarding the current build leaving the player unusable, well, that's always a possibility when you install a development build.  It a risk I'm willing to take in order to test the firmware with the latest features and fixes on my players.  If the function of my players was critical to me, I would definitely run the stable release build.  That said, I haven't found a current build yet that has prevented my players from working exactly the way I want them to.


Edit:  I forgot one more benefit over RBUtil, which is one of the main reasons that prompted me to make this script in the first place.  RBUtil won't work with my Fuze V2, because it's categorized as "unusable" and not yet supported.  This script will work with any model that has a current build, no matter what its status.
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: fml2 on April 30, 2010, 04:30:54 AM
Edit:  I forgot one more benefit over RBUtil, which is one of the main reasons that prompted me to make this script in the first place.  RBUtil won't work with my Fuze V2, because it's categorized as "unusable" and not yet supported.  This script will work with any model that has a current build, no matter what its status.

Ok, that's a killer argument!

But apart from all other things: I think a batch mode would be a very nice feature for RBUtil. I'd do it like this: create small "profiles" and specify them on the command line. Each profile specifies what player to update, with what version (current/release) etc., and is "interpreted" by the RBUtil. There could also be other parameters which are not contained in a profile, e.g. "continue with further profiles even if one profile fails" etc. Then updating Rockbox would be a matter of one mouse click. Now it's a matter of three or four! :-)
Title: Re: Windows Batch Script for Updating to Latest Rockbox Build
Post by: bluebrother on April 30, 2010, 08:32:06 AM
I forgot one more benefit over RBUtil, which is one of the main reasons that prompted me to make this script in the first place.  RBUtil won't work with my Fuze V2, because it's categorized as "unusable" and not yet supported.

Just for the record, adding a new player to Rockbox Utility is pretty simple as long as either no new method for installing the bootloader is required or bootloader installation isn't of interest. For example, the Gigabeat S is supported by Rockbox Utility (though as "disabled" target), but bootloader installation hasn't been implemented (hence the "disabled" classification). For adding a new target that way you basically only need to edit rbutil.ini and recompile.