Add btrfs command check (for future btrfs-progs switch from Depends to Recommends in .deb)

This commit is contained in:
William Hirigoyen (Evolix) 2021-11-02 16:38:58 +01:00
parent 3be8b638fe
commit 4e7d5506de
5 changed files with 32 additions and 12 deletions

View File

@ -15,10 +15,9 @@ create_inc_btrfs() {
inc_path=$(inc_path "${jail_name}" "${inc_name}")
btrfs_bin=$(command -v btrfs)
### Pseudo-code
# if [ -z "${btrfs_bin}" ]; then
# error "Can't find btrfs"
# fi
if [ -z "${btrfs_bin}" ]; then
error "btrfs not found. Please install brtfs-progs."
fi
if dry_run; then
echo "[dry-run] btrfs subvolume snapshot of ${jail_path} to ${inc_path}"

View File

@ -12,8 +12,12 @@ target_path="${2:?}"
lock_target() {
target="${1:?}"
btrfs_bin=$(command -v btrfs)
if [ -z ${btrfs_bin} ]; then
error "btrfs not found. Please install brtfs-progs."
fi
if is_btrfs "${target}"; then
btrfs property set -ts "${target}" ro true
${btrfs_bin} property set -ts "${target}" ro true
info "Lock ${target}: done".
else
info "Lock ${target}: not BTRFS, nothing done".
@ -21,8 +25,12 @@ lock_target() {
}
unlock_target() {
target="${1:?}"
btrfs_bin=$(command -v btrfs)
if [ -z ${btrfs_bin} ]; then
error "btrfs not found. Please install brtfs-progs."
fi
if is_btrfs "${target}"; then
btrfs property set -ts "${target}" ro false
${btrfs_bin} property set -ts "${target}" ro false
info "Unlock ${target}: done."
else
info "Unlock ${target}: not BTRFS, nothing done."

View File

@ -18,9 +18,13 @@ test -d "${jail_path}" && error "Skip jail \`${jail_name}' : it already exists"
# Create config and jails directory
mkdir --parents "${CONFDIR}" "${JAILDIR}"
btrfs_bin=$(command -v btrfs)
if [ -z ${btrfs_bin} ]; then
error "btrfs not found. Please install brtfs-progs."
fi
if is_btrfs "$(dirname "${JAILDIR}")" || is_btrfs "${JAILDIR}"; then
/bin/btrfs subvolume create "${jail_path}"
${btrfs_bin} subvolume create "${jail_path}"
else
mkdir --parents "${jail_path}"
fi

View File

@ -52,9 +52,13 @@ fi
rm -f "${CONFDIR}/${jail_name}"
rm -rf "$(jail_config_dir "${jail_name}")"
jail_inode=$(stat --format=%i "${jail_path}")
if [ "${jail_inode}" -eq 256 ]; then
/bin/btrfs subvolume delete "${jail_path}" | debug
btrfs_bin=$(command -v btrfs)
if [ -z ${btrfs_bin} ]; then
error "btrfs not found. Please install brtfs-progs."
fi
if is_btrfs "${jail_path}"; then
${btrfs_bin} subvolume delete "${jail_path}" | debug
else
rm -rf "${jail_path:?}" | debug
fi
@ -65,7 +69,7 @@ if [ -d "${incs_path}" ]; then
for inc in ${incs}; do
inc_inode=$(stat --format=%i "${incs_path}/${inc}")
if [ "${inc_inode}" -eq 256 ]; then
/bin/btrfs subvolume delete "${incs_path}/${inc}" | debug
${btrfs_bin} subvolume delete "${incs_path}/${inc}" | debug
else
warning "You need to purge \`${incs_path}/${inc}' manually"
fi

View File

@ -61,11 +61,16 @@ delete_inc_btrfs() {
inc_name=$2
inc_path=$(inc_path "${jail_name}" "${inc_name}")
btrfs_bin=$(command -v btrfs)
if [ -z ${btrfs_bin} ]; then
error "btrfs not found. Please install brtfs-progs."
fi
if dry_run; then
echo "[dry-run] delete btrfs subvolume ${inc_path}"
else
/bin/btrfs subvolume delete "${inc_path}" | debug
${btrfs_bin} subvolume delete "${inc_path}" | debug
fi
}
delete_inc_ext4() {