summaryrefslogtreecommitdiff
path: root/tests/test-demo-buildsystem.sh
blob: c11191927362237a1f7fde0385342acbe5042ecd (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#
# Copyright (C) 2016 Colin Walters <walters@verbum.org>
#
# SPDX-License-Identifier: LGPL-2.0+
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

set -euo pipefail

. $(dirname $0)/libtest.sh

skip_without_fuse
skip_without_user_xattrs

echo "1..1"

# Run "triggers" like ldconfig, gtk-update-icon-cache, etc.
demo_triggers() {
    root=$1
    shift
    mkdir -p ${root}/usr/lib
    echo updated ldconfig at $(date) > ${root}/usr/lib/ld.so.cache.new
    mv ${root}/usr/lib/ld.so.cache{.new,}
}

# Make a binary in /usr/bin/$pkg which contains $version
exampleos_build_commit_package() {
    pkg=$1
    version=$2
    mkdir -p ${pkg}-package/usr/bin/
    echo "${pkg}-content ${version}" > ${pkg}-package/usr/bin/${pkg}
    # Use a dummy subject for this.
    ${CMD_PREFIX} ostree --repo=build-repo commit -b exampleos/x86_64/${pkg} -s '' --tree=dir=${pkg}-package
    rm ${pkg}-package -rf
}

exampleos_recompose() {
    rm exampleos-build -rf
    for pkg in ${packages}; do
	${CMD_PREFIX} ostree --repo=build-repo checkout -U --union exampleos/x86_64/${pkg} exampleos-build
    done

    # Now that we have our rootfs, run triggers
    rofiles-fuse exampleos-build mnt
    demo_triggers mnt/
    fusermount -u mnt
    
    # Then we commit it, using --link-checkout-speedup to effectively
    # only re-checksum the ldconfig file.  We also have dummy commit
    # message here.
    ${CMD_PREFIX} ostree --repo=build-repo commit -b exampleos/x86_64/standard -s 'exampleos build' --link-checkout-speedup exampleos-build
}

packages="bash systemd"

mkdir build-repo
ostree_repo_init build-repo --mode=bare-user
mkdir repo
ostree_repo_init repo --mode=archive
# Our FUSE mount point
mkdir mnt

# "Build" some packages which are really just files with
# the version number inside.
exampleos_build_commit_package bash 0.4.7
exampleos_build_commit_package systemd 224

# Now union the packages and commit
exampleos_recompose

# This is our first commit - let's publish it.
${CMD_PREFIX} ostree --repo=repo pull-local build-repo exampleos/x86_64/standard

# Now, update the bash package - this is a new commit on the branch
# exampleos/x86_64/bash.
exampleos_build_commit_package bash 0.5.0

# We now have two commits
exampleos_recompose

# Publish again:
${CMD_PREFIX} ostree --repo=repo pull-local build-repo exampleos/x86_64/standard
# Optional: Generate a static delta vs the previous build
${CMD_PREFIX} ostree --repo=repo static-delta generate exampleos/x86_64/standard
# Optional: Regenerate the summary file
${CMD_PREFIX} ostree --repo=repo summary -u

# Try: ostree --repo=demo-repo ls -R exampleos/x86_64/standard

echo "ok demo buildsystem"