Added jigdump, a simple utility to dump the contents of a template file.
[jigit.git] / jigit
1 #!/bin/bash
2 #
3 # jigit
4 #
5 # (c) 2004 Steve McIntyre
6 #
7 # Wrapper for jigdo to make updating CDs easier
8 #
9
10 # Some definitions
11 APT_CACHE=/var/cache/apt/archives
12 WGET_OPTS="--passive-ftp --no-directories --non-verbose"
13 HOST="http://people.debian.org/~93sam/"
14 TMPDIR=/tmp
15
16 if [ -e /etc/jigit.conf ] ; then
17     . /etc/jigit.conf
18 fi
19 if [ -e ~/.jigit.conf ] ; then
20     . ~/.jigit.conf
21 fi
22
23 URL="$HOST/jigit"
24
25 if [ "$TMPDIR"x = ""x ] ; then
26     TMPDIR=/tmp
27 fi
28
29 SUITE=$1
30 case $SUITE in
31     --help|-h)
32         echo "$0:"
33         echo "Automatic downloader for Jigdo images"
34         echo "Usage:"
35         echo "   jigit [distribution]"
36         exit 1
37     ;;
38 esac
39
40 for DIR in files jigdo
41 do
42     if [ ! -d $TMPDIR/jigit/$DIR ] ; then
43         mkdir -p -m 700 $TMPDIR/jigit/$DIR
44     fi
45 done
46
47 cd $TMPDIR/jigit/jigdo
48 # Grab the latest config file
49 wget $WGET_OPTS --mirror $URL/$SUITE.conf
50
51 . $SUITE.conf
52 wget $WGET_OPTS --mirror $URL/$JIGDO
53 wget $WGET_OPTS --mirror $URL/$TEMPLATE
54
55 echo "If you have a previous CD or CD image available, where is it mounted?"
56 echo "Say \"none\" if you have none"
57 read -p "> [none] " CD
58
59 if [ "$CD"x = ""x ] ; then
60     CD="none"
61 fi
62
63 cd $TMPDIR/jigit/files
64 # If we have a CD, add it to the find list
65 if [ "$CD" != "none" ] ; then
66     FIND="$CD"
67 fi
68
69 # Now the local apt cache and our own temp directory
70 FIND="$FIND $APT_CACHE $TMPDIR/jigit/files"
71
72 find $FIND -type f | \
73     xargs jigdo-file md5 -c $TMPDIR/jigit/jigdo/jigdo-cache.db \
74     > $TMPDIR/jigit/files/md5-list
75
76 echo
77 echo
78
79 rm -f $TMPDIR/jigit/jigdo/missing-list
80
81 # Check if we have all the pieces we need
82 mkimage -f $TMPDIR/jigit/files/md5-list \
83     -t $TMPDIR/jigit/jigdo/$TEMPLATE \
84     -j $TMPDIR/jigit/jigdo/$JIGDO \
85     -M $TMPDIR/jigit/jigdo/missing-list
86
87 # If we have a missing list, we're missing some files. Go and get them
88 if [ -e $TMPDIR/jigit/jigdo/missing-list ] ; then
89     NUM=`wc -l $TMPDIR/jigit/jigdo/missing-list | awk '{print $1}'`
90     while [ $NUM -gt 0 ]
91     do
92         cd $TMPDIR/jigit/files
93         for file in `cat $TMPDIR/jigit/jigdo/missing-list`
94         do
95             printf "\r%5d files missing for the image; retrieving %s           " $NUM `basename $file`
96             mkdir -p `dirname $file`
97             wget $WGET_OPTS --mirror $URL/$SNAPSHOT/$file -O $file
98             stat $file > /dev/null
99             if [ $? -eq 0 ] ; then
100                 NUM=$(($NUM - 1))
101             fi
102         done
103     done
104     echo
105     echo Done
106
107     # Now rebuild our index and try again
108     find $FIND -type f | \
109         xargs jigdo-file md5 -c $TMPDIR/jigit/jigdo/jigdo-cache.db \
110         > $TMPDIR/jigit/files/md5-list
111
112     rm -f $TMPDIR/jigit/jigdo/missing-list
113         # Check (again) if we have all the pieces we need
114     mkimage -f $TMPDIR/jigit/files/md5-list \
115         -t $TMPDIR/jigit/jigdo/$TEMPLATE \
116         -j $TMPDIR/jigit/jigdo/$JIGDO \
117         -M $TMPDIR/jigit/jigdo/missing-list
118
119         # If we still have a missing list, something is wrong. Give up
120     if [ -e $TMPDIR/jigit/jigdo/missing-list ] ; then
121         echo "Failed to build image; could not find all the files. ABORT"
122         exit 1
123     fi
124 fi
125
126 # We should have all the bits; build the image
127 mkimage -v -f $TMPDIR/jigit/files/md5-list \
128     -t $TMPDIR/jigit/jigdo/$TEMPLATE \
129     -j $TMPDIR/jigit/jigdo/$JIGDO \
130     -o $TMPDIR/jigit/jigdo/$SUITE.iso \
131