From 87727b311c0814dba0bf2eefdb7e529a6aa9682c Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 18 Apr 2024 10:00:41 -0400 Subject: [PATCH 1/7] connect-plug-ovn-certificates: gracefully handle /etc/ovn being a symlink Signed-off-by: Simon Deziel (cherry picked from commit e3c9097fe22f176c885d5212758a70f66743d446) --- snapcraft/hooks/connect-plug-ovn-certificates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snapcraft/hooks/connect-plug-ovn-certificates b/snapcraft/hooks/connect-plug-ovn-certificates index 101313d2a..a9b77c7f4 100755 --- a/snapcraft/hooks/connect-plug-ovn-certificates +++ b/snapcraft/hooks/connect-plug-ovn-certificates @@ -37,7 +37,10 @@ get_bool() { if [ -e "/etc/.lxd_generated" ]; then ovn_builtin=$(get_bool "$(snapctl get ovn.builtin)") - if test -d /etc/ovn ; then + # Remove any symlink or cleanup the directory we created + if [ -L /etc/ovn ]; then + rm -f /etc/ovn + elif [ -d /etc/ovn ]; then rm -rf /etc/ovn fi From c61eb2082791efe6b399e1119b7ca2e1c7d5a078 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 18 Apr 2024 10:52:14 -0400 Subject: [PATCH 2/7] connect-plug-ovn-certificates: add some logging Signed-off-by: Simon Deziel (cherry picked from commit bf29949098859747afdc0b68ed2ff736ccc23f4b) --- snapcraft/hooks/connect-plug-ovn-certificates | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snapcraft/hooks/connect-plug-ovn-certificates b/snapcraft/hooks/connect-plug-ovn-certificates index a9b77c7f4..06ea22e27 100755 --- a/snapcraft/hooks/connect-plug-ovn-certificates +++ b/snapcraft/hooks/connect-plug-ovn-certificates @@ -37,14 +37,17 @@ get_bool() { if [ -e "/etc/.lxd_generated" ]; then ovn_builtin=$(get_bool "$(snapctl get ovn.builtin)") - # Remove any symlink or cleanup the directory we created + echo "==> Cleaning up OVN configuration" if [ -L /etc/ovn ]; then + echo "=> Removing /etc/ovn symlink" rm -f /etc/ovn elif [ -d /etc/ovn ]; then + echo "=> Removing /etc/ovn directory" rm -rf /etc/ovn fi if ! [ "${ovn_builtin:-"false"}" = "true" ]; then + echo "=> Configuring MicroOVN Content Interface" mkdir -p /etc/ovn ln -snf "${SNAP_DATA}/microovn/certificates/pki/client-cert.pem" /etc/ovn/cert_host ln -snf "${SNAP_DATA}/microovn/certificates/pki/client-privkey.pem" /etc/ovn/key_host From d748056347c340dfc0095989a037d5a644d1c227 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 18 Apr 2024 10:34:51 -0400 Subject: [PATCH 3/7] daemon.start: cleanup /etc/ovn before setting it up Signed-off-by: Simon Deziel (cherry picked from commit 1ff5a9adf6fda990678b29dd642d894a85c7bfef) --- snapcraft/commands/daemon.start | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/snapcraft/commands/daemon.start b/snapcraft/commands/daemon.start index a63acab29..ac1fa6fd9 100755 --- a/snapcraft/commands/daemon.start +++ b/snapcraft/commands/daemon.start @@ -321,8 +321,18 @@ sed \ "${SNAP}/etc/lvm/lvm.conf" > /etc/lvm/lvm.conf # Setup for OVN +echo "==> Cleaning up OVN configuration" +if [ -L /etc/ovn ]; then + echo "=> Removing /etc/ovn symlink" + rm -f /etc/ovn +elif [ -d /etc/ovn ]; then + echo "=> Removing /etc/ovn directory" + rm -rf /etc/ovn +fi + echo "==> Setting up OVN configuration" if [ "${ovn_builtin:-"false"}" = "true" ]; then + echo "=> Using builtin OVN" mkdir -p "${SNAP_COMMON}/ovn" ln -s "${SNAP_COMMON}/ovn" /etc/ovn elif [ -d "${SNAP_DATA}/microovn/certificates/pki" ]; then From 22f8d76ef679711cc7aa92b0ada50b5390537696 Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 14 Mar 2024 09:04:59 -0400 Subject: [PATCH 4/7] snapcraft/wrappers/editor: do not export XDG_ vars `lxc config edit` would generate some noise if `/root/.local` didn't exist: ``` Unable to create directory /root/.local/share//nano/: No such file or directory It is required for saving/loading search history or cursor positions. ``` Normally, `nano` would create the hiearchy `/root/.local/share/nano/` itself if XDG_DATA_HOME is not defined. This hiearchy creation logic is skipped if the variable is defined. The spec [1] contains this: > If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. > If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. > If $XDG_STATE_HOME is either not set or empty, a default equal to $HOME/.local/state should be used. So let's not export those as `nano` knows about those defaults and can then create the proper directories without warnings. [1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables Signed-off-by: Simon Deziel (cherry picked from commit 7dcb188c2b10e9d5fe95f13a0c82e3fe9ef54d2c) --- snapcraft/wrappers/editor | 3 --- 1 file changed, 3 deletions(-) diff --git a/snapcraft/wrappers/editor b/snapcraft/wrappers/editor index 31ca143c6..d9076f991 100755 --- a/snapcraft/wrappers/editor +++ b/snapcraft/wrappers/editor @@ -7,9 +7,6 @@ run_cmd() { export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" export HOME="${SNAP_REAL_HOME}" export USER="${USERNAME}" - [ -z "${XDG_DATA_HOME:-}" ] && export XDG_DATA_HOME="${HOME}/.local/share/" - [ -z "${XDG_CONFIG_HOME:-}" ] && export XDG_CONFIG_HOME="${HOME}/.config/" - [ -z "${XDG_STATE_HOME:-}" ] && export XDG_STATE_HOME="${HOME}/.local/state/" # shellcheck disable=SC2145 exec unshare --kill-child -U -m -p -r -f --root="/var/lib/snapd/hostfs/" "/bin/sh" -c "mount -t proc proc /proc 2>/dev/null || true; exec \"${CMD}\" \"$@\"" From 6baedfc3739f973652c51b00c7766ac56a83495c Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 14 Mar 2024 09:50:33 -0400 Subject: [PATCH 5/7] snapcraft/wrappers/remote-viewer: do not export XDG_ var The spec [1] contains this: > If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. > If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. > If $XDG_STATE_HOME is either not set or empty, a default equal to $HOME/.local/state should be used. So let's not export those since applications should simply rely on the default/empty. Exporting those without any corresponding directory caused issue with `nano` as can be seen in the previous commit. Also, on a "normal" desktop environment, none of XDG_DATA_HOME, XDG_CONFIG_HOME and XDG_STATE_HOME are exported: ``` $ env | grep ^XDG_ XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg XDG_MENU_PREFIX=gnome- XDG_SESSION_DESKTOP=ubuntu XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=ubuntu:GNOME XDG_SESSION_CLASS=user XDG_RUNTIME_DIR=/run/user/1000 XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop ``` [1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables Signed-off-by: Simon Deziel (cherry picked from commit 1c07fcf7de787facfcc26b4fe221d78016f6f7d9) --- snapcraft/wrappers/remote-viewer | 3 --- 1 file changed, 3 deletions(-) diff --git a/snapcraft/wrappers/remote-viewer b/snapcraft/wrappers/remote-viewer index 4caf7272d..085eab3de 100755 --- a/snapcraft/wrappers/remote-viewer +++ b/snapcraft/wrappers/remote-viewer @@ -7,9 +7,6 @@ run_cmd() { export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" export HOME="${SNAP_REAL_HOME}" export USER="${USERNAME}" - [ -z "${XDG_DATA_HOME:-}" ] && export XDG_DATA_HOME="${HOME}/.local/share/" - [ -z "${XDG_CONFIG_HOME:-}" ] && export XDG_CONFIG_HOME="${HOME}/.config/" - [ -z "${XDG_STATE_HOME:-}" ] && export XDG_STATE_HOME="${HOME}/.local/state/" exec unshare -U -r chroot "/var/lib/snapd/hostfs/" "${CMD}" "$@" } From 3d2cfb2c4398f8bdb3a85cd3eba6e54f074e460d Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Mon, 22 Apr 2024 14:32:22 -0400 Subject: [PATCH 6/7] editor: better handle nano rc files When indirectly invoking `nano` as a non-root user this error is displayed: ``` ubuntu@nv1:~$ lxc profile edit default Unable to create directory /root/.local/share/nano/: Permission denied It is required for saving/loading search history or cursor positions. ``` While applications should use a default value for `XDG_DATA_HOME` of `$HOME/.local/share` it seems that `nano` does not. Exporting `XDG_DATA_HOME` helps but `nano` will fail if the directory does not exist: ``` $ ll .local/ ls: cannot access '.local/': No such file or directory $ lxc profile edit default Unable to create directory /home/ubuntu/.local/share/nano/: No such file or directory It is required for saving/loading search history or cursor positions. ``` As such, if the directory `$HOME/.local/share` does not exist, tell `nano` to not attempt reading any rc files. This provides a nicer experience: ``` ubuntu@nv1:~$ ll .local/ ls: cannot access '.local/': No such file or directory ubuntu@nv1:~$ lxc profile edit default Instructing nano to ignore RC files due to missing directory: "/home/ubuntu/.local/share" ubuntu@nv1:~$ ll .local/ ls: cannot access '.local/': No such file or directory ubuntu@nv1:~$ mkdir -p .local/share ubuntu@nv1:~$ lxc profile edit default ubuntu@nv1:~$ ``` When invoked by root, `nano` has no problem creating `/root/.local/share`. Signed-off-by: Simon Deziel (cherry picked from commit b32b62631fb2f7acde385efe5471788c81859250) --- snapcraft/wrappers/editor | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/snapcraft/wrappers/editor b/snapcraft/wrappers/editor index d9076f991..c431f513c 100755 --- a/snapcraft/wrappers/editor +++ b/snapcraft/wrappers/editor @@ -7,9 +7,17 @@ run_cmd() { export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" export HOME="${SNAP_REAL_HOME}" export USER="${USERNAME}" + IGNORERCFILES="" + if [ "${HOME}" != "/root" ] && [ "${CMD}" = "nano" ]; then + export XDG_DATA_HOME="${HOME}/.local/share" + if [ ! -d "/var/lib/snapd/hostfs/${XDG_DATA_HOME}" ]; then + echo "Instructing nano to ignore RC files due to missing directory: \"${XDG_DATA_HOME}\"" + IGNORERCFILES="--ignorercfiles" + fi + fi # shellcheck disable=SC2145 - exec unshare --kill-child -U -m -p -r -f --root="/var/lib/snapd/hostfs/" "/bin/sh" -c "mount -t proc proc /proc 2>/dev/null || true; exec \"${CMD}\" \"$@\"" + exec unshare --kill-child -U -m -p -r -f --root="/var/lib/snapd/hostfs/" "/bin/sh" -c "mount -t proc proc /proc 2>/dev/null || true; exec \"${CMD}\" ${IGNORERCFILES} \"$@\"" } # Detect base name From d3c96c8f69138213cd1050118cd786cf04f1fe9d Mon Sep 17 00:00:00 2001 From: Thomas Parrott Date: Tue, 23 Apr 2024 13:23:37 +0100 Subject: [PATCH 7/7] github: Use explicit -package argument to lxd-snapcraft Signed-off-by: Thomas Parrott --- .github/workflows/builds.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 2af5dc2fb..2664b87f9 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -57,10 +57,10 @@ jobs: go install github.com/canonical/lxd-ci/lxd-snapcraft@latest git clone -b "${TARGET}" git+ssh://lxdbot@git.launchpad.net/~canonical-lxd/lxd ~/lxd-pkg-snap-lp # XXX: `originVer` contains an array with the 2 versions - originVer=($(lxd-snapcraft -get-version -file snapcraft.yaml)) + originVer=($(lxd-snapcraft -package lxd -get-version -file snapcraft.yaml)) rsync -a --exclude .git --delete . ~/lxd-pkg-snap-lp/ cd ~/lxd-pkg-snap-lp - lxd-snapcraft -set-version "${originVer[0]}-${localRev:0:7}" -set-source-commit "" + lxd-snapcraft -package lxd -set-version "${originVer[0]}-${localRev:0:7}" -set-source-commit "" git add --all git commit --all --quiet -s --allow-empty -m "Automatic upstream build (${TARGET})" -m "Upstream commit: ${localRev}" git show