summary refs log tree commit diff
path: root/pkgs/build-support/release/functions.sh
blob: 875a2da178de2ce114865f349e59c0944d087553 (plain) (blame)
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
findTarball() {
    local suffix i
    if [ -d "$1/tarballs/" ]; then
        for suffix in tar.gz tgz tar.bz2 tbz2 tar.xz tar.lzma; do
            for i in $1/tarballs/*.$suffix; do echo $i; break; done
        done | sort | head -1
        return
    else
        echo "$1"
        return
    fi
}

canonicalizeJarManifest() {
    local input=$1
    # http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Notes_on_Manifest_and_Signature_Files
    (head -n 1 $input && tail -n +2 $input | sort | grep -v '^\s*$') > $input-tmp
    mv $input-tmp $input
}

# Post-process a jar file to contain canonical timestamps and metadata ordering
canonicalizeJar() {
    local input=$1
    local outer=$(pwd)
    unzip -qq $input -d $input-tmp
    canonicalizeJarManifest $input-tmp/META-INF/MANIFEST.MF
    # Set all timestamps to Jan 1 1980, which is the earliest date the zip format supports...
    find $input-tmp -exec touch -t 198001010000.00 {} +
    rm $input
    pushd $input-tmp
    zip -q -r -o -X $outer/tmp-out.jar . 2> /dev/null
    popd
    rm -rf $input-tmp
    mv $outer/tmp-out.jar $input
}

propagateImageName() {
    mkdir -p $out/nix-support
    cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name
}