Making An Autorun CD/DVD
I grant you, most people have little reason to read this post. However, one day, some person will visit this post looking to do precisely what this post talks about! If you're just wanting to read about the autorun part of the post, it is explained towards the bottom - the first half of the post talks about the rest of the CD/DVD!
As part of the technical work that I do for the Baptist Union of Scotland Youth, I have, for the last two years, produced a mission review CD (last year) or DVD (this year) which is mainly full of photographs from missions, with a few other bits thrown in. The CD or DVD is based around an HTML browser through which you - guess what - browse through all the photos from the missions. Other bits thrown in might be a couple of small videos, an evaluation form, contact details, website links, etc... It's generally easier if you can make the CD/DVD run automatically since you then don't have to worry about making sure people know which files to run, etc... (although if they have disabled autorun, then you do, but it's their problem if they've done that). Anyway, my methodology for making the CD/DVD goes as follows:
- Decide upon the size limit for the recording medium (mainly determined by whether I'm using a CD or DVD, which is mainly dependent upon how much data I have to share!);
- Organise the data into the different sections on the CD/DVD (for me, this usually consists of splitting the photos into the different locations of the missions, then working out how to sort the other data out, for example, by making a "video" and "extras" section);
- Designing the interface - simple HTML really, although for the DVD this year, I needed to change and extend the resolution of an existing template, which was slightly fiddly, but not particularly difficult;
- Working out, from the template, the required size for the pictures (I overcomplicate this procedure, using three different resolutions: small (for browsing the whole lot in one folder, the medium size, for looking at individually within the browser, and a large one, for if people want to do anything with it - although sounding complicated, the end result looks better than browser-stretched images which just look really pixelated);
- Resizing all the pictures to the right sizes - this is the longest part of the job, but I can usually go and do other things whilst this happens (as a Linux user, I use mogrify, a simple but efficient command-line utility - a version is also available for Windows, but I've never tried it).
This provides me with the base that I need to put everything together. However, there is then the small matter of one HTML file for each standard size picture. The DVD this year had 2,701 photographs on it, and I'm sure not going to write 2,701 HTML files to go with them! Thus, I need a script that does it for me. In steps galrey, a Linux command-line program. All I do is fill in a few variables and set it off to create all the files for me, and an index.html file for each folder. It does require some fiddling: as with most command-line programs I know, its HTML is pretty shoddy, but it does the scripting fantastically well. Having altered the HTML, cleaning it up and applying my template, all is fine and dandy. I am then left to add my extra pages manually and to put in an index.html file for the disk as a whole. Easy. At this point, I usually spot a mistake in my navigation bar and realise I need to repeat this step of the process, but never mind!
Thus, the CD/DVD is pretty much complete. The one bit left to do is to make the CD/DVD run automatically. I should, at this point, make two quick points. Firstly, it doesn't matter whether the medium is a CD, DVD, or even a USB storage device, the autorun method is the same - although all three require a PC which is set up to automatically run the medium if autorun is detected. Secondly, I'm not going to talk about Macs. I don't provide autorun support to Macs. It's just too much effort. Well, okay, so it's also to do with the fact that I don't have a Mac to test on, so I couldn't guarantee it would work!
Making the DVD run automatically on Windows and Linux is done separately. It's meant to be easiest to do on Windows, but I've found it easiest on Linux, partly because of a script I found as part of another autorun guide. Thus, I'll talk about autorun on Linux first.
Autorun on Linux
If you take a look at the script, which looks to execute an index.html file, you'll see it's a simple bash script, designed to look for a web browser through which it can execute the file index.html. Very simple really. Except, I found it didn't work. Thus, I set about modifying it. The first problem was that, when I ran the script from inside an existing terminal window, the terminal claimed no browser was available to execute index.html. This seemed a little odd, since I have Firefox installed, and the script includes both Mozilla and Netscape. However, a quick look at my system showed that Firefox is executed through the "firefox" command, so I added this to the script. (Firefox is launched through one of a few different commands depending upon a linux system: sometimes by the command "firefox", sometimes "mozilla-firefox", and occasionally by use of the command "mozilla". Confusing!)
The second problem I found was that when Firefox opened, I simply a tab which showed my homepage and a tab showing some folder on my Linux install. Not very helpful if you don't know where to find index.html! However, a closer inspection of the script explained to me why this was.
The script tries to set the first tab through autorun.inf (which I actually use to autorun for Windows, but I'll go into that later), but doesn't succeed, because autorun.inf doesn't contain this information! Therefore, it has ended up showing a directory it shouldn't be showing (I can't remember what it was, but the point is, it wasn't what I wanted, therefore it didn't work!).
A rush of common sense overtook my brain for a split second, and I decided that there was actually no point in processing anything through autorun.inf at all, when I could just specify index.html instead of autorun.inf. I also realised, however, that there was a problem in specifying "$BROWSER /media/cdrom", since /media/cdrom is completely pointless on my system - my two CD/DVD drives are /media/cdrom0 and /media/crdom1. Thus, it will never find the right folder. The solution? Easy, take out the absolute link and replace it with a relative one - index.html. Since we're already in the folder with the index.html file, there's little point in searching for it - we already know where it is!
Curiously, however, there is still the second tab, which shows the homepage. This is shown because the very bottom of the script tells the browser to open it. Since I'm not personally wanting anyone to look at their homepage (they can open it themselves if they want), I just deleted this part of the script. Now, the script works wonderfully on my Linux system. When I place the DVD in my drive, a pop-up alerts me that it has detected autorun, would I like to enable it? I click "confirm", to confirm that I am expecting it and it's not going to eat my computer, and it opens index.html in all its glory. Fantastic. If you want to see my modified script, you can. To use the script, rename it "autorun" (with no file extension!) and place it in what will be your CD/DVD/USB's root directory.
I should say that I suspect the bottom part of my script is unnecessarily bloated. At the bottom, my modified script reads:
HOMEPAGE=`grep homepage index.html | awk 'BEGIN {FS="="} {print $2}'`
if [ ! -f "$HOMEPAGE" ]; then
$BROWSER index.html &
fi
exit 0
It would probably work reading just:
$BROWSER index.html &
exit 0
However, I've not actually tried this to make sure. If it works, great. If it doesn't, just use it as it appears in the text file. So anyway, that was autorun on Linux.
Autorun on Windows
Autorun on Windows - supposedly easier, though not for me. The problem is that there are so many different ways of doing it. The way I've done it is by writing an autorun.inf file with this inside it:
[autorun]
shellexecute=index.html
shell=index.html
icon=favcon.ico
In theory, this should work. In practice, I've found it to work some of the time, but not all of the time. However, when it doesn't work, Windows Explorer seems to come up anyway, so as long as the user thinks to click on the index.html file, then they're fine.
However, ideally we need a workaround. There are plenty of programs out there that will do the job for you, but most are closed source, proprietary solutions. I want an open source solution. And I've found it. "What is it?", I hear you ask. Well, I'll tell you, as long as you promise to keep quiet about it. It's Firefox Portable. You see, Firefox Portable is set up to work from USB keys, using a relative path, and so it immediately gets around the problem of which browser to use. You simply include the browser on the CD, DVD or USB key and specify the autorun.inf file to launch, via a relative path, the executable file on startup. Thus, all you have to do is write the autorun.inf file. Easy!
Well, actually, that's not quite all. You see, if you do that, and burn it all to a CD or DVD, you'll run into a problem. The problem is that Firefox is not able to run from read-only media. The trouble is, that's exactly what we're trying to do! Well, there is a way around it. First, we must run FirefoxPortable so that the application creates all the files it needs in order to operate. Then, we need to go to the FirefoxPortable/Other/Source/ directory and copy the FirefoxPortable.ini file to the main FirefoxPortable directory.
This file is our friend. We want to open and edit the file, in a normal text editor. The crucial line in the file is the last line, where it says "RunLocally=false". We want to change this value to false, which forces Firefox to run in the RAM, and so means that it doesn't try to save anything to the hard drive, which is what caused our errors.
Next, we want to set the homepage for our users, using a relative path, specified half-way down the file in "LocalHomepage". This is most likely to be "../index.html", or similar (without the quotation marks - they're for your benefit). Once this is done, make sure you launch the browser to make sure it does what you want it to.
Please note, if you then want to make a change, you must change "RunLocally" back to "false", or your changes will not work. You can, if I remember correctly, install themes as you wish, and add-ons too, as long as they don't require writes to the CD, DVD or USB stick when used by the end-user. However, you cannot use relative bookmarks. I've tried this without success. Bookmarks require absolute paths, it would seem. You should probably attach a note to say that the attached browser should not be used for general Internet use. This is because you are not able to install security patches, and so computer security could be compromised. The risk is not a great one, but a cautionary note won't harm.
The autorun.inf file would read as follows:
[Autorun]
Open=FirefoxPortable\FirefoxPortable.exe
Action=Open BUSY Photo DVD 2007
Label=BUSY Photo DVD 2007
Icon=favicon.ico
Now that all this is done, you are ready to burn your media! Just make sure you didn't make a mistake...
I hope this tutorial has been helpful. I certainly had fun trying everything out, and it was a great help to be able to get around browser compatibility issues (well, Internet Explorer issues!) by simply distributing a browser with my work. Kudos especially to John Haller on that one.
There are currently 2 comments on this article.
Noelinhohttp://www.noelinho.org
Thanks for that mrBen, I'll look into it some time. My script does look for more than Firefox: it looks for Opera, Konqueror too, the reference to Firefox was merely that if you do have Firefox installed, then it isn't always launched with the same command. However, xdg-open does look like a better all-round solution. :)
2008-02-04 14:15:20
mrben
http://www.jedimoose.org
You might want to look into (on the Linux side) 'sensible-browser' and 'xdg-open', which aim to open the default browser chosen by the user, which may not be Firefox.... (I believe xdg-open is the standard, and part of the freedesktop spec, so should work in GNOME, KDE, XFCE at least - you could use your current code as a failover)
2008-02-04 11:47:17
