cmd/snap-mgmt: introduce snap-mgmt tool #4316

Merged
merged 8 commits into from Dec 1, 2017

cmd/snap-mgmt: replace use of /snap with SNAP_MOUNT_DIR

Cleanup remaining uses of /snap and replace them with SNAP_MOUNT_DIR

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
  • Loading branch information...
commit 44cec064f04899d4821093b0c69459df5e331926 @bboozzoo bboozzoo committed Nov 30, 2017
@@ -42,16 +42,16 @@ purge() {
# snap.mount.service is a trusty thing
@Conan-Kudo

Conan-Kudo Dec 4, 2017

Contributor

Please do not refer to distribution releases by specific codenames, refer to them by their full names. Context is important for a multi-distribution script.

systemctl_stop snap.mount.service
else
- # undo any bind mount to /snap that resulted from LP:#1668659
+ # undo any bind mount to ${SNAP_MOUNT_DIR} that resulted from LP:#1668659
# (that bug can't happen in trusty -- and doing this would mess up snap.mount.service there)
@Conan-Kudo

Conan-Kudo Dec 4, 2017

Contributor

And again...

- if grep -q "/snap /snap" /proc/self/mountinfo; then
- umount -l /snap || true
+ if grep -q "${SNAP_MOUNT_DIR} ${SNAP_MOUNT_DIR}" /proc/self/mountinfo; then
+ umount -l "${SNAP_MOUNT_DIR}" || true
fi
fi
units=$(systemctl list-unit-files --full | grep -vF snap.mount.service || true)
- mounts=$(systemctl list-unit-files --full | grep "^${SNAP_UNIT_PREFIX}[-.].*\.mount" | cut -f1 -d ' ')
- services=$(systemctl list-unit-files --full | grep "^${SNAP_UNIT_PREFIX}[-.].*\.service" | cut -f1 -d ' ')
+ mounts=$(echo "$units" | grep "^${SNAP_UNIT_PREFIX}[-.].*\.mount" | cut -f1 -d ' ')
+ services=$(echo "$units" | grep "^${SNAP_UNIT_PREFIX}[-.].*\.service" | cut -f1 -d ' ')
for unit in $services $mounts; do
# ensure its really a snap mount unit or systemd unit
if ! grep -q 'What=/var/lib/snapd/snaps/' "/etc/systemd/system/$unit" && ! grep -q 'X-Snappy=yes' "/etc/systemd/system/$unit"; then
@@ -127,7 +127,8 @@ purge() {
if test -d /etc/apparmor.d; then
echo "Removing extra snap-confine apparmor rules"
- rm -f /etc/apparmor.d/snap.core.*.usr.lib.snapd.snap-confine
+ # shellcheck disable=SC2046
+ rm -f /etc/apparmor.d/$(echo "$SNAP_UNIT_PREFIX" | tr '-' '.').core.*.usr.lib.snapd.snap-confine
@Conan-Kudo

Conan-Kudo Dec 4, 2017

Contributor

You cannot guarantee the path for snap-confine is in fact /usr/lib/snapd. Please correct this appropriately.

@bboozzoo

bboozzoo Dec 4, 2017

Contributor

AFAIU this is the path inside the core snap, not your host's $(libexecdir)/snapd/snap-confine

@Conan-Kudo

Conan-Kudo Dec 4, 2017

Contributor

On all systems that aren't Ubuntu, they will be the host's. No one else has re-exec enabled.

@bboozzoo

bboozzoo Dec 4, 2017

Contributor

I'll double check this and get back to you.

fi
}