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
|
#!/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 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.
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, source the created file to get the variables
pushd ..
./mkversion.sh
# shellcheck disable=SC1091
. data/info
SNAPD_VERSION=$VERSION
popd
contains_element() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
# Folder for snapd bits, that will be copied to all releases
mkdir -p snapd-initramfs
pushd snapd-initramfs
## snap-bootstrap
mkdir -p cmd
# go commands do not follow symlinks, copy instead
cp -a ../../cmd/snap-bootstrap/ cmd/
cat << EOF > go.mod
module github.com/snapcore/snap-bootstrap
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 -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
popd
# Go through the different supported Ubuntu releases, creating source
# packages for them.
no_link=(debian go.mod go.sum cmd snapd vendor)
if [ "$#" -eq 0 ]; then
# If no explicit releases are given, build all releases in the directory
deb_dir=(*/debian)
set -- "${deb_dir[@]%/debian}"
fi
for rel; do
series=$(dpkg-parsechangelog --file "$rel"/debian/changelog --show-field Distribution)
if [ "$rel" = latest ]; then
ubuntu_ver=$(ubuntu-distro-info --series="$series" -r)
# We might have "xx.xx LTS"
ubuntu_ver=${ubuntu_ver%% *}
else
ubuntu_ver=$rel
for p in latest/*; do
file=${p#latest/}
if contains_element "$file" "${no_link[@]}"; then
continue
fi
cp -a "$p" "$rel/"
done
fi
pushd "$rel"
cp -a ../snapd-initramfs/* .
curr_ver=$(dpkg-parsechangelog --show-field Version)
initrd_ver=${curr_ver%%+*}
next_ver="$initrd_ver"+"$SNAPD_VERSION"+"$ubuntu_ver"
dch -v "$next_ver" "Update to snapd version $SNAPD_VERSION"
dch --distribution "$series" -r ""
dpkg-buildpackage -S -sa -d
popd
done
|