| Current Path : /proc/thread-self/root/proc/thread-self/root/snap/lxd/39313/commands/ |
| Current File : //proc/thread-self/root/proc/thread-self/root/snap/lxd/39313/commands/setup-zfs |
#!/bin/sh
set -eu
# Setup ZFS userspace tools on PATH and LD_LIBRARY_PATH.
# Must be sourced (. setup-zfs), not executed directly.
# Requires SNAP_CURRENT to be set by the calling script.
# Accepts zfs_external pre-set by the caller (e.g. daemon.start sources it
# from SNAP_COMMON/config before calling this helper); otherwise resolves it
# via snapctl. The snapctl fallback is needed for commands/lxd (i.e. `snap run
# lxd`) which does not source SNAP_COMMON/config and therefore always enters
# this helper with zfs_external unset.
if [ -z "${zfs_external+x}" ]; then
zfs_external="$(snapctl get zfs.external 2>/dev/null || echo false)"
fi
if [ "${zfs_external}" = "true" ]; then
echo "==> Using ZFS tools from the host system"
else
if [ -e /sys/module/zfs/version ]; then
read -r _ZFS_VERSION < /sys/module/zfs/version
else
_ZFS_VERSION=$(nsenter -t 1 -m modinfo -F version zfs 2>/dev/null || true)
fi
_ZFS_VER="$(echo "${_ZFS_VERSION}" | cut -d. -f1-2)"
if [ -d "${SNAP_CURRENT}/zfs-${_ZFS_VER}/bin" ]; then
echo "==> Setting up ZFS (${_ZFS_VER})"
export LD_LIBRARY_PATH="${SNAP_CURRENT}/zfs-${_ZFS_VER}/lib/:${LD_LIBRARY_PATH}"
export PATH="${SNAP_CURRENT}/zfs-${_ZFS_VER}/bin:${PATH}"
elif [ -n "${_ZFS_VER}" ]; then
echo "==> Unsupported ZFS version (${_ZFS_VER})" >&2
echo "Consider installing ZFS tools in the host and use zfs.external" >&2
else
echo "==> No ZFS support" >&2
echo "Consider installing ZFS tools in the host and use zfs.external" >&2
fi
# Do not pollute the caller's environment with internal variables
unset _ZFS_VERSION _ZFS_VER
fi