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}") inc_path=$(inc_path "${jail_name}" "${inc_name}")
btrfs_bin=$(command -v btrfs) btrfs_bin=$(command -v btrfs)
### Pseudo-code if [ -z "${btrfs_bin}" ]; then
# if [ -z "${btrfs_bin}" ]; then error "btrfs not found. Please install brtfs-progs."
# error "Can't find btrfs" fi
# fi
if dry_run; then if dry_run; then
echo "[dry-run] btrfs subvolume snapshot of ${jail_path} to ${inc_path}" echo "[dry-run] btrfs subvolume snapshot of ${jail_path} to ${inc_path}"

View file

@ -12,8 +12,12 @@ target_path="${2:?}"
lock_target() { lock_target() {
target="${1:?}" 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 if is_btrfs "${target}"; then
btrfs property set -ts "${target}" ro true ${btrfs_bin} property set -ts "${target}" ro true
info "Lock ${target}: done". info "Lock ${target}: done".
else else
info "Lock ${target}: not BTRFS, nothing done". info "Lock ${target}: not BTRFS, nothing done".
@ -21,8 +25,12 @@ lock_target() {
} }
unlock_target() { unlock_target() {
target="${1:?}" 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 if is_btrfs "${target}"; then
btrfs property set -ts "${target}" ro false ${btrfs_bin} property set -ts "${target}" ro false
info "Unlock ${target}: done." info "Unlock ${target}: done."
else else
info "Unlock ${target}: not BTRFS, nothing done." 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 # Create config and jails directory
mkdir --parents "${CONFDIR}" "${JAILDIR}" 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 if is_btrfs "$(dirname "${JAILDIR}")" || is_btrfs "${JAILDIR}"; then
/bin/btrfs subvolume create "${jail_path}" ${btrfs_bin} subvolume create "${jail_path}"
else else
mkdir --parents "${jail_path}" mkdir --parents "${jail_path}"
fi fi

View file

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

View file

@ -61,11 +61,16 @@ delete_inc_btrfs() {
inc_name=$2 inc_name=$2
inc_path=$(inc_path "${jail_name}" "${inc_name}") 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 if dry_run; then
echo "[dry-run] delete btrfs subvolume ${inc_path}" echo "[dry-run] delete btrfs subvolume ${inc_path}"
else else
/bin/btrfs subvolume delete "${inc_path}" | debug ${btrfs_bin} subvolume delete "${inc_path}" | debug
fi fi
} }
delete_inc_ext4() { delete_inc_ext4() {