Shell script to update a bunch of ISO files with jigdo

Let's say you're using jigdo to download installation images of your favorite operating system. If you don't, you should, because jigdo allows you to quickly and efficiently update your ISO images by downloading only the differences between your existing ISO and the latest currently available, saving time and bandwidth. Here's how to get started with jigdo.

If you've got a directory full of .iso files and matching .jigdo files, instead of updating each individually, could run the script below whilst inside the directory to update them all at once.

Script in action:

ak@lark:~/nfs/shared/Software/Linux/ISO$ jigdo.update 
2011-11-25 15:25:57 jigdo.update INFO: jigdo file(s) found
2011-11-25 15:25:57 jigdo.update INFO: processing debian-testing-amd64-CD-1.jigdo
2011-11-25 15:25:57 jigdo.update INFO: mounting /var/nfs/shared/Software/Linux/ISO/mnt
mount: warning: mnt/ seems to be mounted read-only.
2011-11-25 15:25:57 jigdo.update INFO: removing debian-testing-amd64-CD-1.iso
2011-11-25 15:25:57 jigdo.update INFO: processing debian-testing-amd64-CD-1.jigdo with jigdo-lite

Jigsaw Download "lite"
Copyright (C) 2001-2005  |  jigdo@
Richard Atterer          |  atterer.net
Loading settings from `/home/ak/.jigdo-lite'

-----------------------------------------------------------------
Images offered by `debian-testing-amd64-CD-1.jigdo':
  1: 'Debian GNU/Linux testing "Wheezy" - Official Snapshot amd64 CD Binary-1 20111121-05:07 (20111121)' (debian-testing-amd64-CD-1.iso)

Further information about `debian-testing-amd64-CD-1.iso':
Generated on Mon, 21 Nov 2011 05:15:48 +0000
Path to scan: mnt/

Not downloading .template file - `debian-testing-amd64-CD-1.template' already present
Found 1078 of the 1078 files required by the template
Successfully created `debian-testing-amd64-CD-1.iso'

-----------------------------------------------------------------
Finished!
The fact that you got this far is a strong indication that `debian-testing-amd64-CD-1.iso'
was generated correctly. I will perform an additional, final check,
which you can interrupt safely with Ctrl-C if you do not want to wait.

OK: Checksums match, image is good!   
2011-11-25 15:26:02 jigdo.update INFO: unmounting /var/nfs/shared/Software/Linux/ISO/mnt

Get the script:

#!/bin/bash

err_exit()
{
 echo -e 1>&2
 exit 1
}

if [ ! -f *.jigdo ]; then
 echo "$(date +%F\ %T) $(basename $0) ERROR: no jigdo files in current dir"
 exit 1
else
 echo "$(date +%F\ %T) $(basename $0) INFO: jigdo file(s) found"
fi

dir="$(pwd -P)"

for f in *.jigdo; do
 echo "$(date +%F\ %T) $(basename $0) INFO: processing $f"
 iso=$(echo $f | sed 's/.jigdo/.iso/')
 if [ ! -f $iso ]; then
  echo "$(date +%F\ %T) $(basename $0) ERROR: can't find $iso"
 else
  if [ ! -d mnt ]; then
   mkdir mnt || err_exit
  fi
  if grep -qs "$dir/mnt" /proc/mounts; then
   echo "$(date +%F\ %T) $(basename $0) INFO: $dir/mnt is already mounted, unmounting"
   sudo umount "$dir/mnt" || err_exit
  fi
  echo "$(date +%F\ %T) $(basename $0) INFO: mounting $dir/mnt"
  sudo mount -o loop $iso mnt/ || err_exit
  echo "$(date +%F\ %T) $(basename $0) INFO: removing $iso"
  rm $iso || err_exit
  echo "$(date +%F\ %T) $(basename $0) INFO: processing $f with jigdo-lite"
  jigdo-lite --scan mnt/ $f || err_exit
  echo "$(date +%F\ %T) $(basename $0) INFO: unmounting $dir/mnt"
  sudo umount "$dir/mnt" || err_exit
 fi
done

2 Comments

  • 1. Aji replies at 22nd December 2011, 9:45 am :

    wow, thank you

  • 2. mark replies at 7th April 2013, 8:58 am :

    Please don’t remove the old iso, just mv it and mount it, for the sake of those who don’t cache the packages on an nfs.

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).