summaryrefslogtreecommitdiff
path: root/tests/make-patch.script
blob: cc2af3b6f4dfdb36748e58568ed187485f7a5f16 (plain)
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
#!/bin/sh
#
# Test making a patch between two different system images
#
# Copyright (C) 2012  Codethink Limited
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -eu

( # make the dummy stratum contain a chunk for a fake kernel
    mkdir -p "$DATADIR/dummykernel"
    cd "$DATADIR/dummykernel"
    git init --quiet
    cat <<EOF >dummykernel.morph
{
    "name": "dummykernel",
    "kind": "chunk",
    "install-commands": [
        "mkdir -p \"\$DESTDIR/boot\"",
        "touch \"\$DESTDIR\"/extlinux.conf",
        "touch \"\$DESTDIR\"/boot/vmlinuz",
        "touch \"\$DESTDIR\"/boot/System.map"
    ]
}
EOF
	
	
    git add .
    git commit --quiet -m "Make dummy boot files"

    cd "$DATADIR/morphs-repo"
    git checkout --quiet master
    sed -i -e 's/^.*sources.*$/&\
        {\
            "name": "dummykernel",\
            "ref": "master"\
        },\
/' hello-stratum.morph

    git commit --quiet -m "add dummy kernel" hello-stratum.morph
)

tests/morph build morphs-repo master hello-system.morph

# save the stratum as we will apply the patch on top of this later
cp "$DATADIR/cache/"*stratum* "$DATADIR"/farrokh-stratum

 
( # make an evil stratum
	cd "$DATADIR/chunk-repo"
	git checkout --quiet -b evil farrokh
	sed -i -e 's/hello/goodbye/g' hello.c
	git add hello.c
	git commit --quiet -m "Make the program evil"

	cd "$DATADIR/morphs-repo"
	git checkout --quiet -b evil master
	sed -i -e 's/farrokh/evil/g' hello-stratum.morph
	git add hello-stratum.morph
	git commit --quiet -m "Build evil systems"
)

tests/morph build morphs-repo evil hello-system.morph

# make a patch to make the system evil
PATCH="$DATADIR"/patchfile
tests/morph make-patch "$PATCH" morphs-repo master hello-system.morph \
                                morphs-repo evil hello-system.morph

UNPACKED="$DATADIR"/unpacked
mkdir -p "$UNPACKED"
tar -C "$UNPACKED" -xf "$DATADIR"/farrokh-stratum
(cd "$UNPACKED" && tbdiff-deploy "$PATCH")
"$UNPACKED"/bin/hello