-
Notifications
You must be signed in to change notification settings - Fork 1
/
imgkreator.sh
executable file
·105 lines (92 loc) · 2.22 KB
/
imgkreator.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#This script was written by:
# _ _
#| \ | |
#| \| | __ _ _ __ __ _ _ __ ___ _ __
#| . ` |/ _` | '__/ _` | '__/ _ \ '_ \
#| |\ | (_| | | | (_| | | | __/ | | |
#\_| \_/\__,_|_| \__, |_| \___|_| |_|
# __/ |
# |___/
# 13 oct, 2012
# Script to create .img files
# Nargren | ubuntuhak.blogspot.com
#The script creates an empty img file with the specified filename, size and filesystem
#Output file name is <givenname>.img
#Defining functions
function main {
echo "Specify Filesystem to be used:"
echo "1. Fat32"
echo "2. NTFS"
echo "3. Ext2"
echo "4. Ext3"
echo "5. Ext4"
read choice
if [ $choice -le 5 ] && [ $choice -ge 0 ]; then
if [ $choice -eq 1 ]; then
filetype=Fat32
sudo dd if=/dev/zero of=$imgname bs=1M count=$size
sudo mkfs fat32 -F $imgname
fi
if [ $choice -eq 2 ]; then
filetype=NTFS
sudo dd if=/dev/zero of=$imgname bs=1M count=$size
sudo mkfs ntfs -F $imgname
fi
if [ $choice -eq 3 ]; then
filetype=Ext2
sudo dd if=/dev/zero of=$imgname bs=1M count=$size
sudo mkfs ext2 -F $imgname
fi
if [ $choice -eq 4 ]; then
filetype=Ext3
sudo dd if=/dev/zero of=$imgname bs=1M count=$size
sudo mkfs ext3 -F $imgname
fi
if [ $choice -eq 5 ]; then
filetype=Ext4
sudo dd if=/dev/zero of=$imgname bs=1M count=$size
sudo mkfs ext4 -F $imgname
fi
else
echo "PEBKAC"
echo ""
main
fi
}
function existence {
imgname=$name.img
if [ -e $imgname ]; then
echo "$(tput setaf 1)Warning$(tput sgr0) : File '$name' already exists!"
function decision {
echo "Overwrite? (Y/N)"
read answer
if [ $answer == n ] || [ $answer == N ]; then
echo "Please choose another name:"
read name
existence
elif [ $answer == y ] || [ $answer == Y ]; then
echo "Overwriting '$name'..."
else
echo "Try again."
decision
fi
}
decision
else
echo ""
fi
}
#Main
echo "Welcome to imgKreator!"
echo ""
echo "Specify output filename:"
read name
existence
echo ""
echo "Specify size of '$imgname' (MB):"
read size
echo ""
main
sudo chmod 777 $imgname
echo "$(tput bold)$(tput setaf 4)Img container $imgname ($size MB) was successfully created and formatted to $filetype $(tput sgr0)"