-
Notifications
You must be signed in to change notification settings - Fork 0
/
img2iso.sh
executable file
·56 lines (49 loc) · 1.22 KB
/
img2iso.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
input=$1
stripped=${input%.*}
filename=${stripped##*/}
cwd=$(pwd)
echo -ne "\033]0;IMG 2 ISO\007"
Output() {
echo "$(date -d "1970-01-01 UTC $2 seconds") - $1"
}
Duration() {
local S=$(echo $FINISH_TIME $BEGIN_TIME | awk '{print$1-$2}')
((h=S/3600))
((m=S%3600/60))
((s=S%60))
printf "Conversion took: %dh:%dm:%ds\n" $h $m $s
}
Begin() {
BEGIN_TIME=$(date +%s)
Output Begin $BEGIN_TIME "$1"
}
Finish() {
FINISH_TIME=$(date +%s)
Output Finished $FINISH_TIME "$1"
Duration
}
echo "Converting $filename.img to $filename.iso"
echo ""
Begin
echo ""
iat --input="$1" --output=$filename.iso --iso
echo ""
Finish
filesizein=$(stat -c%s "$1")
filesizeout=$(stat -c%s $cwd/$filename.iso)
echo ""
echo "Size of $filename.img = $filesizein bytes."
echo "Size of $filename.iso = $filesizeout bytes."
echo ""
echo "Would you like to delete the original file?"
prompt='Press [Y] to delete it, or [N] to quit without deleting it.'
echo -n "$prompt"
echo ""
read -n1 char
case "$char" in
[Nn]) echo "" && read -p "Press [Enter] to continue." ;;
[Yy]) rm $1 && echo "" && echo "$1 deleted" && echo "" && read -p "Press [Enter] to continue." ;;
esac
fi
read -p "Press [Enter] to continue."