-
Notifications
You must be signed in to change notification settings - Fork 34
/
create-clover.sh
168 lines (141 loc) · 3.51 KB
/
create-clover.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
######################################################################
# defaults
iso=""
img=""
cfg=""
drv=""
######################################################################
# create work dir
function msg() {
local txt="$1"
local bold="\x1b[1m"
local normal="\x1b[0m"
echo -e "${bold}### ${txt}${normal}"
}
function do_cleanup() {
msg "cleaning up ..."
if test "$GUESTFISH_PID" != ""; then
guestfish --remote -- exit >/dev/null 2>&1 || true
fi
sudo rm -rf "$WORK"
}
WORK="${TMPDIR-/var/tmp}/${0##*/}-$$"
mkdir "$WORK" || exit 1
trap 'do_cleanup' EXIT
BASE="$(dirname $0)"
######################################################################
# parse args
function print_help() {
cat <<EOF
usage: $0 [ options ]
options:
--iso <iso-image>
--img <disk-image>
--cfg <clover-config>
--drv <extra-driver>
EOF
}
while test "$1" != ""; do
case "$1" in
--iso)
iso="$2"
shift; shift
;;
--img)
img="$2"
shift; shift
;;
--cfg)
cfg="$2"
shift; shift
;;
--drv)
drv="$drv $2"
shift; shift
;;
esac
done
######################################################################
# guestfish script helpers
function fish() {
echo "#" "$@"
guestfish --remote -- "$@" || exit 1
}
function fish_init() {
local format
case "$img" in
*.raw) format="raw" ;;
*) format="qcow2";;
esac
msg "creating and adding disk image"
fish disk-create $img $format 256M
fish add $img
fish run
}
function fish_fini() {
fish umount-all
}
######################################################################
# sanity checks
if test ! -f "$iso"; then
echo "ERROR: iso not found: $iso"
exit 1
fi
if test ! -f "$cfg"; then
echo "ERROR: cfg not found: $cfg"
exit 1
fi
if test -f "$img"; then
if test "$allow_override" = "yes"; then
rm -f "$img"
else
echo "ERROR: image exists: $img"
exit 1
fi
fi
######################################################################
# go!
msg "copy files from iso"
guestfish -a "$iso" -m "/dev/sda:/:norock" <<EOF || exit 1
copy-out /EFI $WORK
EOF
#msg "[debug] list drivers in EFI/CLOVER"
#(cd $WORK/EFI/CLOVER; find driver* -print)
export LIBGUESTFS_BACKEND=direct
eval $(guestfish --listen)
if test "$GUESTFISH_PID" = ""; then
echo "ERROR: starting guestfish failed"
exit 1
fi
fish_init
msg "partition disk image"
fish part-init /dev/sda gpt
fish part-add /dev/sda p 2048 200000
fish part-add /dev/sda p 202048 -2048
fish part-set-gpt-type /dev/sda 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B
fish part-set-bootable /dev/sda 1 true
fish mkfs vfat /dev/sda1 label:EFI
fish mkfs vfat /dev/sda2 label:clover
fish mount /dev/sda2 /
fish mkdir /ESP
fish mount /dev/sda1 /ESP
msg "copy files to disk image"
cp -v "$cfg" $WORK/config.plist
fish mkdir /ESP/EFI
fish mkdir /ESP/EFI/CLOVER
fish mkdir /ESP/EFI/CLOVER/kexts
fish mkdir /ESP/EFI/CLOVER/kexts/Other
fish mkdir /ESP/EFI/CLOVER/drivers
fish copy-in $WORK/EFI/BOOT /ESP/EFI
fish copy-in $WORK/EFI/CLOVER/CLOVERX64.efi /ESP/EFI/CLOVER
fish copy-in $WORK/EFI/CLOVER/drivers/UEFI /ESP/EFI/CLOVER/drivers
fish copy-in $WORK/EFI/CLOVER/tools /ESP/EFI/CLOVER
fish copy-in $WORK/config.plist /ESP/EFI/CLOVER
nodef="$WORK/EFI/CLOVER/drivers/off"
for file in $drv; do
echo "# -*- extra driver: $file -*-"
fish copy-in $file /ESP/EFI/CLOVER/drivers/UEFI
done
fish ls /ESP/EFI/CLOVER/drivers/UEFI
fish_fini