Commit 0f106c07 authored by Tristan Cavelier's avatar Tristan Cavelier

add cros-safe-write.bash

parent 68456732
Pipeline #4162 skipped
#!/bin/bash
# Copy stdin to a file
cmd=$(basename "$0")
usage="Usage: $cmd DST < SRC
Where DST is the destination file
Copy stdin to DST. Data is flushed regularly to avoid some eventual crash during cache sync.
Example:
gunzip myimage.img.gz -c | sudo bash $cmd /dev/sda"
KiB=1024
MiB=$((1024 * $KiB))
bs=4096
count=$((50 * $MiB / $bs))
infostep=50
infounit=MiB
cooldd() {
local _cooldd_out
local _cooldd_length=$infostep
[ $# = 1 ] || { echo "$usage" >&2 ; return 2 ; }
[ $1 != - ] || { echo "DST should not be '-'" >&2 ; return 2 ; }
while [ $? = 0 ] ; do
echo "+ copying until $_cooldd_length $infounit"
_cooldd_length=$(($_cooldd_length + $infostep))
_cooldd_out=$(dd bs=$bs count=$count of="$1" 2>&1) || { echo "$_cooldd_out" ; return 1 ; }
echo "$_cooldd_out"
! echo "$_cooldd_out" | grep '(0 B) copied' > /dev/null
done
return 0
}
cooldd "$@"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment