-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathoverlay.sh
executable file
Β·127 lines (110 loc) Β· 3.84 KB
/
overlay.sh
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
#!/bin/bash
set -euo pipefail
# Execute this code path on the host
if test -z "${INSIDE_VM:-}"; then
. ${commondir}/libvm.sh
vm_setup
if ! vm_ssh_wait 30; then
echo "ERROR: A running VM is required for 'make vmcheck'."
exit 1
fi
vm_rsync
# βββ BEGIN selinux-policy hack (part 1) for
# https://github.com/fedora-selinux/selinux-policy-contrib/pull/45
selhack=selinux-tmp-hack
if ! vm_cmd sesearch -A -s init_t -t install_t -c dbus | grep -q allow; then
echo "Activating selinux-tmp-hack"
d=$(mktemp -d)
cat > $d/$selhack.te << 'EOF'
policy_module(selinux-tmp-hack, 1.0.0)
gen_require(`
type install_t;
')
init_dbus_chat(install_t)
EOF
make -C $d -f /usr/share/selinux/devel/Makefile $selhack.pp
vm_send /var/roothome/sync $d/$selhack.pp
rm -rf $d
fi
# βββ END selinux-policy hack βββ
vm_cmd env INSIDE_VM=1 /var/roothome/sync/tests/vmcheck/overlay.sh
vm_reboot
exit 0
fi
set -x
# And then this code path in the VM
# get details from the current default deployment
rpm-ostree status --json > json.txt
json_field() {
field=$1; shift;
python -c "
import sys, json;
deployment = json.load(open('json.txt'))['deployments'][0]
print deployment.get('$field', '')
exit()"
}
commit=$(json_field checksum)
origin=$(json_field origin)
version=$(json_field version)
timestamp=$(json_field timestamp)
[ -n "$timestamp" ]
timestamp=$(date -d "@$timestamp" "+%b %d %Y")
rm -f json.txt
if [[ -z $commit ]] || ! ostree rev-parse $commit; then
echo "Error while determining current commit" >&2
exit 1
fi
cd /ostree/repo/tmp
rm vmcheck -rf
ostree checkout $commit vmcheck --fsync=0
rm vmcheck/etc -rf
# Now, overlay our built binaries & config files
INSTTREE=/var/roothome/sync/insttree
rsync -rlv $INSTTREE/usr/ vmcheck/usr/
rsync -rlv $INSTTREE/etc/ vmcheck/usr/etc/
## βββ BEGIN selinux-policy hack (part 2) for
## https://github.com/fedora-selinux/selinux-policy-contrib/pull/45
selhack=selinux-tmp-hack
pp=/var/roothome/sync/$selhack.pp
if [ -f $pp ]; then
seld=usr/share/selinux/packages/$selhack
mkdir -p vmcheck/$seld
cp $pp vmcheck/$seld
mkdir vmcheck/var/tmp # bwrap wrapper will mount tmpfs there
/var/roothome/sync/scripts/bwrap-script-shell.sh /ostree/repo/tmp/vmcheck \
semodule -v -n -i /$seld/$selhack.pp
fi
## βββ END selinux-policy hack βββ
# βββ BEGIN hack to get --keep-metadata
if ! ostree commit --help | grep -q -e --keep-metadata; then
# this is fine, rsync doesn't modify in place
mount -o rw,remount /usr
# don't overwrite /etc/ to not mess up 3-way merge
rsync -rlv --exclude '/etc/' vmcheck/usr/ /usr/
fi
# βββ END hack to get --keep-metadata βββ
# if the commit already has pkglist metadata (i.e. the tree was composed with at
# least v2018.1), make sure it gets preserved, because it's useful for playing
# around (but note it's not a requirement for our tests)
commit_opts=
if ostree show $commit --raw | grep -q rpmostree.rpmdb.pkglist; then
commit_opts="${commit_opts} --keep-metadata=rpmostree.rpmdb.pkglist"
fi
source_opt= # make this its own var since it contains spaces
if [ $origin != vmcheck ]; then
source_title="${origin}"
if [ -n "$version" ]; then
source_title="${source_title} (${version}; $timestamp)"
else
source_title="${source_title} ($timestamp)"
fi
source_opt="--add-metadata-string=ostree.source-title=Dev overlay on ${source_title}"
commit_opts="${commit_opts} --add-metadata-string=rpmostree.original-origin=${origin}"
else
source_opt="--keep-metadata=ostree.source-title"
commit_opts="${commit_opts} --keep-metadata=rpmostree.original-origin"
fi
ostree commit --parent=$commit -b vmcheck --consume --no-bindings \
--link-checkout-speedup ${commit_opts} "${source_opt}" \
--selinux-policy=vmcheck --tree=dir=vmcheck
ostree admin deploy vmcheck