~xnox/debian-cd/cleanup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /bin/sh

# Copyright 2004 Steve McIntyre <steve@einval.com>
# See the README file for the license

# This script is called by the Makefile to cleanup the .jigdo
# files:
#
# Make sure the iso filename is sane
# Add in the TEMPLATEURL information
# Update the Servers lines

jigdo="$1"    # .jigdo file to work on
iso="$2"      # The name to give to the .iso
dirpath="$3"  # The disc build tree
template="$4" # URL for .template file, can be relative URL
discinfo="$5" # e.g. "Debian GNU/Linux 3.0 r1 "Woody" - Unofficial i386 Binary-1"
# any further parameters are fallback URLs
info="Generated on "`date -R`

# Don't panic - the \047 in the awk below is the ASCII for ' - if I
# use ' instead, the enclosing shell script gets annoyed...!
cat $jigdo | awk -v ISO="$iso" -v TEMPLATE="$template" -v DISCINFO="$discinfo" -v INFO="$info" '
    /^Filename=/        {
                            printf("Filename=%s\n", ISO);
                            next
                        }
    /^Template=/        {
                            printf("Template=%s\n", TEMPLATE);
                            next
                        }
    /^Template-MD5Sum=/ {
                            printf("%s\n", $0);
                            printf("ShortInfo=\047%s\047\n", DISCINFO);
                            printf("Info=\047%s\047\n", INFO);
                            next
                        }
    /.*/                {   print $0 }
' > $jigdo.1
mv -f $jigdo.1 $jigdo

# If some fallbacks were specified, output a servers section with the
# URLs. The entries of the variable are expected to be already of the
# form "Label=http://some.url/"
if test -n "$JIGDOFALLBACKURLS"; then
    for url in "$JIGDOFALLBACKURLS"
    do
        # The --try-last switch assigns a lower priority to the URL,
        # so it will only be used if other server entries (without the
        # --try-last) have already been tried without success.
        echo "$url --try-last" >> $jigdo
    done
fi

# Create a snapshot tree if we've been told where to create one
if test -n "$JIGDOFALLBACKPATH"; then
	echo "Creating snapshot tree:"
	for jentry in `cat $jigdo | grep =Debian:`
	do
		file=`echo $jentry | sed 's/^.*Debian://g'`
		dir=$JIGDOFALLBACKPATH/Debian/`dirname $file`
		if [ ! -d $dir ] ; then
			mkdir -p $dir
		fi
		ln -f $MIRROR/$file $JIGDOFALLBACKPATH/Debian/$file
	done
	for jentry in `cat $jigdo | grep =Non-US:`
	do
		file=`echo $jentry | sed 's/^.*Non-US://g'`
		dir=$JIGDOFALLBACKPATH/Non-US/`dirname $file`
		if [ ! -d $dir ] ; then
			mkdir -p $dir
		fi
		ln -f $NONUS/$file $JIGDOFALLBACKPATH/Non-US/$file
	done
fi