File: start_new_disc

package info (click to toggle)
debian-cd 3.1.13
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,244 kB
  • sloc: sh: 4,925; perl: 3,730; makefile: 387
file content (478 lines) | stat: -rwxr-xr-x 17,016 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#!/bin/bash
#
# start_new_disc
#
# Start a new temporary disc tree, including all the basic metadata
# needed

set -e
#set -x

BASEDIR=$1
MIRROR=$2
TDIR=$3
CODENAME=$4
ARCHES="$5"
DISKNUM=$6
SOURCEDISK=0
BINARYDISK=0

BDIR=$TDIR/$CODENAME
CDDIR=$BDIR/CD${DISKNUM}
DATE=`cat $BDIR/DATE`
DI_DATA_DIR=$BASEDIR/data/$DI_CODENAME

CAPCODENAME=`perl -e "print ucfirst("$CODENAME")"`

NUM_ARCHES=`echo $ARCHES | wc -w`
case "$ARCHES" in
    *kfreebsd*) DEBIAN_KERNEL="GNU/kFreeBSD";;
    *hurd*)     DEBIAN_KERNEL="GNU/Hurd";;
    *)          DEBIAN_KERNEL="GNU/Linux";;
esac
export DEBIAN_KERNEL

if [ "$VOLID_BASE"x = ""x ] ; then
    VOLID_BASE="Debian $DEBVERSION"
fi

if [ "$DISKINFO_DISTRO"x = ""x ] ; then
    DISKINFO_DISTRO="Debian"
fi
export DISKINFO_DISTRO

if [ $NUM_ARCHES = 1 ] ; then
    case $ARCHES in
        source)
            SOURCEDISK=1
            export DISKINFO="$DISKINFO_DISTRO $DEBVERSION \"$CAPCODENAME\" - $OFFICIAL $DISKTYPE Source-$DISKNUM $BUILD_DATE"
            export VOLID="$VOLID_BASE Source $DISKNUM"
            export SOURCEONLY=yes
            ;;
        *)
            BINARYDISK=1
            export DISKINFO="$DISKINFO_DISTRO ${DEBIAN_KERNEL} $DEBVERSION \"$CAPCODENAME\" - $OFFICIAL $ARCHES $DISKTYPE Binary-$DISKNUM $BUILD_DATE"
            case "$ARCHES" in
                powerpc)
                    export VOLID="$VOLID_BASE ppc $DISKNUM" ;;
                kfreebsd-i386)
                    export VOLID="$VOLID_BASE f-i386 $DISKNUM" ;;
                kfreebsd-amd64)
                    export VOLID="$VOLID_BASE f-amd64 $DISKNUM" ;;
                hurd-i386)
                    export VOLID="$VOLID_BASE h-i386 $DISKNUM" ;;
                *)
                    export VOLID="$VOLID_BASE $ARCHES $DISKNUM" ;;
            esac
            ;;
    esac
    export ARCHDEF=$ARCHES
else
    BINARYDISK=1
    case "$ARCHES" in
        *source*) SOURCEDISK=1;;
    esac
    export ARCHDEF=`echo $ARCHES | sed 's? ?/?g'`
    export DISKINFO="$DISKINFO_DISTRO ${DEBIAN_KERNEL} $DEBVERSION \"$CAPCODENAME\" - $OFFICIAL Multi-architecture $ARCHDEF $DISKTYPE #$DISKNUM $BUILD_DATE"
    export VOLID="$VOLID_BASE M-A $DISKNUM"
fi

merge_include_exclude () {
    OUT="$1"
    TYPE="$2"
    LIST="$3"
    WRITE=0 # Don't create empty files

    # Check to see if any file specified actually exist
    for FILE in $LIST ; do
        if [ -r "$FILE" ] ; then
            WRITE=1
        else
            echo "WARNING: Unable to read $TYPE file $FILE"
        fi
    done

    # If we have any files, merge and write them out
    if [ "$WRITE" = 1 ] ; then
        sort -u $LIST > "$OUT"
    fi
}

mkdir -p $CDDIR
echo "  Adding the required directories"

if [ ! -e $CDDIR/debian ] ; then
    ln -sf . $CDDIR/debian
fi

if [ ! -d $CDDIR/dists/$CODENAME ] ; then
    mkdir -p $CDDIR/dists/$CODENAME
fi

# Commodity link for tools which want local in dists/local/local ...
if [ -n "$LOCAL" ]
then
    ln -sf $CODENAME $CDDIR/dists/local
