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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
|
#!/bin/bash
#
# Builds the pica-pica Debian packages for every distribution we support, each
# in its own podman container, and assembles the results into a signed apt
# repository.
#
# Takes a source tarball as produced by "make dist" - a self contained
# autotools distribution, which already carries the generated configure, so
# the containers have nothing to bootstrap.
#
# Meant to be run on an Ubuntu 24.04 host, but the only thing that is host
# specific is installing podman; give it podman by hand and it will run
# anywhere.
#
# The build matrix is at the top of the script. Note what is NOT in it:
# Ubuntu i386. Ubuntu has had no i386 architecture since 19.10 - what remains
# is a small multiarch compatibility subset with no installable base system,
# so there is no i386 Ubuntu container image to build in (docker.io/i386/ubuntu
# stops at 18.04) and no i386 Qt to build against. Debian still has i386 as a
# full architecture, so the 32 bit build happens there.
#
# The GPG key never enters a container. Containers produce .deb files; the
# repository is assembled and signed here on the host.
#
# (c) Copyright 2012 - 2026 Anton Sviridenko
# https://picapica.im
#
# 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 3.
set -euo pipefail
# codename | container image | dpkg arch | podman platform
TARGETS=(
"noble|docker.io/library/ubuntu:24.04|amd64|linux/amd64"
"resolute|docker.io/library/ubuntu:26.04|amd64|linux/amd64"
"trixie|docker.io/library/debian:trixie|amd64|linux/amd64"
"trixie|docker.io/i386/debian:trixie|i386|linux/386"
)
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
TARBALL=""
OUTDIR="$SCRIPTDIR/out"
REPODIR="$SCRIPTDIR/repo"
GPGKEY=""
SIGN=1
ONLY=""
SKIP_BUILD=0
ORIGIN="Pica Pica"
LABEL="Pica Pica"
progname=$(basename "$0")
usage()
{
cat <<EOF
Usage: $progname [OPTIONS] TARBALL
Build the pica-pica packages in containers and assemble a signed apt
repository from the results.
TARBALL is a source tarball as produced by "make dist" in the pica-pica tree,
e.g. pica-pica-0.9.0dev.tar.gz. Not needed with --skip-build.
Options:
-k, --gpg-key KEYID Key to sign the repository's Release files with. Any
form gpg accepts - key id, fingerprint, or the email
address on the uid. Required unless --no-sign.
--no-sign Build the repository but leave it unsigned. apt will
refuse it without extra configuration; for testing.
-o, --output DIR Where the containers leave their .deb files.
Default: $OUTDIR
-r, --repo DIR Where to assemble the apt repository.
Default: $REPODIR
--only PATTERN Only build targets whose "codename/arch" matches this
shell pattern, e.g. --only 'noble/*' or --only '*/i386'.
--skip-build Do not build anything; just assemble and sign the
repository from whatever is already in the output
directory.
-h, --help This message.
Targets:
EOF
local t cn img arch plat
for t in "${TARGETS[@]}"; do
IFS='|' read -r cn img arch plat <<<"$t"
printf ' %-16s %-34s %s\n' "$cn/$arch" "$img" "$plat"
done
cat <<'EOF'
There is no Ubuntu i386 target and there cannot be: Ubuntu dropped i386 as an
architecture after 18.04, so there is no i386 Ubuntu base image and no i386 Qt
to build against. The 32 bit build is done on Debian, which still carries i386
as a full architecture.
EOF
}
die()
{
echo "$progname: error: $*" >&2
exit 1
}
note()
{
echo
echo "=== $*"
}
while [ $# -gt 0 ]; do
case "$1" in
-k|--gpg-key) GPGKEY="${2:?--gpg-key needs a value}"; shift 2 ;;
--no-sign) SIGN=0; shift ;;
-o|--output) OUTDIR="${2:?--output needs a value}"; shift 2 ;;
-r|--repo) REPODIR="${2:?--repo needs a value}"; shift 2 ;;
--only) ONLY="${2:?--only needs a value}"; shift 2 ;;
--skip-build) SKIP_BUILD=1; shift ;;
-h|--help) usage; exit 0 ;;
-*) die "unknown option $1 (try --help)" ;;
*) break ;;
esac
done
if [ $# -gt 1 ]; then
die "expected at most one tarball, got: $*"
elif [ $# -eq 1 ]; then
TARBALL=$(readlink -f "$1")
fi
if [ "$SIGN" -eq 1 ] && [ -z "$GPGKEY" ]; then
die "no signing key given. Pass --gpg-key KEYID, or --no-sign to skip signing"
fi
if [ "$SKIP_BUILD" -eq 0 ]; then
[ -n "$TARBALL" ] ||
die "no source tarball given. Run \"make dist\" in the pica-pica tree and pass the result (try --help)"
[ -f "$TARBALL" ] ||
die "$TARBALL does not exist"
tar -tf "$TARBALL" >/dev/null 2>&1 ||
die "$TARBALL is not a readable tar archive"
fi
if [ "$(id -u)" -eq 0 ]; then
SUDO=""
elif command -v sudo >/dev/null; then
SUDO="sudo"
else
# Not fatal on its own. Nothing may need installing, which is the normal
# case on a signing-only machine; ensure_tool() complains if something
# actually is missing.
SUDO=""
fi
# Installs a package, but only if the tool it provides is not already there -
# and says plainly why it cannot when it has no way to become root, rather
# than letting apt-get fail with something less obvious.
ensure_tool()
{
local tool="$1" package="$2"
command -v "$tool" >/dev/null && return 0
if [ "$(id -u)" -ne 0 ] && [ -z "$SUDO" ]; then
die "$tool is missing and would come from the $package package, but this is not root and there is no sudo"
fi
note "installing $package, for $tool"
$SUDO apt-get install -y "$package"
}
# --- tools ----------------------------------------------------------------
# podman only when there is something to build. --skip-build exists so that
# the repository can be assembled and signed on a machine that holds the key
# and does nothing else; installing a container runtime on that machine would
# be exactly backwards.
if [ "$SKIP_BUILD" -eq 0 ]; then
if command -v podman >/dev/null; then
note "podman is already installed: $(podman --version)"
else
if [ "$(id -u)" -ne 0 ] && [ -z "$SUDO" ]; then
die "podman is missing and this is not root and there is no sudo - install podman yourself and re-run"
fi
note "installing podman"
$SUDO apt-get update
$SUDO apt-get install -y podman
fi
fi
# apt-ftparchive builds the repository indices, so it is needed in both
# modes. gpg only matters when there is something to sign.
ensure_tool apt-ftparchive apt-utils
if [ "$SIGN" -eq 1 ]; then
ensure_tool gpg gnupg
fi
if [ "$SIGN" -eq 1 ]; then
gpg --list-keys "$GPGKEY" >/dev/null 2>&1 ||
die "gpg does not know a key called '$GPGKEY'"
gpg --list-secret-keys "$GPGKEY" >/dev/null 2>&1 ||
die "no SECRET key for '$GPGKEY' - the repository cannot be signed with it"
fi
# --- work area ------------------------------------------------------------
WORKDIR=$(mktemp -d /tmp/pica-packaging.XXXXXX)
trap 'rm -rf "$WORKDIR"' EXIT
if [ "$SKIP_BUILD" -eq 0 ]; then
note "source tarball"
echo " $TARBALL"
echo " $(du -h "$TARBALL" | cut -f1), top level: $(tar -tf "$TARBALL" | head -1)"
fi
# --- build ----------------------------------------------------------------
mkdir -p "$OUTDIR"
BUILT=()
FAILED=()
if [ "$SKIP_BUILD" -eq 0 ]; then
for target in "${TARGETS[@]}"; do
IFS='|' read -r codename image arch platform <<<"$target"
if [ -n "$ONLY" ]; then
# shellcheck disable=SC2254
case "$codename/$arch" in
$ONLY) ;;
*) echo " skipping $codename/$arch (does not match --only '$ONLY')"; continue ;;
esac
fi
note "$codename/$arch ($image)"
if ! podman pull --platform "$platform" "$image"; then
FAILED+=("$codename/$arch: could not pull $image")
continue
fi
# --userns=keep-id is deliberately not used: the build wants to be
# root inside the container to install packages, and in rootless
# podman that still maps back to this user on the way out.
# The tarball is bind mounted as a single file under a fixed name, so
# container-build.sh does not have to be told what it is called. tar
# works out the compression from the content, so the missing .gz or
# .xz on that name costs nothing.
if podman run --rm \
--platform "$platform" \
-v "$TARBALL:/src/pica-source.tar:ro" \
-v "$SCRIPTDIR:/scripts:ro" \
-v "$OUTDIR:/out" \
-e PICA_DISTRO="$codename" \
-e PICA_ARCH="$arch" \
-w / \
"$image" \
/bin/bash /scripts/container-build.sh
then
BUILT+=("$codename/$arch")
else
FAILED+=("$codename/$arch: build failed")
fi
done
note "build summary"
for b in "${BUILT[@]:-}"; do [ -n "$b" ] && echo " ok $b"; done
for f in "${FAILED[@]:-}"; do [ -n "$f" ] && echo " FAILED $f"; done
[ ${#BUILT[@]} -gt 0 ] || die "nothing built - not assembling a repository"
fi
# --- repository -----------------------------------------------------------
#
# Laid out with a pool per codename rather than one shared pool. The indices
# are per suite, and a shared pool would let noble's Packages list trixie's
# binaries - apt would happily offer them and they would not install.
note "assembling the repository in $REPODIR"
rm -rf "$REPODIR"
mkdir -p "$REPODIR"
CODENAMES=()
for distdir in "$OUTDIR"/*/; do
[ -d "$distdir" ] || continue
codename=$(basename "$distdir")
arches=()
for archdir in "$distdir"*/; do
[ -d "$archdir" ] || continue
arch=$(basename "$archdir")
compgen -G "$archdir*.deb" >/dev/null || continue
arches+=("$arch")
for deb in "$archdir"*.deb; do
# Pool path by source package, the way Debian lays it out, so
# that the binaries of one source sit together.
src=$(dpkg-deb -f "$deb" Source 2>/dev/null | awk '{print $1}')
[ -n "$src" ] || src=$(dpkg-deb -f "$deb" Package)
case "$src" in
lib*) letter="${src:0:4}" ;;
*) letter="${src:0:1}" ;;
esac
pool="$REPODIR/pool/$codename/main/$letter/$src"
mkdir -p "$pool"
cp "$deb" "$pool/"
done
done
[ ${#arches[@]} -gt 0 ] || continue
CODENAMES+=("$codename")
# Deduplicate: a codename built for two architectures appears twice above.
mapfile -t arches < <(printf '%s\n' "${arches[@]}" | sort -u)
echo " $codename: ${arches[*]}"
for arch in "${arches[@]}"; do
bindir="$REPODIR/dists/$codename/main/binary-$arch"
mkdir -p "$bindir"
# Run from the repository root so that the Filename fields come out
# relative to it, which is what apt expects.
( cd "$REPODIR" &&
apt-ftparchive --arch "$arch" packages "pool/$codename" \
> "dists/$codename/main/binary-$arch/Packages" )
gzip -9 -k -f "$bindir/Packages"
cat > "$bindir/Release" <<EOF
Archive: $codename
Suite: $codename
Component: main
Origin: $ORIGIN
Label: $LABEL
Architecture: $arch
EOF
done
# The suite Release, carrying the checksums of everything above. Written
# to a temporary file first - apt-ftparchive walks the directory it is
# indexing, and would otherwise hash a half-written Release.
( cd "$REPODIR" &&
apt-ftparchive \
-o APT::FTPArchive::Release::Origin="$ORIGIN" \
-o APT::FTPArchive::Release::Label="$LABEL" \
-o APT::FTPArchive::Release::Suite="$codename" \
-o APT::FTPArchive::Release::Codename="$codename" \
-o APT::FTPArchive::Release::Components="main" \
-o APT::FTPArchive::Release::Architectures="${arches[*]}" \
-o APT::FTPArchive::Release::Description="Pica Pica Messenger packages" \
release "dists/$codename" > "$WORKDIR/Release.$codename" )
mv "$WORKDIR/Release.$codename" "$REPODIR/dists/$codename/Release"
if [ "$SIGN" -eq 1 ]; then
echo " signing $codename with $GPGKEY"
rm -f "$REPODIR/dists/$codename/Release.gpg" \
"$REPODIR/dists/$codename/InRelease"
# Both forms: InRelease is what modern apt fetches, Release.gpg is
# the detached signature older clients look for.
gpg --batch --yes --default-key "$GPGKEY" \
--armor --detach-sign \
-o "$REPODIR/dists/$codename/Release.gpg" \
"$REPODIR/dists/$codename/Release"
gpg --batch --yes --default-key "$GPGKEY" \
--clearsign \
-o "$REPODIR/dists/$codename/InRelease" \
"$REPODIR/dists/$codename/Release"
fi
done
[ ${#CODENAMES[@]} -gt 0 ] || die "no packages found under $OUTDIR"
if [ "$SIGN" -eq 1 ]; then
gpg --armor --export "$GPGKEY" > "$REPODIR/pica-pica-archive-keyring.asc"
fi
# --- how to use it --------------------------------------------------------
note "done"
cat <<EOF
Repository: $REPODIR
Suites: ${CODENAMES[*]}
Serve that directory over HTTP, then on a client:
sudo install -d /usr/share/keyrings
sudo curl -fsSL https://YOUR.HOST/pica-pica-archive-keyring.asc \\
-o /usr/share/keyrings/pica-pica-archive-keyring.asc
echo "deb [signed-by=/usr/share/keyrings/pica-pica-archive-keyring.asc] \\
https://YOUR.HOST \$(lsb_release -cs) main" \\
| sudo tee /etc/apt/sources.list.d/pica-pica.list
sudo apt update && sudo apt install pica-client
EOF
if [ "$SIGN" -eq 0 ]; then
cat <<'EOF'
The repository is NOT signed. apt will reject it unless clients add
[trusted=yes] to the sources.list entry, which disables authentication -
do that for local testing only.
EOF
fi
|