aboutsummaryrefslogtreecommitdiff
path: root/scripts/bootusb
blob: eb648a87a9e33e62a06f7ba5e8dd21f21904b47c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash

if [ $# -ne 2 ]
then
	echo Usage: $0 SOURCE SINK
	exit 1
fi

if [ ! -e $1 -o ! -e $2 ]
then
	echo "Filename(s) invalid."
	exit 2
fi

if grep $2 /etc/mtab > /dev/null
then
	echo Device is mounted. Aborting
	exit 3
fi

read -p "Writing $1 to $2. Continue? (y/N)" cont
case $cont in
	[yY]);;
	*)
		echo Aborting.
		exit 4;;
esac

sudo -v

FILESIZE=$(du -b $1 | cut -f 1)
BLOCKSIZE=$(sudo blockdev --getsize64 $2)

if [ $FILESIZE -gt $BLOCKSIZE ]
then
	echo $1 is too large for $2.
	exit 5
fi

echo Writing $FILESIZE Bytes to $2

dd iflag=direct if=$1 2>/dev/null | pv --size $FILESIZE | sudo dd bs=4K oflag=direct of=$2 2>/dev/null

exit 0