-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·150 lines (132 loc) · 4.37 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
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
#!/usr/bin/env bash
set -e
arch="$1"
install_manager="yum"
linux_distro='fedora'
debian_version="${2:-buster}"
debian_variant="${3:-minbase}"
version=`cat VERSION`
echo "Starting build system for ${version}"
function check_args {
if [[ "$arch" == "" || "$debian_version" == "" ]]; then
echo "usage: $0 <cpu architecture> [debian version] [debian variant]"
exit 1
fi
}
function is_fedora {
if [[ "$linux_distro" == 'fedora' ]]; then
return 0;
fi;
return 1
}
function detect_os {
echo -n 'Detecting base Linux variant... '
if is_package_installed apt &>/dev/null; then
install_manager=apt
linux_distro='debian'
echo 'Debian'
else
echo 'Fedora'
fi;
}
function is_package_installed {
echo -n "Detecting if '$1' is installed... "
if which $1 &>/dev/null; then
echo "yes!"
return 0;
fi;
echo "no."
return 1;
}
function init_debootstrap {
if ! is_package_installed debootstrap; then
echo "Installing debootstrap..."
sudo $install_manager install -y debootstrap
fi;
}
function init_qemu_user_static {
if ! is_package_installed qemu-arm-static; then
echo "Installing qemu-user-static..."
sudo $install_manager install -y qemu-user-binfmt
sudo $install_manager install -y qemu-user-static
fi;
}
function init_docker {
pending_reboot=0
if ! is_package_installed docker; then
echo "Installing Docker..."
if is_fedora; then
sudo dnf -y install dnf-plugins-core
sudo dnf -y config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo sed -ie 's/$releasever/31/g' /etc/yum.repos.d/docker-ce.repo
sudo dnf -y install docker-ce docker-ce-cli containerd.io grubby
sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
sudo firewall-cmd --permanent --zone=trusted --add-interface=docker0
sudo firewall-cmd --permanent --zone=FedoraWorkstation --add-masquerade
sudo firewall-cmd --permanent --zone=trusted --add-interface=docker0
sudo firewall-cmd --permanent --zone=FedoraWorkstation --add-masquerade
sudo firewall-cmd --reload
pending_reboot=1
else
sudo apt update
sudo apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
fi;
echo -n "Enabling Docker... "
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker "$USER"
newgrp docker
echo "done."
if [[ $pending_reboot == 1 ]]; then
while true; do
read -p "Fedora requires a reboot after installing Docker for the first time. Would you like to reboot? (y|n): " yn
case $yn in
[Yy]* ) sudo reboot; break;;
[Nn]* ) echo "Please reboot before re-running this script"; exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fi
# docker login
}
function build_docker {
echo "Building Docker container... "
docker_versioned_tag="${arch}/embedci:${version}-${debian_version}-${debian_variant}"
docker_latest_tag="${arch}/embedci:latest-${debian_version}-${debian_variant}"
qemu_static="/usr/bin/qemu-arm-static"
case "$arch" in
armel|armhf) qemu_static="/usr/bin/qemu-arm-static";;
arm64) qemu_static="/usr/bin/qemu-aarch64-static";;
*) qemu_static="/usr/bin/qemu-${arch}-static";;
esac
qemu_static_basename=$(basename "$qemu_static")
cp "$qemu_static" .
docker build . \
-t "$docker_versioned_tag" \
-t "$docker_latest_tag" \
--build-arg "QEMU_STATIC=${qemu_static_basename}" \
--build-arg "ARCH=${arch}" \
--build-arg "DEBIAN_VERSION=${debian_version}" \
--build-arg "DEBIAN_VARIANT=${debian_variant}"
docker run -v "${qemu_static}:${qemu_static}" "$docker_versioned_tag" -c "uname -a"
echo "Successfully built container ${docker_latest_tag}!"
}
check_args
detect_os
init_debootstrap
init_qemu_user_static
init_docker
build_docker