Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically lookup the base snap name #262

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions snapcraft/commands/daemon.start
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export PYTHONPATH=/snap/lxd/current/lib/python3/dist-packages/
# Detect model
SNAP_MODEL="$(nsenter -t 1 -m snap model --assertion | sed -n 's/^model: \(.\+\)/\1/p')"

# Detect base name
SNAP_BASE="$(sed -n '/^name:/ s/^name:\s*\(core[0-9]\{2\}\)/\1/p' /meta/snap.yaml)"

# Wait for appliance configuration
if echo "${SNAP_MODEL}" | grep -q "^lxd-core"; then
while :; do
Expand Down Expand Up @@ -229,7 +232,7 @@ done

## And the bits we need from the core snap
for entry in alternatives apparmor apparmor.d; do
ln -s "/snap/core22/current/etc/${entry}" "/etc/${entry}"
ln -s "/snap/${SNAP_BASE}/current/etc/${entry}" "/etc/${entry}"
done

## And those we directly ship in the snap
Expand All @@ -245,7 +248,7 @@ if [ -e "/var/lib/snapd/hostfs/etc/ssl" ] && [ -e "/var/lib/snapd/hostfs/usr/sha
ln -s "/var/lib/snapd/hostfs/etc/ssl" "/etc/ssl"
mountpoint -q "/usr/share/ca-certificates" || mount -o ro,bind "/var/lib/snapd/hostfs/usr/share/ca-certificates" "/usr/share/ca-certificates"
else
ln -s "/snap/core22/current/etc/ssl" "/etc/ssl"
ln -s "/snap/${SNAP_BASE}/current/etc/ssl" "/etc/ssl"
fi

## Try to handle special /etc/resolv.conf setups
Expand Down Expand Up @@ -492,15 +495,15 @@ if [ -e "${SNAP_COMMON}/var/lib/lxcfs/cgroup" ]; then
CURRENT_FUSE="${NEW_FUSE}"

## Get the name of the base (core2X) used by the new snap
NEW_BASE="$(grep ^name /meta/snap.yaml)"
NEW_BASE="${SNAP_BASE}"
CURRENT_BASE="${NEW_BASE}"

## Use the old lxcfs instance to get the libfuse soname and old base it uses
if [ -e "${SNAP_COMMON}/lxcfs.pid" ]; then
read -r CURRENT_PID < "${SNAP_COMMON}/lxcfs.pid"
if [ -e "/proc/${CURRENT_PID}" ]; then
CURRENT_FUSE="$(ldd "/proc/${CURRENT_PID}/exe" | sed -n "/libfuse3\?\.so/ s/.*libfuse3\?\.so\.\([^ ]\+\) .*/\1/p")"
CURRENT_BASE="$(grep ^name "/proc/${CURRENT_PID}/root/meta/snap.yaml")"
CURRENT_BASE="$(sed -n '/^name:/ s/^name:\s*\(core[0-9]\{2\}\)/\1/p' "/proc/${CURRENT_PID}/root/meta/snap.yaml")"
fi
fi

Expand Down
5 changes: 4 additions & 1 deletion snapcraft/wrappers/editor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ run_cmd() {
exec unshare --kill-child -U -m -p -r -f -R "/var/lib/snapd/hostfs/" "/bin/sh" -c "mount -t proc proc /proc 2>/dev/null || true; exec \"${CMD}\" \"$@\""
}

# Detect base name
SNAP_BASE="$(sed -n '/^name:/ s/^name:\s*\(core[0-9]\{2\}\)/\1/p' /meta/snap.yaml)"

USERNS=1
[ -e /proc/sys/kernel/unprivileged_userns_clone ] && grep -qxF 0 /proc/sys/kernel/unprivileged_userns_clone && USERNS=0

Expand Down Expand Up @@ -56,7 +59,7 @@ fi
# Setup for VIM.
if [ "$EDIT_CMD" != "nano" ]; then
# Find the base use by the LXD snap.
for vimrc in "${SNAP_USER_COMMON}/.vimrc" "/snap/core22/current/etc/vim/vimrc"; do
for vimrc in "${SNAP_USER_COMMON}/.vimrc" "/snap/${SNAP_BASE}/current/etc/vim/vimrc"; do
[ -r "${vimrc}" ] || continue
export VIMINIT="source ${vimrc}"
done
Expand Down
9 changes: 6 additions & 3 deletions snapcraft/wrappers/kmod
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#!/bin/sh
NAME="$(basename "${0}")"

# Detect base name
SNAP_BASE="$(sed -n '/^name:/ s/^name:\s*\(core[0-9]\{2\}\)/\1/p' /meta/snap.yaml)"

if [ "$(id -u)" != "0" ] && [ "${NAME}" = "modinfo" ]; then
TMPDIR=$(mktemp -d)
ln -s "/snap/core22/current/bin/kmod" "${TMPDIR}/modinfo"
TMPDIR="$(mktemp -d)"
ln -s "/snap/${SNAP_BASE}/current/bin/kmod" "${TMPDIR}/modinfo"
"${TMPDIR}/modinfo" "$@"
RET=$?
rm -Rf "${TMPDIR}"
exit "${RET}"
fi

if [ "${NAME}" = "lsmod" ]; then
exec "/snap/core22/current/bin/kmod" "list" "$@"
exec "/snap/${SNAP_BASE}/current/bin/kmod" "list" "$@"
fi

for i in "/bin/${NAME}" "/sbin/${NAME}" "/usr/bin/${NAME}" "/usr/sbin/${NAME}"; do
Expand Down
Loading