Skip to content

Commit

Permalink
tests,core-initrd: introduce script to build core-initrd for
Browse files Browse the repository at this point in the history
just one Ubuntu release.
  • Loading branch information
alfonsosanchezbeato committed Dec 17, 2024
1 parent b800bb2 commit 9587030
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
42 changes: 30 additions & 12 deletions core-initrd/build-source-pkgs.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#!/bin/bash -exu

# This scripts cleans-up the core-initrd subfolder and pulls all necessary bits
# from snapd to create the ubuntu-core-initramfs source package for each
# supported Ubuntu release. It is meant to be called inside the core-initrd
# folder.

git clean -ffdx
# from snapd to create the ubuntu-core-initramfs source package for supported
# Ubuntu releases. It is meant to be called inside the core-initrd folder.
#
# Usage:
#
# $ ./build-source-pkgs.sh <ubuntu_release1> ... <ubuntu_releaseN>
# or
# $ ./build-source-pkgs.sh
#
# to build all releases in the directory.

# The current commit must be in the repo to be able to get the dependencies
# of snap-bootstrap.
commit=$(git rev-parse HEAD)
if [ -n "${TEST_BUILD-}" ]; then
# code at this commit won't be actually used, but we need it to exist so go
# mod tidy runs properly
commit=master
else
git clean -ffdx
commit=$(git rev-parse HEAD)
fi

# build info file
pushd ..
Expand All @@ -24,10 +36,10 @@ contains_element() {
}

# Folder for snapd bits, that will be copied to all releases
mkdir snapd-initramfs
mkdir -p snapd-initramfs
pushd snapd-initramfs
## snap-bootstrap
mkdir cmd
mkdir -p cmd
# go commands do not follow symlinks, copy instead
cp -a ../../cmd/snap-bootstrap/ cmd/
cat << EOF > go.mod
Expand All @@ -37,13 +49,17 @@ go 1.18
require github.com/snapcore/snapd $commit
EOF
if [ -n "${TEST_BUILD-}" ]; then
# Use local code for test builds
printf "\nreplace github.com/snapcore/snapd => ../../\n" >> go.mod
fi
# solve dependencies
go mod tidy
# build vendor folder
go mod vendor

## info and recovery trigger service
mkdir snapd
mkdir -p snapd
cp ../../data/info snapd/
sed 's#@libexecdir@#/usr/lib#' ../../data/systemd/snapd.recovery-chooser-trigger.service.in > \
snapd/snapd.recovery-chooser-trigger.service
Expand All @@ -52,9 +68,11 @@ popd
# Go through the different supported Ubuntu releases, creating source
# packages for them.
no_link=(debian go.mod go.sum cmd snapd vendor)
for dir in */debian; do
rel=${dir%/debian}

if [ "$#" -eq 0 ]; then
deb_dir=(*/debian)
set -- "${deb_dir[@]%/debian}"
fi
for rel; do
if [ "$rel" != latest ]; then
for p in latest/*; do
file=${p#latest/}
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/core-initrd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -ex

# Builds and installs the ubuntu-core-initramfs package for the Ubuntu
# release running in the system.
build_and_install_initramfs_deb() {
pushd "$PROJECT_PATH"/core-initrd

# For dpkg-parsechangelog (used by mkversion.sh too) and to have
# the tools needed to build the source package.
quiet eatmydata apt-get install -y dpkg-dev debhelper
codename=$(lsb_release -c -s)
latest=$(dpkg-parsechangelog --file latest/debian/changelog --show-field Distribution)
if [ "$codename" = "$latest" ]; then
rel=latest
else
rel=$(lsb_release -r -s)
fi

# build source packages using local code
TEST_BUILD=1 ./build-source-pkgs.sh "$rel"

# build and install binary package

pushd "$rel"
quiet eatmydata apt-get build-dep -y ./
dpkg-buildpackage -tc -us -uc
popd

quiet eatmydata apt-get install -y ./ubuntu-core-initramfs_*.deb

popd
}

0 comments on commit 9587030

Please sign in to comment.