Merge branch 'master' of ssh://apo.geoffray-levasseur.org/share/services/git/legos

This commit is contained in:
2022-02-18 14:03:19 +01:00
2 changed files with 78 additions and 46 deletions

View File

@@ -17,7 +17,14 @@ blank_disk()
prnt I "Wipping $1 drive signature (a backup is made in /root)..."
wipefs --force --all --backup /dev/$1
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
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()
{
# That technique is fast but might not be relayable enough if we are on
# exotic data structure or filesystem...
local devstat=$(file /dev/$1 | sed "s@/dev/$1: @@")
if [[ $devstat == 'data' ]]; then
return 0
if [[ -b /dev/$1 ]]; then
# That technique is fast but might not be relayable enough if we are on
# exotic data structure or filesystem...
local devstat=$(file /dev/$1 | sed "s@/dev/$1: @@")
if [[ $devstat == 'data' ]]; then
return 0
else
return 1
fi
else
return 1
return 2
fi
}