fi

if [ ! -d $CDDIR/.disk ] ; then
    mkdir $CDDIR/.disk
fi

if [ "$DISC_START_HOOK"x != ""x ] ; then
    echo "  Calling start hook: $DISC_START_HOOK"
    $DISC_START_HOOK $TDIR $MIRROR $DISKNUM $CDDIR "$ARCHES"
fi

echo "  Generating the image label and volume id"
echo -n $DISKINFO                   > $CDDIR/.disk/info
echo -n "$DISKINFO ($DATE)"         >  $BDIR/$DISKNUM.diskinfo
echo '#define DISKNAME ' $DISKINFO  >  $CDDIR/README.diskdefines
echo '#define ARCH ' $ARCHDEF       >> $CDDIR/README.diskdefines
for ARCH in $ARCHES
do
    echo '#define ARCH'$ARCH ' 1'       >> $CDDIR/README.diskdefines
done
echo '#define DISKNUM ' $DISKNUM    >> $CDDIR/README.diskdefines
echo '#define DISKNUM'$DISKNUM ' 1' >> $CDDIR/README.diskdefines
echo -n $VOLID                      >  $BDIR/$DISKNUM.volid

if [ $BINARYDISK = 1 ] ; then
    echo '#define TYPEbinary  1'        >> $CDDIR/README.diskdefines
    $BASEDIR/tools/set_mkisofs_opts bin $DISKNUM       >> $BDIR/$DISKNUM.mkisofs_opts
fi
if [ $SOURCEDISK = 1 ] ; then
    echo '#define TYPEsource  1'        >> $CDDIR/README.diskdefines
    $BASEDIR/tools/set_mkisofs_opts src $DISKNUM       >> $BDIR/$DISKNUM.mkisofs_opts
fi

