-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vagrant-build
executable file
·101 lines (83 loc) · 3.07 KB
/
vagrant-build
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
#!/bin/bash -xe
IMAGE_NAME="patchOS-rpi4.img"
ARCH_LINUX_TARBALL="ArchLinuxARM-rpi-4-aarch64-2020-05-06.tar.gz"
cd /home/vagrant
# Clean up existing build
echo "[ STARTED ] Cleaning up existing build"
sudo rm -Rf tmp
mkdir tmp
cd tmp
echo "[ FINISHED ] Cleaning up existing build"
# Create empty image file
echo "[ STARTED ] Creating empty image file"
fallocate -l 4G ${IMAGE_NAME}
DRIVE=$(sudo losetup --partscan --find --show ${IMAGE_NAME})
echo "[ FINISHED ] Creating empty image file"
# Partition
echo "[ STARTED ] Partinioning"
sudo parted --script ${DRIVE} mklabel msdos
sudo parted --script ${DRIVE} mkpart primary fat32 0% 100M
sudo parted --script ${DRIVE} mkpart primary ext4 100M 100%
echo "[ FINISHED ] Partinioning"
# Format
echo "[ STARTED ] Formatting"
sudo mkfs.vfat -F32 ${DRIVE}p1
sudo mkfs.ext4 -F ${DRIVE}p2
echo "[ FINISHED ] Formatting"
# Mount partitions
echo "[ STARTED ] Mounting partitions"
sudo mount ${DRIVE}p2 /mnt
sudo mkdir /mnt/boot
sudo mount ${DRIVE}p1 /mnt/boot
echo "[ FINISHED ] mounting partitions"
# Download Arch Linux ARM
echo "[ STARTED ] Downloading Arch Linux ARM"
wget https://olegtown.pw/Public/ArchLinuxArm/RPi4/rootfs/${ARCH_LINUX_TARBALL}
echo "[ FINISHED ] Downloading Arch Linux ARM"
# Extract Arch Linux ARM to /mnt
echo "[ STARTED ] Extracting Arch Linux ARM"
sudo tar -xpf "${ARCH_LINUX_TARBALL}" -C /mnt
echo "[ FINISHED ] Extracting Arch Linux ARM"
# Enable ARM execution on x86_64
echo "[ STARTED ] Enabling ARM execution on x86_64"
sudo cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/
echo "[ FINISHED ] Enabling ARM execution on x86_64"
# Copy patchOS to Arch Linux ARM
echo "[ STARTED ] Copying patchOS to Arch Linux ARM"
sudo cp /vagrant/build /mnt/usr/bin
sudo rsync -a --exclude='.git' --exclude='release' /vagrant/ /mnt/patchOS
echo "[ FINISHED ] Copying patchOS to Arch Linux ARM"
# Chroot into Arch Linux ARM
echo "[ STARTED ] Setting up patchOS"
sudo systemctl restart systemd-binfmt.service
sudo systemd-nspawn -D /mnt usr/bin/build
echo "[ FINISHED ] Setting up patchOS"
# Build kernel if not built before
if [ ! -d /home/vagrant/linux ]; then
echo "[ STARTED ] Building kernel"
/vagrant/kernel-build
echo "[ FINISHED] Building kernel"
fi
# Install kernel
echo "[ STARTED ] Installing kernel"
sudo cp /home/vagrant/linux/arch/arm64/boot/Image /mnt/boot/kernel8.img
sudo cp /home/vagrant/linux/arch/arm64/boot/dts/broadcom/*.dtb /mnt/boot/
sudo cp /home/vagrant/linux/arch/arm64/boot/dts/overlays/*.dtb* /mnt/boot/overlays/
sudo cp /home/vagrant/linux/arch/arm64/boot/dts/overlays/README /mnt/boot/overlays/
echo "[ FINISHED ] Installing kernel"
# Cleanup
echo "[ STARTED ] Cleaning up"
sudo umount /mnt/boot
sudo umount /mnt
sudo losetup --detach "${DRIVE}"
echo "[ FINISHED ] Cleaning up"
# Shrink image
echo "[ STARTED ] Shrinking image"
cd /home/vagrant/tmp
sudo pishrink.sh -s patchOS-rpi4.img
echo "[ FINISHED ] Shrinking image"
# Copy image to build directory
echo "[ STARTED ] Copying image to release directory"
mkdir -p /vagrant/release
cp patchOS-rpi4.* /vagrant/release
echo "[ FINISHED ] Copying image to release directory"