-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash-awk.sh
executable file
·59 lines (54 loc) · 1.76 KB
/
bash-awk.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
#!/bin/bash
#
# processSfdisk() processes the output of sfdisk -d
# and creates a new sfdisk -d like output, applying
# the requested action. Read below to see the actions
#
# $1 the name of a file that is the output of sfdisk -d
# $2 is the action "resize|other?"
# $3 is the first parameter
# $4 is the second parameter
# ...
#
# actions:
# processSfdisk foo.sfdisk resize /dev/sda1 100000
# foo.sfdisk = sfdisk -d output
# resize = action
# /dev/sda1 = partition to modify
# 100000 = 1024 byte blocks size to make it
# output: new sfdisk -d like output
#
# processSfdisk foo.sfdisk move /dev/sda1 100000
# foo.sfdisk = sfdisk -d output
# move = action
# /dev/sda1 = partition to modify
# 100000 = 1024 byte blocks size to move it to
# output: new sfdisk -d like output
#
# processSfdisk foo.sfdisk filldisk /dev/sda 100000 1:3:6
# foo.sfdisk = sfdisk -d output
# filldisk = action
# /dev/sda = disk to modify
# 100000 = 1024 byte blocks size of disk
# 1:3:6 = partition numbers that are fixed in size, : separated
# output: new sfdisk -d like output
#
# example file data
# /dev/sda1 : start= 2048, size= 204800, Id= 7, bootable
# /dev/sda2 : start= 206848, size= 50573312, Id= 7
# /dev/sda3 : start= 50780160, size= 2048, Id=83
# /dev/sda4 : start= 50784254, size= 16322562, Id= 5
# /dev/sda5 : start= 50784256, size= 7811072, Id=83
# /dev/sda6 : start= 58597376, size= 8509440, Id=82
#
data=$1
minstart=`awk -F'[ ,]+' '/start/{if ($4) print $4}' $data | sort -n | head -1`;
chunksize="2048";
awkArgs="-v CHUNKSIZE=$chunksize -v MIN_START=$minstart"
awkArgs="${awkArgs} -v action=$2 -v target=$3 -v sizePos=$4"
# Optional argument
if [ -n "$5" ]; then
awkArgs="${awkArgs} -v fixedList=$5"
fi
# Process with external awk script
/usr/share/fog/lib/procsfdisk.awk $awkArgs $data