diff --git a/lib/diskman.sh b/lib/diskman.sh index 2e5374e..02fc9f9 100644 --- a/lib/diskman.sh +++ b/lib/diskman.sh @@ -13,11 +13,18 @@ # Blank the given disks 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)..." 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 }