confz

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

commit 9ef38040cc5917c2f274cf48733f13502b99fa21
parent c5498d9408169bef84899e53beab733a097adde4
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Sat, 18 Nov 2017 23:36:28 +0100

Find disks by IDs
Diffstat:
Mzsh-functions/confz_fs_init | 45+++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+), 0 deletions(-)

diff --git a/zsh-functions/confz_fs_init b/zsh-functions/confz_fs_init @@ -4,6 +4,20 @@ # confz functions for dealing with filesystem and mounting # +# smartctl -i /dev/sda | while IFS=':' read foo bar; do P '***' ${${foo:l}// /_} ${bar/# #}; done + +fs_smartctl_probe() { + (($+smartctl_probed)) && (($smartctl_probed) && return 0 + local dev item val rest + typeset -g smartctl_probed + typeset -ga smartctl_devices + typeset -gA smartctl_info + smartctl --scan | while read dev rest; do + smartctl_devices+=( $dev ) + smartctl -i $dev | while IFS=':' read item val; do smartctl_info[${dev}:${${item:l}// /_}]=${val/# #}; done + done + smartctl_probed=1 +} # helper for probing devices fs_blkid_probe() { @@ -100,6 +114,37 @@ fs_parted_list() { done <<<"$out" } +# Find disks by their IDs +confz_disk_id_check() { + # arguments: device device_model serial_number + if ! (($+vars[device] + $+vars[device_model] + $+vars[serial_number])); then + die "$0: requires one or more arguments: device device_model serial_number" + fi + + do_command=( true ) + fs_smartctl_probe + local device + local -a found + + for device in $smartctl_devices; do + if (($+vars[device])); then + [[ $vars[device] != $device]] && continue + fi + if (($+vars[device_model])); then + [[ $vars[device_model] != $smartctl_info[${device}:device_model] ]] && continue + fi + if (($+vars[serial_number])); then + [[ $vars[serial_number] != $smartctl_info[${device}:serial_number] ]] && continue + fi + found+=( $device $smartctl_info[${device}:device_model] $smartctl_info[${device}:serial_number] ) + done + + (( $#found )) || die "$0: found no matching devices" + [[ $#found != 3 ]] || die "$0: found too many matching devices" + vars[device]=$found[0] + vars[device_model]=$found[1] + vars[serial_number]=$found[2] +} # check for DOS-style MBR on device confz_disklabel_dos_check() {