if [ $DISKNUM = 1 ] ; then
    if [ "$OMIT_DOC_TOOLS" != "1" ]; then
        if [ ! -e $MIRROR/doc ]; then
            echo "You need a Debian mirror with the doc directory!"
            exit 1
        fi
    fi
    
    echo "  Adding .disk/base_components"
    echo "main" > $CDDIR/.disk/base_components
    if [ -n "$LOCAL" ] ; then
        echo "local" >> $CDDIR/.disk/base_components
    fi

    echo "  Adding .disk/cd_type"
    if [ "$COMPLETE"x = "1"x ]; then
        if [ $DISKTYPE = DVD ] || [ $DISKTYPE = DLDVD ]; then
            if [ "$MAXCDS"x = "1"x ]; then
                echo "dvd/single" > $CDDIR/.disk/cd_type
            else
                echo "dvd" > $CDDIR/.disk/cd_type
            fi
        elif [ $DISKTYPE = BD ] || [ $DISKTYPE = DLBD ]; then
            if [ "$MAXCDS"x = "1"x ]; then
                echo "bluray/single" > $CDDIR/.disk/cd_type
            else
                echo "bluray" > $CDDIR/.disk/cd_type
            fi
        else
            if [ "$MAXCDS"x = "1"x ]; then
                echo "full_cd/single" > $CDDIR/.disk/cd_type
            else
                echo "full_cd" > $CDDIR/.disk/cd_type
            fi
        fi
    else
        echo "not_complete" > $CDDIR/.disk/cd_type
    fi

    if [ $NUM_ARCHES -gt 1 ]; then
        echo "  Adding .disk/multi_arch"
        touch $CDDIR/.disk/multi_arch
    fi

    echo "  Adding udeb/base includes/excludes"

    for ARCH in $ARCHES
    do
        if [ $ARCH != source ] ; then
            # Netinst/businesscard CD have different
            # udeb_include and udeb_exclude files
            if [ -z "$UDEB_INCLUDE" ] ; then
                case "$INSTALLER_CD"x in
                    "1"x)
                        UDEB_INCLUDE=$DI_DATA_DIR/"$ARCH"_businesscard_udeb_include;;
                    "2"x|"C"x)
                        UDEB_INCLUDE=$DI_DATA_DIR/"$ARCH"_netinst_udeb_include;;
                    *)
                        UDEB_INCLUDE=$DI_DATA_DIR/"$ARCH"_udeb_include;;
                esac
            fi

            if [ -z "$UDEB_EXCLUDE" ] ; then
                case "$INSTALLER_CD"x in
                    "1"x)
                        UDEB_EXCLUDE=$DI_DATA_DIR/"$ARCH"_businesscard_udeb_exclude;;
                    "2"x|"C"x)
                        UDEB_EXCLUDE=$DI_DATA_DIR/"$ARCH"_netinst_udeb_exclude;;
                    *)
                        UDEB_EXCLUDE=$DI_DATA_DIR/"$ARCH"_udeb_exclude;;
                esac
            fi

            UDEB_INCLUDES="$UDEB_INCLUDES $UDEB_INCLUDE"
            UDEB_EXCLUDES="$UDEB_EXCLUDES $UDEB_EXCLUDE"
            BASE_INCLUDES="$BASE_INCLUDES $BASE_INCLUDE"
            BASE_EXCLUDES="$BASE_EXCLUDES $BASE_EXCLUDE"
        fi
    done

    # Sort and merge the the include and exclude files as necessary
    merge_include_exclude "$CDDIR/.disk/udeb_include" UDEB_INCLUDE "$UDEB_INCLUDES"
    merge_include_exclude "$CDDIR/.disk/udeb_exclude" UDEB_EXCLUDE "$UDEB_EXCLUDES"
    merge_include_exclude "$CDDIR/.disk/base_include" BASE_INCLUDE "$BASE_INCLUDES"
    merge_include_exclude "$CDDIR/.disk/base_exclude" BASE_EXCLUDE "$BASE_EXCLUDES"

    if [ "$OMIT_DOC_TOOLS" != "1" ]; then
        echo "  Adding docs to CD1"
        $BASEDIR/tools/add_files $CDDIR $MIRROR doc
        find $CDDIR/doc -name "dedication-*" | grep -v "$DEBVERSION" | xargs rm -f
        find $CDDIR/doc -name "debian-keyring.tar.gz" | xargs rm -f

        if [ ! -e $CDDIR/doc/FAQ/html ] ; then
            echo "  Extracting FAQ on CD1"
            mkdir $CDDIR/doc/FAQ/html
            cd $CDDIR/doc/FAQ/html
            if [ -e "../debian-faq.en.html.tar.gz" ] ; then
                tar xzf ../debian-faq.en.html.tar.gz
            else
                tar xzf ../debian-faq.html.tar.gz
            fi
        fi
    fi

    # Installtools
    mkdir $CDDIR/install
    if [ -x "$BASEDIR/tools/$CODENAME/installtools.sh" ] ; then
        echo "  Adding installtools"
        $BASEDIR/tools/$CODENAME/installtools.sh $CDDIR "$ARCHES"
    fi

    for ARCH in $ARCHES
    do
        if [ -e $MIRROR/dists/$DI_CODENAME/main/disks-$ARCH ] ; then
            echo "  Adding disks-$ARCH stuff ..."
            mkdir -p $CDDIR/dists/$DI_CODENAME/main/disks-$ARCH
            $BASEDIR/tools/add_files $CDDIR/dists/$DI_CODENAME/main/disks-$ARCH $MIRROR/dists/$DI_CODENAME/main/disks-$ARCH . 
            touch $CDDIR/.disk/kernel_installable
            cd $CDDIR/dists/$DI_CODENAME/main/disks-$ARCH
            rm -rf base-images-*
            if [ -L current ] ; then
                CURRENT_LINK=`readlink current`
                mv $CURRENT_LINK .tmp_link
                rm -rf [0123456789]*
                mv .tmp_link $CURRENT_LINK
            elif [ -d current ] ; then
                rm -rf [0123456789]* 
            fi
        fi
    done

    # See if we had to remove anything because it was too big. Warn the user.
    if [ -s $BDIR/sourcetoobig ] ; then
        echo "  Adding README.excluded (some source files were too big)"
        echo "For size reasons, the following source packages were excluded from this disc set:" >> $CDDIR/README.excluded
        echo >> $CDDIR/README.excluded
        cat $BDIR/sourcetoobig >> $CDDIR/README.excluded
        if [ -s $BDIR/sourcetoobig-deps ] ; then
            echo "and that caused the following packages to be also excluded because" >> $CDDIR/README.excluded
            echo "of dependencies:" >> $CDDIR/README.excluded
            echo >> $CDDIR/README.excluded
            cat $BDIR/sourcetoobig-deps >> $CDDIR/README.excluded
            echo >> $CDDIR/README.excluded
            echo "Beware that this may break dependencies in this disc set." >> $CDDIR/README.excluded
        fi
        echo >> $CDDIR/README.excluded
    fi

    # Stop the greps below from complaining
    touch $BDIR/sort_deps_dummy.log

    grep "refused because of toobig" $BDIR/sort_deps*.log | sort -u | awk '{print $1}' > $BDIR/toobig
    if [ -s $BDIR/toobig ] ; then
        echo "  Adding README.excluded (some package files were too big)"
        echo "For size reasons, the following packages were excluded from this disc set:" >> $CDDIR/README.excluded
        echo >> $CDDIR/README.excluded
        cat $BDIR/toobig >> $CDDIR/README.excluded
        grep "Can't add.*toobig" $BDIR/sort_deps*.log | sort -u | awk '{print $3}' > $BDIR/toobig-deps
        if [ -s $BDIR/toobig-deps ] ; then
            echo >> $CDDIR/README.excluded
            echo "and that caused the following packages to be also excluded because" >> $CDDIR/README.excluded
            echo "of dependencies:" >> $CDDIR/README.excluded
            echo >> $CDDIR/README.excluded
            cat $BDIR/toobig-deps >> $CDDIR/README.excluded
        fi
    fi
