-
Notifications
You must be signed in to change notification settings - Fork 186
/
build-recipe-mkosi
158 lines (141 loc) · 5.56 KB
/
build-recipe-mkosi
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
#
# mkosi specific functions.
#
################################################################
#
# Copyright (c) 2022 Luca Boccassi <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# 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 (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
recipe_setup_mkosi() {
TOPDIR=/usr/src/packages
test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
for i in OTHER SOURCES ; do
mkdir -p "$BUILD_ROOT$TOPDIR/$i"
done
if test "$MYSRCDIR" = "$BUILD_ROOT/.build-srcdir" ; then
mv "$MYSRCDIR"/* "$BUILD_ROOT$TOPDIR/SOURCES/"
else
copy_sources "$MYSRCDIR" "$BUILD_ROOT$TOPDIR/SOURCES/"
#cp -r "$MYSRCDIR/mkosi.cache" "$BUILD_ROOT$TOPDIR/SOURCES/"
fi
chown -hR "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
}
recipe_prepare_mkosi() {
:
}
recipe_build_mkosi() {
local ARCH DIST RELEASE_ARG
if [ -x "$BUILD_ROOT/bin/rpm" ]; then
ARCH=$(chroot "$BUILD_ROOT" sh -c "rpm --eval '%{_target_cpu}'")
elif [ -x "$BUILD_ROOT/usr/bin/dpkg-architecture" ]; then
ARCH=$(chroot "$BUILD_ROOT" sh -c "dpkg-architecture -qDEB_BUILD_ARCH")
# The distro release is usually specified in the recipe, but it is not mandatory.
DIST=$(grep Release= "${RECIPEFILE}" | sed "s/\s*Release\s*=\s*\(.*\)\s*/\1/")
if [ -z "$DIST" ]; then
DIST=$(chroot "$BUILD_ROOT" sh -c "lsb_release --codename" | awk '{ print $2 }')
fi
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=845651
# For our use case it makes sense to always return the testing codename. In
# the example cited in the above bug, the metadata for sid would be incorrect
# anyway, and we would want the ones for potato.
if test "${DIST}" = "n/a" ; then
DIST=$(chroot "$BUILD_ROOT" sh -c "sed 's/\(.*\)\/.*/\1/' /etc/debian_version")
fi
# Pass it to mkosi, so that the configured mirror is the same as the repository created below
RELEASE_ARG="--release ${DIST}"
test -z "${ARCH}" -o -z "${DIST}" && cleanup_and_exit 1
elif [ ! -x "$BUILD_ROOT/usr/bin/repo-add" ]; then
cleanup_and_exit 1
fi
test -d "$BUILD_ROOT/.build.binaries" || cleanup_and_exit 1 "missing $BUILD_ROOT/.build.binaries"
if test "$DO_INIT" = true; then
if [ -x "$BUILD_ROOT/usr/bin/dpkg-architecture" ] && [ ! -d "$BUILD_ROOT/.build.binaries/dists" ]; then
echo "creating debian repository metadata..."
createrepo_debian "$BUILD_ROOT/.build.binaries" "${ARCH}" "${DIST}"
elif [ -x "$BUILD_ROOT/bin/rpm" ] && [ ! -d "$BUILD_ROOT/.build.binaries/repodata" ]; then
echo "creating rpm repository metadata..."
if chroot "$BUILD_ROOT" test -x /usr/bin/createrepo_c; then
chroot "$BUILD_ROOT" /usr/bin/createrepo_c /.build.binaries
elif chroot "$BUILD_ROOT" test -x /usr/bin/createrepo; then
chroot "$BUILD_ROOT" /usr/bin/createrepo /.build.binaries
else
cleanup_and_exit 1 "No createrepo found in build root"
fi
elif [ -x "$BUILD_ROOT/usr/bin/repo-add" ]; then
echo "creating Arch Linux repository metadata..."
chroot "$BUILD_ROOT" sh -c "repo-add /.build.binaries/core.db.tar.gz /.build.binaries/*"
fi
fi
local image_version=""
if [ -n "$RELEASE" ]; then
image_version="--image-version=${RELEASE}"
else
# Provide some fallback value for %v specifiers
image_version="--image-version=0"
fi
set -- mkosi \
--directory "$TOPDIR/SOURCES" \
--default \
"$RECIPEFILE" \
$RELEASE_ARG \
$image_version \
--nspawn-keep-unit \
--output-dir "$TOPDIR/OTHER" \
--checksum \
--repository-key-check=no \
--with-network=never \
--local-mirror file:///.build.binaries/ \
--cache /.build.binaries/ \
build
echo "running $*"
chroot "$BUILD_ROOT" "$@" || cleanup_and_exit 1
# move the output files from the subdirectory, as only files in the OTHER/ directory
# are published, but they get deposited in OTHER/$DIST~$RELEASE/
for d in "$BUILD_ROOT/$TOPDIR"/OTHER/*/; do
if [ ! -d "$d" ]; then
continue
fi
mv "$d"/* "$BUILD_ROOT/$TOPDIR/OTHER/"
rmdir "$d"
done
# if present, compress the manifest file(s) which can be quite large
for f in "$BUILD_ROOT/$TOPDIR"/OTHER/*.manifest; do
if [ ! -f "$f" ]; then
continue
fi
gzip -9 -f "$f"
done
cat <<-EOF > "$BUILD_ROOT/checksum.sh"
echo "Create sha256 files..."
cd "/$TOPDIR"/OTHER
for f in *; do
[ -f "\$f" ] || continue
/usr/bin/sha256sum "\$f" > "\$f.sha256"
done
EOF
chroot "$BUILD_ROOT" sh /checksum.sh
rm -f "$BUILD_ROOT/checksum.sh"
# shellcheck disable=SC2034
BUILD_SUCCEEDED=true
}
recipe_resultdirs_mkosi() {
:
}
recipe_cleanup_mkosi() {
:
}
# vim: syntax=sh