-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage-macos.sh
42 lines (34 loc) · 852 Bytes
/
image-macos.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
#!/bin/bash
set -e
if [[ $(id -u) -ne 0 ]]; then
echo "run as root"
exit 1
fi
GRUB_INSTALL=grub-install
if ! command -v grub-install &> /dev/null; then
GRUB_INSTALL=grub2-install
fi
image=boot.img
#rm -f $image
#truncate -s 128M $image
#fdisk -i -a dos $image
loop_device="$(hdiutil attach -nomount $image | head -n1 | cut -d " " -f1)"
loop_part=${loop_device}s1
mkfs.vfat -F32 $loop_part
mkdir -p mountdir
mount -t msdos $loop_part mountdir
cd mountdir
cp -r ../base_image/* .
${GRUB_INSTALL} --modules=part_msdos --locales="" --themes="" --target=i386-pc --boot-directory="./boot" ../$image
if [ $GRUB_INSTALL = "grub2-install" ]; then
mv boot/grub/* boot/grub2/
rm -rf boot/grub
fi
cd ..
umount mountdir
sync
rm -rf mountdir
hdiutil detach $loop_device
if [[ -n $SUDO_UID ]]; then
chown $SUDO_UID:$SUDO_GID $image
fi