diskman.sh: small improvements

This commit is contained in:
levasseur
2022-02-11 18:46:16 +01:00
parent cc36f50279
commit 77b51a2702

View File

@@ -13,11 +13,18 @@
# Blank the given disks # Blank the given disks
blank_disk() blank_disk()
{ {
if [[ $(test -b /dev/$1) ]]; then if [[ -b /dev/$1 ]]; then
prnt I "Wipping $1 drive signature (a backup is made in /root)..." prnt I "Wipping $1 drive signature (a backup is made in /root)..."
wipefs --force --all --backup /dev/$1 wipefs --force --all --backup /dev/$1
prnt I "Filling beginning of $1 drive with zeroes..." prnt I "Filling beginning of $1 drive with zeroes..."
dd if="/dev/zero" of="$1" bs="512" count="1024" if [[ $2 == "--full" ]]; then
# If full we display progress as it might take a very long time
# Need true to avoid error as the last byte will generate a disk
# full error
dd if="/dev/zero" of="$1" bs="512" status=progress || true
else
dd if="/dev/zero" of="$1" bs="512" count="1024"
fi
# Update kernel partition scheme # Update kernel partition scheme
partprobe partprobe
@@ -29,16 +36,23 @@ blank_disk()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Check if $1 is a block device and if it's blank # Check if $1 is a blank block device. Return values:
# * 0 if empty block device
# * 1 if not empty block device
# * 2 if not block device or if it don't exists
is_blank() is_blank()
{ {
# That technique is fast but might not be relayable enough if we are on if [[ -b /dev/$1 ]]; then
# exotic data structure or filesystem... # That technique is fast but might not be relayable enough if we are on
local devstat=$(file /dev/$1 | sed "s@/dev/$1: @@") # exotic data structure or filesystem...
if [[ $devstat == 'data' ]]; then local devstat=$(file /dev/$1 | sed "s@/dev/$1: @@")
return 0 if [[ $devstat == 'data' ]]; then
return 0
else
return 1
fi
else else
return 1 return 2
fi fi
} }