-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
63 lines (54 loc) · 1.66 KB
/
build.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
#!/bin/bash
# Mode to build, using "jokes" as default
export DADJOKES_MODE="${DADJOKES_MODE:-jokes}"
echo "Building image in '${DADJOKES_MODE}' mode"
# Whether to enable USB networking interface in RPi Image for debugging
echo "Enabling debug mode: ${PI_DEBUG:-false}"
#
# Setup ARM emulation and packer
#
PACKER_VERSION="1.7.4"
# Update the system
echo "Updating Vagrant box..."
sudo apt-get update &>/dev/null
sudo apt-get -y upgrade &>/dev/null
sudo apt-get -y autoremove &>/dev/null
sudo apt-get clean
# Install required packages
echo "Installing build tools..."
sudo apt-get install -y \
qemu-user-static \
e2fsprogs \
parted \
qemu-utils \
ca-certificates \
dosfstools \
gdisk \
kpartx \
libarchive-tools \
git \
golang-go \
unzip &>/dev/null
sudo apt-get clean
# Download and install packer
command -v packer >/dev/null 2>&1 || {
echo "Installing packer..."
wget -q https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip -O /tmp/packer.zip &>/dev/null
sudo unzip /tmp/packer.zip -d /bin &>/dev/null
rm /tmp/packer.zip
}
# Download and build packer-builder-arm
if [ ! -f /vagrant/packer-builder-arm ]; then
echo "Installing packer-builder-arm provisioner..."
git clone https://github.com/mkaczanowski/packer-builder-arm &>/dev/null
cd packer-builder-arm
go mod download &>/dev/null
go build &>/dev/null
cp packer-builder-arm /vagrant/
fi
# Build
cd /vagrant
echo "Building image..."
host raspbian.raspberrypi.org &>/dev/null # ensure updates will work
host archive.raspberrypi.org &>/dev/null # ensure updates will work
sudo PI_DEBUG=$PI_DEBUG DADJOKES_MODE=$DADJOKES_MODE packer build packer.json