fi

# Create an empty dirs file; will be appended to later if needed
> $BDIR/$DISKNUM.mkisofs_dirs

echo "  Adding common docs on CD$DISKNUM"
$BASEDIR/tools/add-bin-doc $DISKNUM "$ARCHES"

# Common stuff for all disks in the set
if [ "$SOURCEONLY"x = "yes"x ] ; then
    echo -n "-J -joliet-long" >> $BDIR/$DISKNUM.mkisofs_opts
fi

echo "  Adding Release files"
# Release files
cd $CDDIR

SECTIONS="main"
if [ "${NONFREE:-0}" != "0" -o "${EXTRANONFREE:-0}" != "0" ] ; then
    SECTIONS="${SECTIONS} non-free"
fi
if [ "${CONTRIB:-0}" != "0" ] ; then
    SECTIONS="${SECTIONS} contrib"
fi

if [ -n "$LOCAL" ] ; then
    SECTIONS="$SECTIONS local"
fi

# these two lines can be inserted below the "Architectures" line below,
# to sort out broken Release files just after the testing --> stable
# transition
#     sed -e "s/^Suite: .*$/Suite: stable/" | \
#     sed -e "s/^Description: .*$/Description: Debian $DEBVERSION/" | \

if [ -e "$MIRROR/dists/$CODENAME/Release" ] ; then
    # Strip the MD5Sum and SHA1 fields
    # Update some other information as well
    sed -e "s/^Architectures: .*$/Architectures: $ARCHES/" \
        $MIRROR/dists/$CODENAME/Release | \
        sed -e "s|^Components: .*$|Components: $SECTIONS|" | \
        perl -ne 'if (/^(MD5Sum|SHA1|SHA256):/i) { $f=1; next } 
    if ($f) { 
        unless (/^ /) { print; $f=0 }
    } else { print }' > dists/$CODENAME/Release
    if [ "$EARLY_BUILD_HACK"x = "1"x ] ; then
        RDATE=`awk '/^Date:/ { print $2,$3,$4,$5}' dists/$CODENAME/Release`
        sed -i -e "s/^Suite: .*$/Suite: stable/" dists/$CODENAME/Release
        sed -i -e "s/^Description: .*$/Description: Debian $DEBVERSION Released $RDATE/" dists/$CODENAME/Release
    fi

    # Create the suite symlink
    SUITE=$(sed -n "/^Suite:/ s/.*: //p" dists/$CODENAME/Release)
    if [ -n "$SUITE" ] && [ x"$SUITE" != x"$CODENAME" ]; then
        ln -sf $CODENAME dists/$SUITE
    fi
else
    echo "ERROR: Release file ($MIRROR/dists/$CODENAME/Release) is missing !"
    exit 1
fi

