Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tristan Cavelier
toolbox
Commits
0f106c07
Commit
0f106c07
authored
Dec 08, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
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
"
$@
"
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