2020-11-28 10:46:57 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Description: Lock or unlock dated copies (incs) on BTRFS formatted volumes
|
|
|
|
# Usage: inc-<lock|unlock> <all|jailname[/inc]>
|
|
|
|
#
|
|
|
|
|
|
|
|
# shellcheck source=./includes
|
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
|
|
|
|
|
|
|
lock_status="${1:?}"
|
|
|
|
target_path="${2:?}"
|
|
|
|
|
|
|
|
lock_target() {
|
|
|
|
target="${1:?}"
|
2021-11-02 16:38:58 +01:00
|
|
|
btrfs_bin=$(command -v btrfs)
|
2022-04-28 14:51:10 +02:00
|
|
|
if [ -z "${btrfs_bin}" ]; then
|
2022-03-09 16:16:35 +01:00
|
|
|
error "btrfs not found. Please install btrfs-progs."
|
2021-11-02 16:38:58 +01:00
|
|
|
fi
|
2020-11-28 10:46:57 +01:00
|
|
|
if is_btrfs "${target}"; then
|
2021-11-02 16:38:58 +01:00
|
|
|
${btrfs_bin} property set -ts "${target}" ro true
|
2020-11-28 10:46:57 +01:00
|
|
|
info "Lock ${target}: done".
|
|
|
|
else
|
|
|
|
info "Lock ${target}: not BTRFS, nothing done".
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
unlock_target() {
|
|
|
|
target="${1:?}"
|
2021-11-02 16:38:58 +01:00
|
|
|
btrfs_bin=$(command -v btrfs)
|
2022-04-28 14:51:10 +02:00
|
|
|
if [ -z "${btrfs_bin}" ]; then
|
2021-11-02 16:38:58 +01:00
|
|
|
error "btrfs not found. Please install brtfs-progs."
|
|
|
|
fi
|
2020-11-28 10:46:57 +01:00
|
|
|
if is_btrfs "${target}"; then
|
2021-11-02 16:38:58 +01:00
|
|
|
${btrfs_bin} property set -ts "${target}" ro false
|
2020-11-28 10:46:57 +01:00
|
|
|
info "Unlock ${target}: done."
|
|
|
|
else
|
|
|
|
info "Unlock ${target}: not BTRFS, nothing done."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# this directory test must be quoted,beacause of the probable globbing
|
|
|
|
if [ -d ${target_path} ]; then
|
|
|
|
if [ "${lock_status}" = "on" ]; then
|
|
|
|
lock_target "${target_path}"
|
|
|
|
elif [ "${lock_status}" = "off" ]; then
|
|
|
|
unlock_target "${target_path}"
|
|
|
|
else
|
|
|
|
error "Unknown lock status \`${lock_status}'."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
error "\`${target_path}': no such file or directory."
|
|
|
|
exit 1
|
|
|
|
fi
|