# Copying individual release files
for ARCH in $ARCHES
do
    for SECT in $SECTIONS
    do
        # Install the release files
        if [ -e "$MIRROR/dists/$CODENAME/$SECT/binary-$ARCH/Release" ] ; then
            mkdir -p dists/$CODENAME/$SECT/binary-$ARCH
            cp $MIRROR/dists/$CODENAME/$SECT/binary-$ARCH/Release \
                dists/$CODENAME/$SECT/binary-$ARCH/
            if [ "$DEBVERSION" != "testing" ] ; then
                sed -i "s/^Archive:.*$/Archive: stable/" dists/$CODENAME/$SECT/binary-$ARCH/Release
            fi
        fi
        if [ -n "$NONUS" -a -e "$NONUS/dists/$CODENAME/non-US/$SECT/binary-$ARCH/Release" ] ; then
            mkdir -p dists/$CODENAME/non-US/$SECT/binary-$ARCH
            cp $NONUS/dists/$CODENAME/non-US/$SECT/binary-$ARCH/Release \
                dists/$CODENAME/non-US/$SECT/binary-$ARCH/
            if [ "$DEBVERSION" != "testing" ] ; then
                sed -i "s/^Archive:.*$/Archive: stable/" dists/$CODENAME/non-US/$SECT/binary-$ARCH/Release
            fi
        fi
    done

    if [ -n "$LOCALDEBS" -a -n "$LOCAL" ] ; then
        if [ -e $LOCALDEBS/dists/$CODENAME/local/binary-$ARCH/Release ] ; then
            mkdir -p dists/$CODENAME/local/binary-$ARCH
            cp $LOCALDEBS/dists/$CODENAME/local/binary-$ARCH/Release \
                dists/$CODENAME/local/binary-$ARCH/
        fi
    fi

    if [ -e "$MIRROR/dists/$DI_CODENAME/main/debian-installer/binary-$ARCH/Release" ] ; then
        mkdir -p dists/$CODENAME/main/debian-installer/binary-$ARCH
        cp $MIRROR/dists/$DI_CODENAME/main/debian-installer/binary-$ARCH/Release \
            dists/$CODENAME/main/debian-installer/binary-$ARCH/
        if [ "$DEBVERSION" != "testing" ] ; then
            sed -i "s/^Archive:.*$/Archive: stable/" dists/$CODENAME/main/debian-installer/binary-$ARCH/Release
        fi
    fi
done

# Upgrade packages / kernels
if [ "$SOURCEONLY"x != "yes"x ] ; then
    echo "  Trying to add upgrade* directories"
    if [ -x "$BASEDIR/tools/$CODENAME/upgrade.sh" ] ; then
        $BASEDIR/tools/$CODENAME/upgrade.sh
    fi
fi

for ARCH in $ARCHES
do
    export ARCH=$ARCH
    if [ $ARCH != source ] ; then
        if [ -x "$BASEDIR/tools/$CODENAME/upgrade-$ARCH.sh" ] ; then
            $BASEDIR/tools/$CODENAME/upgrade-$ARCH.sh $DISKNUM $CDDIR
        fi

        echo "  (Optionally) making the image bootable for $ARCH:"
        if [ -f $BASEDIR/tools/boot/$DI_CODENAME/boot-$ARCH ] ; then
            cd $TDIR
            echo "    Running tools/boot/$DI_CODENAME/boot-$ARCH $DISKNUM $CDDIR"
            $BASEDIR/tools/boot/$DI_CODENAME/boot-$ARCH $DISKNUM $CDDIR || booterror=$?
            if [ "$booterror"x != ""x ] ; then
                echo "      FAILED: error $booterror"
                exit $booterror
            fi
        else
            if [ "${IGNORE_MISSING_BOOT_SCRIPT:-0}" = "0" ] ; then
                echo "    No script to make CDs bootable for $ARCH"
                echo "    We've not been asked to ignore this. Aborting."
                exit 1
            fi
        fi
    fi
done

# If we've had to extract any files from packages to put them onto the
# CD (e.g. bootloader files), then we will have listed them in
# $BDIR/$DISKNUM.pkgs_extracted. If that file exists, add a README.source
# to the root of the CD
if [ -e $BDIR/$DISKNUM.pkgs_extracted ] && \
    [ ""x != "$ARCHIVE_EXTRACTED_SOURCES"x ] ; then
    echo "  Adding README.source"
    cat > $CDDIR/README.source <<EOF
Creation of this disk image included extracting files from some Debian
packages. In case you do not have those packages already, both the
binary and source packages are archived at

EOF
    echo "$ARCHIVE_EXTRACTED_SOURCES" >> $CDDIR/README.source
    echo "" >> $CDDIR/README.source
    echo "The following binary/source packages were used:" >> $CDDIR/README.source
    sort $BDIR/$DISKNUM.pkgs_extracted | uniq | \
        xargs -n1 basename >> $CDDIR/README.source
fi

if [ "$DISC_PKG_HOOK"x != ""x ] ; then
    echo "  Calling pkg hook: $DISC_PKG_HOOK"
    $DISC_PKG_HOOK $TDIR $MIRROR $DISKNUM $CDDIR "$ARCHES"
fi

exit 0