confz

git mirror of https://ccx.te2000.cz/bzr/confz
git clone https://ccx.te2000.cz/git/confz
Log | Files | Refs

commit 8e680e277466189fdcda4a9b4ae447d60dfc6eeb
parent d69418dfc45c813806000d115016269402f5319b
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Mon, 17 Sep 2018 19:05:56 +0200

Prevent output from busybox blkid in incorrect format to be misinterpreted, simplify filesystem creation code.
Diffstat:
Mzsh-functions/confz_fs_init | 24+++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/zsh-functions/confz_fs_init b/zsh-functions/confz_fs_init @@ -37,6 +37,7 @@ fs_blkid_probe() { case $fs_blkid_result in (2);; (0) while IFS='=' read key val; do + [[ $key == *' '* ]] && die "Malformed blkid output for \"export\" format." fs_blkid_output[$key]=$val done <<<$out;; (*) die "blkid probe failed on device: ${(qqq)1}" @@ -567,24 +568,25 @@ confz_filesystem_check() { [[ -n $vars[mkfs_opts] ]] && do_command+=( "${(Q@)${(z)vars[mkfs_opts]}}" ) do_command+=( ${vars[device]} ) - local tries blk_out DEVNAME LABEL UUID TYPE SEC_TYPE PARTLABEL PARTUUID + local tries # blk_out DEVNAME LABEL UUID TYPE SEC_TYPE PARTLABEL PARTUUID tries=10 while ((tries)); do - blk_out=$(blkid -o export ${vars[device]}) - case $? in - (0) break;; - (2) ;; - (*) die "$0: error $? from blkid";; - esac + fs_blkid_probe $vars[device] + [[ $fs_blkid_result == 0 ]] && break;; tries=$[$tries - 1] done fail_reason="no blkid signature found on $vars[device]" - [[ -z $blk_out ]] && return 1 # nothing found on the device - eval $blk_out - [[ $LABEL == ${vars[label]} && $TYPE == $vars[filesystem] ]] && return 0 - [[ -z $TYPE && -z $LABEL && -z $UUID ]] && return 1 + # Check if anything was detected at all + (( $#fs_blkid_output )) || return 1 + + # Check if it is a filesystem + [[ -z ${fs_blkid_output[TYPE]:-} && -z ${fs_blkid_output[LABEL]:-} && -z ${fs_blkid_output[UUID]:-} ]] && return 1 + + # Check if it matches requirements + [[ ${fs_blkid_output[LABEL]:-} == ${vars[label]:-} && $fs_blkid_output[TYPE] == $vars[filesystem] ]] && return 0 + die "$0: filesystem already present on ${(qqq)vars[device]}!" }