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
|
#! /bin/sh
IMG=$1
# get the last partition, incrment by 1 so we know where we start
LAST="$(sudo sgdisk -p $IMG |tail -1|sed 's/^[ \t]*//'|cut -d ' ' -f1)"
case $LAST in
[0-9]*)
LAST="$(($LAST + 1))"
;;
*)
LAST=1
;;
esac
oIFS=$IFS
IFS=,
cat parts.txt|while read name size type; do
echo $name
sudo sgdisk -a 1 -n 0:0:+$(($size*2)) $IMG
PNUM="$(sudo sgdisk -p $IMG |tail -1|sed 's/^[ \t]*//'|cut -d ' ' -f1)"
sudo sgdisk -c $PNUM:$name $IMG
sudo sgdisk -t $PNUM:$type $IMG
done
IFS=oIFS
|