This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
/
flatpak-repository.bbclass
190 lines (163 loc) · 5.47 KB
/
flatpak-repository.bbclass
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
# Check we have the necessary distro features enabled.
inherit distro_features_check
REQUIRED_DISTRO_FEATURES_append = " usrmerge systemd pam"
inherit flatpak-config
# These are lists of files we check to determine the flatpak
# runtime type of an image if it is not directly visible from
# the image name. This did not used to be necessary before we
# made the gateway image a flatpak-enabled (flatpak-runtime)
# by itself, but now it is. Actually we could now drop the
# other, image name based, tests altogether...
FLATPAK_RUNTIME_FILES = " \
/usr/bin/flatpak \
"
FLATPAK_SDK_FILES = " \
/usr/bin/flatpak /usr/bin/gcc /usr/bin/make \
/usr/bin/patch /usr/bin/pkg-config \
/usr/include/stdio.h /usr/include/stdlib.h \
"
#
# Create and populate a primary flatpak repository from/for an image.
#
fakeroot do_flatpak_populate_repository () {
echo "Flatpak repository population:"
echo " * FLATPAKBASE: ${FLATPAKBASE}"
echo " * IMAGE_BASENAME: ${IMAGE_BASENAME}"
# Bail out early if flatpak is not enabled for this image.
case ${IMAGE_BASENAME} in
*-flatpak-runtime) RUNTIME_TYPE=BasePlatform;;
*-flatpak-sdk) RUNTIME_TYPE=BaseSdk;;
*)
RUNTIME_TYPE=BaseSdk
for f in ${FLATPAK_SDK_FILES}; do
if [ ! -e ${IMAGE_ROOTFS}/$f ]; then
RUNTIME_TYPE=""
break
fi
done
if [ -z "$RUNTIME_TYPE" ]; then
RUNTIME_TYPE=BasePlatform
for f in ${FLATPAK_RUNTIME_FILES}; do
if [ ! -e ${IMAGE_ROOTFS}/$f ]; then
RUNTIME_TYPE=""
break
fi
done
fi
if [ -z "$RUNTIME_TYPE" ]; then
echo "${IMAGE_BASENAME} is not a flatpak-enabled image..."
return 0
fi
;;
esac
echo "${IMAGE_BASENAME} is a flatpak $RUNTIME_TYPE image"
if [ -n "${FLATPAK_GPGID}" ]; then
GPG_SIGN="--gpg-home ${FLATPAK_GPGDIR} --gpg-id ${FLATPAK_GPGID}"
else
GPG_SIGN=""
fi
# Hmm... it might be a better idea to either preconstruct this in
# flatpak-config and just be a postman for it here, or pass these
# separately to the backend script and let that construct these.
# XXX TODO: We'll need to revisit this and decide...
_base="runtime/${FLATPAK_DOMAIN}.$RUNTIME_TYPE/${FLATPAK_ARCH}"
_t=""
for _b in ${FLATPAK_BRANCH} ${FLATPAK_LATEST} ${FLATPAK_BUILD}; do
BRANCHES="$BRANCHES$_t$_base/$_b"
_t=","
done
echo "Using flatpak branches $BRANCHES for ${IMAGE_ROOTFS}..."
# Generate/populate flatpak/OSTree repository
${FLATPAKBASE}/scripts/flatpak-populate-repo.sh \
--repo-path ${FLATPAK_REPO} \
--repo-mode bare-user \
$GPG_SIGN \
--branches "$BRANCHES" \
--image-sysroot ${IMAGE_ROOTFS} \
--tmp-dir ${TMPDIR}
}
do_flatpak_populate_repository[depends] += " \
ostree-native:do_populate_sysroot \
flatpak-native:do_populate_sysroot \
gnupg1-native:do_populate_sysroot \
"
do_flatpak_populate_repository[vardeps] += " \
FLATPAK_REPO \
FLATPAK_EXPORT \
FLATPAK_DOMAIN \
FLATPAK_BRANCH \
FLATPAK_LATEST \
FLATPAK_BUILD \
FLATPAK_GPGID \
"
#
# Export an image (well the bare-user repo, really) to an archive-z2 repo.
#
fakeroot do_flatpak_export_repository () {
# Bail out early if no export repository is defined.
if [ -z "${FLATPAK_EXPORT}" ]; then
echo "Flatpak repository for export not specified, skip export..."
return 0
fi
# Bail out early if flatpak is not enabled for this image.
case ${IMAGE_BASENAME} in
*-flatpak-runtime) RUNTIME_TYPE=BasePlatform;;
*-flatpak-sdk) RUNTIME_TYPE=BaseSdk;;
*)
RUNTIME_TYPE=BaseSdk
for f in ${FLATPAK_SDK_FILES}; do
if [ ! -e ${IMAGE_ROOTFS}/$f ]; then
RUNTIME_TYPE=""
break
fi
done
if [ -z "$RUNTIME_TYPE" ]; then
RUNTIME_TYPE=BasePlatform
for f in ${FLATPAK_RUNTIME_FILES}; do
if [ ! -e ${IMAGE_ROOTFS}/$f ]; then
RUNTIME_TYPE=""
break
fi
done
fi
if [ -z "$RUNTIME_TYPE" ]; then
echo "${IMAGE_BASENAME} is not a flatpak-enabled image..."
return 0
fi
;;
esac
echo "${IMAGE_BASENAME} is a flatpak $RUNTIME_TYPE image"
if [ -n "${FLATPAK_GPGID}" ]; then
GPG_SIGN="--gpg-home ${FLATPAK_GPGDIR} --gpg-id ${FLATPAK_GPGID}"
else
GPG_SIGN=""
fi
# Export to archive-z2 flatpak/OSTree repository
${FLATPAKBASE}/scripts/flatpak-populate-repo.sh \
--repo-path ${FLATPAK_REPO} \
--repo-export ${FLATPAK_EXPORT} \
--machine ${MACHINE} \
$GPG_SIGN \
--tmp-dir ${TMPDIR}
}
do_flatpak_export_repository[depends] += " \
ostree-native:do_populate_sysroot \
flatpak-native:do_populate_sysroot \
gnupg1-native:do_populate_sysroot \
"
do_flatpak_export_repository[vardeps] += " \
FLATPAK_REPO \
FLATPAK_EXPORT \
FLATPAK_DOMAIN \
FLATPAK_BRANCH \
FLATPAK_LATEST \
FLATPAK_BUILD \
FLATPAK_GPGID \
MACHINE \
"
addtask flatpak_populate_repository \
after do_rootfs \
before do_image_complete
addtask flatpak_export_repository \
after do_flatpak_populate_repository \
before do_image_complete