Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tristan Cavelier
toolbox
Commits
0f106c07
Commit
0f106c07
authored
8 years ago
by
Tristan Cavelier
Browse files
Options
Download
Email Patches
Plain Diff
add cros-safe-write.bash
parent
68456732
Pipeline
#4162
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
cros-safe-write.bash
cros-safe-write.bash
+37
-0
No files found.
cros-safe-write.bash
0 → 100644
View file @
0f106c07
#!/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
"
$@
"
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment