-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdisk-automation.sh
67 lines (59 loc) · 2.85 KB
/
fdisk-automation.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
#!/bin/bash
# BASIC DIRECTORIES, VARIABLES AND PACKAGES
source .env
source Fdisk-lib.sh
install_parted
mkdir -p $tmp_dir 2> /dev/null
# MAIN SECTION ############################################################################################
purify_inputfile
array_them
nop=0
for ((i=0; $nop < $nl; )) # $i will always be the working row (=being processed partition)
do
# Basically the for loop is in charge of choosing disks.
# and while loop works the partiotions on it
PA=$(echo ${array1[$nop]})
find_nop # we find the value of nop here because we want $i to go on untill
# we get to the next PA -untill we are finished with the current PA
counter=0
# this is used for gpt. because when we use "g" in fdisk it'll delete
# the already existing partitions and is only used when initializing.
while [ $i -lt $nop ]
do
case ${array2[$i]} in
gpt)
if [ $counter = 0 ]
then
init_partitioning_gpt
format_it
mkdir_mnt
update_fstab
((counter++))
else
continue_partitioning_gpt
format_it
mkdir_mnt
update_fstab
fi
;;
mbr)
partitioning_mbr
format_it
mkdir_mnt
update_fstab
;;
*)
echo "none"
;;
esac
((i++))
done
done
report
# END #####################################################################################################
# Here's some explanation about the script:
# The loop above will deal with the input file as multiple groups of rows. It works like this: each
# group is defined based on physical addr. The "find_nop" function is in charge of that. It'll find the
# first PA, calculates how many partitions will be put into this disk, and simply spots the next PA.
# The index $i, which specifies the current, row will be incremented untill its value reaches $nop
# then it's time to work on the next PA; so $nop gets calculated and $i will try to reach its value again.