-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiskFormatter.sh
More file actions
91 lines (76 loc) · 1.62 KB
/
diskFormatter.sh
File metadata and controls
91 lines (76 loc) · 1.62 KB
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
#!/bin/bash
#AUTHOR: AlphanetEX, disk formatter automatization v0.1.2
unset dec hex alphabet
unset fdisk_raid_cmd fdisk_lvm_cmd madnm_cmd
#MDADM SECTOR
fdisk_raid_cmd="n
p
#\n
#\n
#\n
t
fd
w
q"
fdisk_lvm_cmd="n
p
#\n
#\n
#\n
t
8e
w
q"
madnm_cmd="#\n
y
"
val_existence(){
if [[ -e "/dev/xvd$1" ]]; then
echo true
else
echo "the /dev/xvd$1 was not found \n"
fi
}
Disk_formatter(){
dec=98 #equivale a valor ascii de b
counter=0
counter_disk=0
cant=$1
receptor=$2
if ! [[ $1 && $2 != "" ]]; then
read -p "Cantidad de discos a Formatear ?: " cant
read -p "Opcion de formateo (RAID)=1, (LVM=2), (Default EXT 4): " receptor
fi
while [ $counter -lt $cant ]
do
hex=$(printf "%x\n" $dec);
alphabet=$(printf "\x$hex");
validator=$(val_existence $alphabet);
if [[ $validator == true ]]; then
#RAID1
if [[ $receptor == 1 ]]; then
sudo -S sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' <<< $fdisk_raid_cmd | sudo -S fdisk /dev/xvd$alphabet >> disk_formatter.log 2<&1
((counter ++));
((dec ++));
#LVM
elif [[ $receptor == 2 ]]; then
sudo -S sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' <<< $fdisk_lvm_cmd | sudo -S fdisk /dev/xvd$alphabet >> disk_formatter.log 2<&1
((counter ++));
((dec ++));
else
#DEFAULT EXT4
sudo -S mkfs.ext4 /dev/xvd$alphabet >> fdisk.log 2<&1
((counter ++));
((dec ++))
fi
else
printf "$validator"
((counter ++));
((dec ++));
fi
done
}
main(){
Disk_formatter $1 $2
}
main $1 $2