osi-tools/lib/mk/format-btrfs.sh

45 lines
1.2 KiB
Bash
Raw Normal View History

#!/hint/bash
# Copyright (C) 2018 Luke Shumaker
# Copyright (C) 2023-2024 Umorpha Systems
# SPDX-License-Identifier: AGPL-3.0-or-later
source "${install_prefix}/lib/mk/shellcheck.sh"
formats+=('btrfs')
format_is_block['btrfs']='true'
# Option parsing #####################################################
format_options['btrfs']='size fsuuid'
format_checkconf:btrfs() {
shellcheck:format_checkconf
packages+=(btrfs-progs)
}
# format_is_block[…]='true' settings #################################
format_mkfs:btrfs() {
shellcheck:format_mkfs
mkfs.btrfs ${arg_fmtconf[fsuuid]:+"--uuid=${arg_fmtconf[fsuuid]}"} -- "$arg_file"
}
format_editfs:btrfs() (
shellcheck:format_editfs
if [[ -n ${arg_fmtconf[fsuuid]:-} ]]; then
# Explicit new FSUUID.
btrfstune -f -U "${arg_fmtconf[fsuuid]:-}" "$arg_file"
elif [[ -n $arg_edit_base ]]; then
# Random new FSUUID.
btrfstune -fu "$arg_file"
fi
if [[ -n ${arg_fmtconf[size]:-} ]]; then
local mountpoint
mountpoint=$(mktemp -dt -- "${0##*/}.btrfs.sXXXXXXXXXX")
trap "rmdir -- ${mountpoint@Q}" EXIT
osi.sh:sudo -- "${install_prefix}/bin/osi-mount" --root -- "$arg_file" "$mountpoint" btrfs filesystem resize "${arg_fmtconf[size]}" "$mountpoint"
fi
)
shellcheck:format