##// END OF EJS Templates
better apt-chacher-ng detection and correction apt_proxy
Unknown -
r434:bfa952727903
parent child
Show More
@@ -1,788 +1,788
1 #!/bin/sh
1 #!/bin/sh
2 ########################################################################
2 ########################################################################
3 # rpi23-gen-image.sh 2015-2017
3 # rpi23-gen-image.sh 2015-2017
4 #
4 #
5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
6 #
6 #
7 # This program is free software; you can redistribute it and/or
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (at your option) any later version.
10 # of the License, or (at your option) any later version.
11 #
11 #
12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 #
13 #
14 # Big thanks for patches and enhancements by 20+ github contributors!
14 # Big thanks for patches and enhancements by 20+ github contributors!
15 ########################################################################
15 ########################################################################
16
16
17 # Are we running as root?
17 # Are we running as root?
18 if [ "$(id -u)" -ne "0" ] ; then
18 if [ "$(id -u)" -ne "0" ] ; then
19 echo "error: this script must be executed with root privileges!"
19 echo "error: this script must be executed with root privileges!"
20 exit 1
20 exit 1
21 fi
21 fi
22
22
23 # Check if ./functions.sh script exists
23 # Check if ./functions.sh script exists
24 if [ ! -r "./functions.sh" ] ; then
24 if [ ! -r "./functions.sh" ] ; then
25 echo "error: './functions.sh' required script not found!"
25 echo "error: './functions.sh' required script not found!"
26 exit 1
26 exit 1
27 fi
27 fi
28
28
29 # Load utility functions
29 # Load utility functions
30 . ./functions.sh
30 . ./functions.sh
31
31
32 # Load parameters from configuration template file
32 # Load parameters from configuration template file
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
33 if [ -n "$CONFIG_TEMPLATE" ] ; then
34 use_template
34 use_template
35 fi
35 fi
36
36
37 # Introduce settings
37 # Introduce settings
38 set -e
38 set -e
39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
40 set -x
40 set -x
41
41
42 # Raspberry Pi model configuration
42 # Raspberry Pi model configuration
43 RPI_MODEL=${RPI_MODEL:=2}
43 RPI_MODEL=${RPI_MODEL:=2}
44
44
45 # Debian release
45 # Debian release
46 RELEASE=${RELEASE:=buster}
46 RELEASE=${RELEASE:=buster}
47
47
48 # Kernel Branch
48 # Kernel Branch
49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
49 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
50
50
51 # URLs
51 # URLs
52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
58 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
58 VIDEOCORE_URL=${VIDEOCORE_URL:=https://github.com/raspberrypi/userland}
59 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
59 BLUETOOTH_URL=${BLUETOOTH_URL:=https://github.com/RPi-Distro/pi-bluetooth.git}
60
60
61 # Build directories
61 # Build directories
62 WORKDIR=$(pwd)
62 WORKDIR=$(pwd)
63 BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}}
63 BASEDIR=${BASEDIR:=${WORKDIR}/images/${RELEASE}}
64 BUILDDIR="${BASEDIR}/build"
64 BUILDDIR="${BASEDIR}/build"
65
65
66 # Chroot directories
66 # Chroot directories
67 R="${BUILDDIR}/chroot"
67 R="${BUILDDIR}/chroot"
68 ETC_DIR="${R}/etc"
68 ETC_DIR="${R}/etc"
69 LIB_DIR="${R}/lib"
69 LIB_DIR="${R}/lib"
70 BOOT_DIR="${R}/boot/firmware"
70 BOOT_DIR="${R}/boot/firmware"
71 KERNEL_DIR="${R}/usr/src/linux"
71 KERNEL_DIR="${R}/usr/src/linux"
72 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
72 WLAN_FIRMWARE_DIR="${LIB_DIR}/firmware/brcm"
73
73
74 # Firmware directory: Blank if download from github
74 # Firmware directory: Blank if download from github
75 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
75 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
76
76
77 # General settings
77 # General settings
78 SET_ARCH=${SET_ARCH:=32}
78 SET_ARCH=${SET_ARCH:=32}
79 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
79 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
80 PASSWORD=${PASSWORD:=raspberry}
80 PASSWORD=${PASSWORD:=raspberry}
81 USER_PASSWORD=${USER_PASSWORD:=raspberry}
81 USER_PASSWORD=${USER_PASSWORD:=raspberry}
82 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
82 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
83 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
83 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
84 EXPANDROOT=${EXPANDROOT:=true}
84 EXPANDROOT=${EXPANDROOT:=true}
85
85
86 # Keyboard settings
86 # Keyboard settings
87 XKB_MODEL=${XKB_MODEL:=""}
87 XKB_MODEL=${XKB_MODEL:=""}
88 XKB_LAYOUT=${XKB_LAYOUT:=""}
88 XKB_LAYOUT=${XKB_LAYOUT:=""}
89 XKB_VARIANT=${XKB_VARIANT:=""}
89 XKB_VARIANT=${XKB_VARIANT:=""}
90 XKB_OPTIONS=${XKB_OPTIONS:=""}
90 XKB_OPTIONS=${XKB_OPTIONS:=""}
91
91
92 # Network settings (DHCP)
92 # Network settings (DHCP)
93 ENABLE_DHCP=${ENABLE_DHCP:=true}
93 ENABLE_DHCP=${ENABLE_DHCP:=true}
94
94
95 # Network settings (static)
95 # Network settings (static)
96 NET_ADDRESS=${NET_ADDRESS:=""}
96 NET_ADDRESS=${NET_ADDRESS:=""}
97 NET_GATEWAY=${NET_GATEWAY:=""}
97 NET_GATEWAY=${NET_GATEWAY:=""}
98 NET_DNS_1=${NET_DNS_1:=""}
98 NET_DNS_1=${NET_DNS_1:=""}
99 NET_DNS_2=${NET_DNS_2:=""}
99 NET_DNS_2=${NET_DNS_2:=""}
100 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
100 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
101 NET_NTP_1=${NET_NTP_1:=""}
101 NET_NTP_1=${NET_NTP_1:=""}
102 NET_NTP_2=${NET_NTP_2:=""}
102 NET_NTP_2=${NET_NTP_2:=""}
103
103
104 # APT settings
104 # APT settings
105 APT_PROXY=${APT_PROXY:=""}
105 APT_PROXY=${APT_PROXY:=""}
106 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
106 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
107
107
108 # Feature settings
108 # Feature settings
109 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
109 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
110 ENABLE_I2C=${ENABLE_I2C:=false}
110 ENABLE_I2C=${ENABLE_I2C:=false}
111 ENABLE_SPI=${ENABLE_SPI:=false}
111 ENABLE_SPI=${ENABLE_SPI:=false}
112 ENABLE_IPV6=${ENABLE_IPV6:=true}
112 ENABLE_IPV6=${ENABLE_IPV6:=true}
113 ENABLE_SSHD=${ENABLE_SSHD:=true}
113 ENABLE_SSHD=${ENABLE_SSHD:=true}
114 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
114 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
115 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
115 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
116 ENABLE_SOUND=${ENABLE_SOUND:=true}
116 ENABLE_SOUND=${ENABLE_SOUND:=true}
117 ENABLE_DBUS=${ENABLE_DBUS:=true}
117 ENABLE_DBUS=${ENABLE_DBUS:=true}
118 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
118 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
119 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
119 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
120 ENABLE_XORG=${ENABLE_XORG:=false}
120 ENABLE_XORG=${ENABLE_XORG:=false}
121 ENABLE_WM=${ENABLE_WM:=""}
121 ENABLE_WM=${ENABLE_WM:=""}
122 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
122 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
123 ENABLE_USER=${ENABLE_USER:=true}
123 ENABLE_USER=${ENABLE_USER:=true}
124 USER_NAME=${USER_NAME:="pi"}
124 USER_NAME=${USER_NAME:="pi"}
125 ENABLE_ROOT=${ENABLE_ROOT:=false}
125 ENABLE_ROOT=${ENABLE_ROOT:=false}
126 ENABLE_QEMU=${ENABLE_QEMU:=false}
126 ENABLE_QEMU=${ENABLE_QEMU:=false}
127 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
127 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
128
128
129 # SSH settings
129 # SSH settings
130 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
130 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
131 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
131 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
132 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
132 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
133 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
133 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
134 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
134 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
135
135
136 # Advanced settings
136 # Advanced settings
137 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
137 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
138 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
138 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
139 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
139 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
140 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
140 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
141 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
141 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
142 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false}
142 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=false}
143 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
143 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
144 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
144 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
145 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
145 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
146 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
146 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
147 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
147 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
148 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
148 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
149 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
149 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
150 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
150 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
151
151
152 # Kernel compilation settings
152 # Kernel compilation settings
153 BUILD_KERNEL=${BUILD_KERNEL:=true}
153 BUILD_KERNEL=${BUILD_KERNEL:=true}
154 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
154 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
155 KERNEL_THREADS=${KERNEL_THREADS:=1}
155 KERNEL_THREADS=${KERNEL_THREADS:=1}
156 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
156 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
157 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
157 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
158 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
158 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
159 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
159 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
160 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
160 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
161
161
162 # Kernel compilation from source directory settings
162 # Kernel compilation from source directory settings
163 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
163 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
164 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
164 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
165 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
165 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
166 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
166 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
167
167
168 # Reduce disk usage settings
168 # Reduce disk usage settings
169 REDUCE_APT=${REDUCE_APT:=true}
169 REDUCE_APT=${REDUCE_APT:=true}
170 REDUCE_DOC=${REDUCE_DOC:=true}
170 REDUCE_DOC=${REDUCE_DOC:=true}
171 REDUCE_MAN=${REDUCE_MAN:=true}
171 REDUCE_MAN=${REDUCE_MAN:=true}
172 REDUCE_VIM=${REDUCE_VIM:=false}
172 REDUCE_VIM=${REDUCE_VIM:=false}
173 REDUCE_BASH=${REDUCE_BASH:=false}
173 REDUCE_BASH=${REDUCE_BASH:=false}
174 REDUCE_HWDB=${REDUCE_HWDB:=true}
174 REDUCE_HWDB=${REDUCE_HWDB:=true}
175 REDUCE_SSHD=${REDUCE_SSHD:=true}
175 REDUCE_SSHD=${REDUCE_SSHD:=true}
176 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
176 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
177
177
178 # Encrypted filesystem settings
178 # Encrypted filesystem settings
179 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
179 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
180 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
180 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
181 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
181 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
182 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
182 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
183 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
183 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
184
184
185 # Chroot scripts directory
185 # Chroot scripts directory
186 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
186 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
187
187
188 # Packages required in the chroot build environment
188 # Packages required in the chroot build environment
189 APT_INCLUDES=${APT_INCLUDES:=""}
189 APT_INCLUDES=${APT_INCLUDES:=""}
190 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd"
190 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup,libnss-systemd"
191
191
192 # Packages to exclude from chroot build environment
192 # Packages to exclude from chroot build environment
193 APT_EXCLUDES=${APT_EXCLUDES:=""}
193 APT_EXCLUDES=${APT_EXCLUDES:=""}
194
194
195 # Packages required for bootstrapping
195 # Packages required for bootstrapping
196 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
196 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
197 MISSING_PACKAGES=""
197 MISSING_PACKAGES=""
198
198
199 # Packages installed for c/c++ build environment in chroot (keep empty)
199 # Packages installed for c/c++ build environment in chroot (keep empty)
200 COMPILER_PACKAGES=""
200 COMPILER_PACKAGES=""
201
201
202 set +x
202 set +x
203
203 #Check if apt-cacher-ng has port 3142 open and set APT_PROXY
204 #Check if apt-cacher-ng has its default port open on and set APT_PROXY
204 APT_CACHER_RUNNING=$(lsof -i :3142 | grep apt-cacher-ng | cut -d ' ' -f3 | uniq)
205 if [ -n "$(lsof -i :3142)" ] ; then
205 if [ -n ${APT_CACHER_RUNNING} ] ; then
206 HTTP_PROXY=http://127.0.0.1:3142/
206 APT_PROXY=http://127.0.0.1:3142/
207 fi
207 fi
208
208
209 # Setup architecture specific settings
209 # Setup architecture specific settings
210 if [ -n "$SET_ARCH" ] ; then
210 if [ -n "$SET_ARCH" ] ; then
211 # 64 bit configuration
211 # 64 bit configuration
212 if [ "$SET_ARCH" = 64 ] ; then
212 if [ "$SET_ARCH" = 64 ] ; then
213 # General 64 bit depended settings
213 # General 64 bit depended settings
214 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
214 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
215 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
215 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
216 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
216 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
217
217
218 # Board specific settings
218 # Board specific settings
219 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
219 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
220 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
220 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
221 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
221 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
222 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
222 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
223 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
223 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
224 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
224 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
225 else
225 else
226 echo "error: Only Raspberry PI 3 and 3B+ support 64 bit"
226 echo "error: Only Raspberry PI 3 and 3B+ support 64 bit"
227 exit 1
227 exit 1
228 fi
228 fi
229 fi
229 fi
230
230
231 # 32 bit configuration
231 # 32 bit configuration
232 if [ "$SET_ARCH" = 32 ] ; then
232 if [ "$SET_ARCH" = 32 ] ; then
233 # General 32 bit dependend settings
233 # General 32 bit dependend settings
234 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
234 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
235 KERNEL_ARCH=${KERNEL_ARCH:=arm}
235 KERNEL_ARCH=${KERNEL_ARCH:=arm}
236 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
236 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
237
237
238 # Hardware specific settings
238 # Hardware specific settings
239 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
239 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
240 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
240 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
241 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
241 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
242 RELEASE_ARCH=${RELEASE_ARCH:=armel}
242 RELEASE_ARCH=${RELEASE_ARCH:=armel}
243 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
243 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
244 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
244 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
245 fi
245 fi
246
246
247 # Hardware specific settings
247 # Hardware specific settings
248 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
248 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
249 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
249 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
250 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
250 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
251 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
251 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
252 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
252 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
253 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
253 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
254 fi
254 fi
255 fi
255 fi
256 #SET_ARCH not set
256 #SET_ARCH not set
257 else
257 else
258 echo "error: Please set '32' or '64' as value for SET_ARCH"
258 echo "error: Please set '32' or '64' as value for SET_ARCH"
259 exit 1
259 exit 1
260 fi
260 fi
261 # Device specific configuration and U-Boot configuration
261 # Device specific configuration and U-Boot configuration
262 case "$RPI_MODEL" in
262 case "$RPI_MODEL" in
263 0)
263 0)
264 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
264 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
265 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
265 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
266 ;;
266 ;;
267 1)
267 1)
268 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
268 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
269 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
269 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
270 ;;
270 ;;
271 1P)
271 1P)
272 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
272 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
273 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
273 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
274 ;;
274 ;;
275 2)
275 2)
276 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
276 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
277 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
277 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
278 ;;
278 ;;
279 3)
279 3)
280 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
280 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
281 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
281 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
282 ;;
282 ;;
283 3P)
283 3P)
284 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
284 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
285 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
285 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
286 ;;
286 ;;
287 *)
287 *)
288 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
288 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
289 exit 1
289 exit 1
290 ;;
290 ;;
291 esac
291 esac
292
292
293 # Prepare date string for default image file name
293 # Prepare date string for default image file name
294 DATE="$(date +%Y-%m-%d)"
294 DATE="$(date +%Y-%m-%d)"
295 if [ -z "$KERNEL_BRANCH" ] ; then
295 if [ -z "$KERNEL_BRANCH" ] ; then
296 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
296 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
297 else
297 else
298 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
298 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
299 fi
299 fi
300
300
301 # Check if the internal wireless interface is supported by the RPi model
301 # Check if the internal wireless interface is supported by the RPi model
302 if [ "$ENABLE_WIRELESS" = true ] ; then
302 if [ "$ENABLE_WIRELESS" = true ] ; then
303 if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then
303 if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then
304 echo "error: The selected Raspberry Pi model has no internal wireless interface"
304 echo "error: The selected Raspberry Pi model has no internal wireless interface"
305 exit 1
305 exit 1
306 fi
306 fi
307 fi
307 fi
308
308
309 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
309 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
310 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
310 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
311 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
311 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
312 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
312 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
313 exit 1
313 exit 1
314 fi
314 fi
315 fi
315 fi
316
316
317 # Add cmake to compile videocore sources
317 # Add cmake to compile videocore sources
318 if [ "$ENABLE_VIDEOCORE" = true ] ; then
318 if [ "$ENABLE_VIDEOCORE" = true ] ; then
319 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
319 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
320 fi
320 fi
321
321
322 # Add libncurses5 to enable kernel menuconfig
322 # Add libncurses5 to enable kernel menuconfig
323 if [ "$KERNEL_MENUCONFIG" = true ] ; then
323 if [ "$KERNEL_MENUCONFIG" = true ] ; then
324 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
324 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
325 fi
325 fi
326
326
327 # Add ccache compiler cache for (faster) kernel cross (re)compilation
327 # Add ccache compiler cache for (faster) kernel cross (re)compilation
328 if [ "$KERNEL_CCACHE" = true ] ; then
328 if [ "$KERNEL_CCACHE" = true ] ; then
329 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
329 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
330 fi
330 fi
331
331
332 # Add cryptsetup package to enable filesystem encryption
332 # Add cryptsetup package to enable filesystem encryption
333 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
333 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
334 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
334 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
335 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
335 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
336
336
337 if [ -z "$CRYPTFS_PASSWORD" ] ; then
337 if [ -z "$CRYPTFS_PASSWORD" ] ; then
338 echo "error: no password defined (CRYPTFS_PASSWORD)!"
338 echo "error: no password defined (CRYPTFS_PASSWORD)!"
339 exit 1
339 exit 1
340 fi
340 fi
341 ENABLE_INITRAMFS=true
341 ENABLE_INITRAMFS=true
342 fi
342 fi
343
343
344 # Add initramfs generation tools
344 # Add initramfs generation tools
345 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
345 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
346 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
346 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
347 fi
347 fi
348
348
349 # Add device-tree-compiler required for building the U-Boot bootloader
349 # Add device-tree-compiler required for building the U-Boot bootloader
350 if [ "$ENABLE_UBOOT" = true ] ; then
350 if [ "$ENABLE_UBOOT" = true ] ; then
351 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
351 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
352 fi
352 fi
353
353
354 # Check if root SSH (v2) public key file exists
354 # Check if root SSH (v2) public key file exists
355 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
355 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
356 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
356 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
357 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
357 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
358 exit 1
358 exit 1
359 fi
359 fi
360 fi
360 fi
361
361
362 # Check if $USER_NAME SSH (v2) public key file exists
362 # Check if $USER_NAME SSH (v2) public key file exists
363 if [ -n "$SSH_USER_PUB_KEY" ] ; then
363 if [ -n "$SSH_USER_PUB_KEY" ] ; then
364 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
364 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
365 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
365 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
366 exit 1
366 exit 1
367 fi
367 fi
368 fi
368 fi
369
369
370 # Check if all required packages are installed on the build system
370 # Check if all required packages are installed on the build system
371 for package in $REQUIRED_PACKAGES ; do
371 for package in $REQUIRED_PACKAGES ; do
372 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
372 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
373 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
373 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
374 fi
374 fi
375 done
375 done
376
376
377 # If there are missing packages ask confirmation for install, or exit
377 # If there are missing packages ask confirmation for install, or exit
378 if [ -n "$MISSING_PACKAGES" ] ; then
378 if [ -n "$MISSING_PACKAGES" ] ; then
379 echo "the following packages needed by this script are not installed:"
379 echo "the following packages needed by this script are not installed:"
380 echo "$MISSING_PACKAGES"
380 echo "$MISSING_PACKAGES"
381
381
382 printf "\ndo you want to install the missing packages right now? [y/n] "
382 printf "\ndo you want to install the missing packages right now? [y/n] "
383 read -r confirm
383 read -r confirm
384 [ "$confirm" != "y" ] && exit 1
384 [ "$confirm" != "y" ] && exit 1
385
385
386 # Make sure all missing required packages are installed
386 # Make sure all missing required packages are installed
387 apt-get -qq -y install "${MISSING_PACKAGES}"
387 apt-get -qq -y install "${MISSING_PACKAGES}"
388 fi
388 fi
389
389
390 # Check if ./bootstrap.d directory exists
390 # Check if ./bootstrap.d directory exists
391 if [ ! -d "./bootstrap.d/" ] ; then
391 if [ ! -d "./bootstrap.d/" ] ; then
392 echo "error: './bootstrap.d' required directory not found!"
392 echo "error: './bootstrap.d' required directory not found!"
393 exit 1
393 exit 1
394 fi
394 fi
395
395
396 # Check if ./files directory exists
396 # Check if ./files directory exists
397 if [ ! -d "./files/" ] ; then
397 if [ ! -d "./files/" ] ; then
398 echo "error: './files' required directory not found!"
398 echo "error: './files' required directory not found!"
399 exit 1
399 exit 1
400 fi
400 fi
401
401
402 # Check if specified KERNELSRC_DIR directory exists
402 # Check if specified KERNELSRC_DIR directory exists
403 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
403 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
404 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
404 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
405 exit 1
405 exit 1
406 fi
406 fi
407
407
408 # Check if specified UBOOTSRC_DIR directory exists
408 # Check if specified UBOOTSRC_DIR directory exists
409 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
409 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
410 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
410 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
411 exit 1
411 exit 1
412 fi
412 fi
413
413
414 # Check if specified VIDEOCORESRC_DIR directory exists
414 # Check if specified VIDEOCORESRC_DIR directory exists
415 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
415 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
416 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
416 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
417 exit 1
417 exit 1
418 fi
418 fi
419
419
420 # Check if specified FBTURBOSRC_DIR directory exists
420 # Check if specified FBTURBOSRC_DIR directory exists
421 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
421 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
422 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
422 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
423 exit 1
423 exit 1
424 fi
424 fi
425
425
426 # Check if specified CHROOT_SCRIPTS directory exists
426 # Check if specified CHROOT_SCRIPTS directory exists
427 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
427 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
428 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
428 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
429 exit 1
429 exit 1
430 fi
430 fi
431
431
432 # Check if specified device mapping already exists (will be used by cryptsetup)
432 # Check if specified device mapping already exists (will be used by cryptsetup)
433 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
433 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
434 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
434 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
435 exit 1
435 exit 1
436 fi
436 fi
437
437
438 # Don't clobber an old build
438 # Don't clobber an old build
439 if [ -e "$BUILDDIR" ] ; then
439 if [ -e "$BUILDDIR" ] ; then
440 echo "error: directory ${BUILDDIR} already exists, not proceeding"
440 echo "error: directory ${BUILDDIR} already exists, not proceeding"
441 exit 1
441 exit 1
442 fi
442 fi
443
443
444 # Setup chroot directory
444 # Setup chroot directory
445 mkdir -p "${R}"
445 mkdir -p "${R}"
446
446
447 # Check if build directory has enough of free disk space >512MB
447 # Check if build directory has enough of free disk space >512MB
448 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
448 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
449 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
449 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
450 exit 1
450 exit 1
451 fi
451 fi
452
452
453 set -x
453 set -x
454
454
455 # Call "cleanup" function on various signals and errors
455 # Call "cleanup" function on various signals and errors
456 trap cleanup 0 1 2 3 6
456 trap cleanup 0 1 2 3 6
457
457
458 # Add required packages for the minbase installation
458 # Add required packages for the minbase installation
459 if [ "$ENABLE_MINBASE" = true ] ; then
459 if [ "$ENABLE_MINBASE" = true ] ; then
460 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
460 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
461 fi
461 fi
462
462
463 # Add parted package, required to get partprobe utility
463 # Add parted package, required to get partprobe utility
464 if [ "$EXPANDROOT" = true ] ; then
464 if [ "$EXPANDROOT" = true ] ; then
465 APT_INCLUDES="${APT_INCLUDES},parted"
465 APT_INCLUDES="${APT_INCLUDES},parted"
466 fi
466 fi
467
467
468 # Add dbus package, recommended if using systemd
468 # Add dbus package, recommended if using systemd
469 if [ "$ENABLE_DBUS" = true ] ; then
469 if [ "$ENABLE_DBUS" = true ] ; then
470 APT_INCLUDES="${APT_INCLUDES},dbus"
470 APT_INCLUDES="${APT_INCLUDES},dbus"
471 fi
471 fi
472
472
473 # Add iptables IPv4/IPv6 package
473 # Add iptables IPv4/IPv6 package
474 if [ "$ENABLE_IPTABLES" = true ] ; then
474 if [ "$ENABLE_IPTABLES" = true ] ; then
475 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
475 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
476 fi
476 fi
477
477
478 # Add openssh server package
478 # Add openssh server package
479 if [ "$ENABLE_SSHD" = true ] ; then
479 if [ "$ENABLE_SSHD" = true ] ; then
480 APT_INCLUDES="${APT_INCLUDES},openssh-server"
480 APT_INCLUDES="${APT_INCLUDES},openssh-server"
481 fi
481 fi
482
482
483 # Add alsa-utils package
483 # Add alsa-utils package
484 if [ "$ENABLE_SOUND" = true ] ; then
484 if [ "$ENABLE_SOUND" = true ] ; then
485 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
485 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
486 fi
486 fi
487
487
488 # Add rng-tools package
488 # Add rng-tools package
489 if [ "$ENABLE_HWRANDOM" = true ] ; then
489 if [ "$ENABLE_HWRANDOM" = true ] ; then
490 APT_INCLUDES="${APT_INCLUDES},rng-tools"
490 APT_INCLUDES="${APT_INCLUDES},rng-tools"
491 fi
491 fi
492
492
493 # Add fbturbo video driver
493 # Add fbturbo video driver
494 if [ "$ENABLE_FBTURBO" = true ] ; then
494 if [ "$ENABLE_FBTURBO" = true ] ; then
495 # Enable xorg package dependencies
495 # Enable xorg package dependencies
496 ENABLE_XORG=true
496 ENABLE_XORG=true
497 fi
497 fi
498
498
499 # Add user defined window manager package
499 # Add user defined window manager package
500 if [ -n "$ENABLE_WM" ] ; then
500 if [ -n "$ENABLE_WM" ] ; then
501 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
501 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
502
502
503 # Enable xorg package dependencies
503 # Enable xorg package dependencies
504 ENABLE_XORG=true
504 ENABLE_XORG=true
505 fi
505 fi
506
506
507 # Add xorg package
507 # Add xorg package
508 if [ "$ENABLE_XORG" = true ] ; then
508 if [ "$ENABLE_XORG" = true ] ; then
509 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
509 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
510 fi
510 fi
511
511
512 # Replace selected packages with smaller clones
512 # Replace selected packages with smaller clones
513 if [ "$ENABLE_REDUCE" = true ] ; then
513 if [ "$ENABLE_REDUCE" = true ] ; then
514 # Add levee package instead of vim-tiny
514 # Add levee package instead of vim-tiny
515 if [ "$REDUCE_VIM" = true ] ; then
515 if [ "$REDUCE_VIM" = true ] ; then
516 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
516 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
517 fi
517 fi
518
518
519 # Add dropbear package instead of openssh-server
519 # Add dropbear package instead of openssh-server
520 if [ "$REDUCE_SSHD" = true ] ; then
520 if [ "$REDUCE_SSHD" = true ] ; then
521 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
521 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
522 fi
522 fi
523 fi
523 fi
524
524
525 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
525 # Configure systemd-sysv exclude to make halt/reboot/shutdown scripts available
526 if [ "$ENABLE_SYSVINIT" = false ] ; then
526 if [ "$ENABLE_SYSVINIT" = false ] ; then
527 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
527 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
528 fi
528 fi
529
529
530 # Check if kernel is getting compiled
530 # Check if kernel is getting compiled
531 if [ "$BUILD_KERNEL" = false ] ; then
531 if [ "$BUILD_KERNEL" = false ] ; then
532 echo "Downloading precompiled kernel"
532 echo "Downloading precompiled kernel"
533 echo "error: not configured"
533 echo "error: not configured"
534 exit 1;
534 exit 1;
535 # BUILD_KERNEL=true
535 # BUILD_KERNEL=true
536 else
536 else
537 echo "No precompiled kernel repositories were added"
537 echo "No precompiled kernel repositories were added"
538 fi
538 fi
539
539
540 # Configure kernel sources if no KERNELSRC_DIR
540 # Configure kernel sources if no KERNELSRC_DIR
541 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
541 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
542 KERNELSRC_CONFIG=true
542 KERNELSRC_CONFIG=true
543 fi
543 fi
544
544
545 # Configure reduced kernel
545 # Configure reduced kernel
546 if [ "$KERNEL_REDUCE" = true ] ; then
546 if [ "$KERNEL_REDUCE" = true ] ; then
547 KERNELSRC_CONFIG=false
547 KERNELSRC_CONFIG=false
548 fi
548 fi
549
549
550 # Configure qemu compatible kernel
550 # Configure qemu compatible kernel
551 if [ "$ENABLE_QEMU" = true ] ; then
551 if [ "$ENABLE_QEMU" = true ] ; then
552 DTB_FILE=vexpress-v2p-ca15_a7.dtb
552 DTB_FILE=vexpress-v2p-ca15_a7.dtb
553 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
553 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
554 KERNEL_DEFCONFIG="vexpress_defconfig"
554 KERNEL_DEFCONFIG="vexpress_defconfig"
555 if [ "$KERNEL_MENUCONFIG" = false ] ; then
555 if [ "$KERNEL_MENUCONFIG" = false ] ; then
556 KERNEL_OLDDEFCONFIG=true
556 KERNEL_OLDDEFCONFIG=true
557 fi
557 fi
558 fi
558 fi
559
559
560 # Execute bootstrap scripts
560 # Execute bootstrap scripts
561 for SCRIPT in bootstrap.d/*.sh; do
561 for SCRIPT in bootstrap.d/*.sh; do
562 head -n 3 "$SCRIPT"
562 head -n 3 "$SCRIPT"
563 . "$SCRIPT"
563 . "$SCRIPT"
564 done
564 done
565
565
566 ## Execute custom bootstrap scripts
566 ## Execute custom bootstrap scripts
567 if [ -d "custom.d" ] ; then
567 if [ -d "custom.d" ] ; then
568 for SCRIPT in custom.d/*.sh; do
568 for SCRIPT in custom.d/*.sh; do
569 . "$SCRIPT"
569 . "$SCRIPT"
570 done
570 done
571 fi
571 fi
572
572
573 # Execute custom scripts inside the chroot
573 # Execute custom scripts inside the chroot
574 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
574 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
575 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
575 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
576 chroot_exec /bin/bash -x <<'EOF'
576 chroot_exec /bin/bash -x <<'EOF'
577 for SCRIPT in /chroot_scripts/* ; do
577 for SCRIPT in /chroot_scripts/* ; do
578 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
578 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
579 $SCRIPT
579 $SCRIPT
580 fi
580 fi
581 done
581 done
582 EOF
582 EOF
583 rm -rf "${R}/chroot_scripts"
583 rm -rf "${R}/chroot_scripts"
584 fi
584 fi
585
585
586 # Remove c/c++ build environment from the chroot
586 # Remove c/c++ build environment from the chroot
587 chroot_remove_cc
587 chroot_remove_cc
588
588
589 # Generate required machine-id
589 # Generate required machine-id
590 MACHINE_ID=$(dbus-uuidgen)
590 MACHINE_ID=$(dbus-uuidgen)
591 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
591 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
592 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
592 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
593
593
594 # APT Cleanup
594 # APT Cleanup
595 chroot_exec apt-get -y clean
595 chroot_exec apt-get -y clean
596 chroot_exec apt-get -y autoclean
596 chroot_exec apt-get -y autoclean
597 chroot_exec apt-get -y autoremove
597 chroot_exec apt-get -y autoremove
598
598
599 # Unmount mounted filesystems
599 # Unmount mounted filesystems
600 umount -l "${R}/proc"
600 umount -l "${R}/proc"
601 umount -l "${R}/sys"
601 umount -l "${R}/sys"
602
602
603 # Clean up directories
603 # Clean up directories
604 rm -rf "${R}/run/*"
604 rm -rf "${R}/run/*"
605 rm -rf "${R}/tmp/*"
605 rm -rf "${R}/tmp/*"
606
606
607 # Clean up files
607 # Clean up files
608 rm -f "${ETC_DIR}/ssh/ssh_host_*"
608 rm -f "${ETC_DIR}/ssh/ssh_host_*"
609 rm -f "${ETC_DIR}/dropbear/dropbear_*"
609 rm -f "${ETC_DIR}/dropbear/dropbear_*"
610 rm -f "${ETC_DIR}/apt/sources.list.save"
610 rm -f "${ETC_DIR}/apt/sources.list.save"
611 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
611 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
612 rm -f "${ETC_DIR}/*-"
612 rm -f "${ETC_DIR}/*-"
613 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
613 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
614 rm -f "${ETC_DIR}/resolv.conf"
614 rm -f "${ETC_DIR}/resolv.conf"
615 rm -f "${R}/root/.bash_history"
615 rm -f "${R}/root/.bash_history"
616 rm -f "${R}/var/lib/urandom/random-seed"
616 rm -f "${R}/var/lib/urandom/random-seed"
617 rm -f "${R}/initrd.img"
617 rm -f "${R}/initrd.img"
618 rm -f "${R}/vmlinuz"
618 rm -f "${R}/vmlinuz"
619 rm -f "${R}${QEMU_BINARY}"
619 rm -f "${R}${QEMU_BINARY}"
620
620
621 if [ "$ENABLE_QEMU" = true ] ; then
621 if [ "$ENABLE_QEMU" = true ] ; then
622 # Setup QEMU directory
622 # Setup QEMU directory
623 mkdir "${BASEDIR}/qemu"
623 mkdir "${BASEDIR}/qemu"
624
624
625 # Copy kernel image to QEMU directory
625 # Copy kernel image to QEMU directory
626 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
626 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
627
627
628 # Copy kernel config to QEMU directory
628 # Copy kernel config to QEMU directory
629 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
629 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
630
630
631 # Copy kernel dtbs to QEMU directory
631 # Copy kernel dtbs to QEMU directory
632 for dtb in "${BOOT_DIR}/"*.dtb ; do
632 for dtb in "${BOOT_DIR}/"*.dtb ; do
633 if [ -f "${dtb}" ] ; then
633 if [ -f "${dtb}" ] ; then
634 install_readonly "${dtb}" "${BASEDIR}/qemu/"
634 install_readonly "${dtb}" "${BASEDIR}/qemu/"
635 fi
635 fi
636 done
636 done
637
637
638 # Copy kernel overlays to QEMU directory
638 # Copy kernel overlays to QEMU directory
639 if [ -d "${BOOT_DIR}/overlays" ] ; then
639 if [ -d "${BOOT_DIR}/overlays" ] ; then
640 # Setup overlays dtbs directory
640 # Setup overlays dtbs directory
641 mkdir "${BASEDIR}/qemu/overlays"
641 mkdir "${BASEDIR}/qemu/overlays"
642
642
643 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
643 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
644 if [ -f "${dtb}" ] ; then
644 if [ -f "${dtb}" ] ; then
645 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
645 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
646 fi
646 fi
647 done
647 done
648 fi
648 fi
649
649
650 # Copy u-boot files to QEMU directory
650 # Copy u-boot files to QEMU directory
651 if [ "$ENABLE_UBOOT" = true ] ; then
651 if [ "$ENABLE_UBOOT" = true ] ; then
652 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
652 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
653 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
653 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
654 fi
654 fi
655 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
655 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
656 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
656 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
657 fi
657 fi
658 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
658 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
659 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
659 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
660 fi
660 fi
661 fi
661 fi
662
662
663 # Copy initramfs to QEMU directory
663 # Copy initramfs to QEMU directory
664 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
664 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
665 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
665 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
666 fi
666 fi
667 fi
667 fi
668
668
669 # Calculate size of the chroot directory in KB
669 # Calculate size of the chroot directory in KB
670 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
670 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
671
671
672 # Calculate the amount of needed 512 Byte sectors
672 # Calculate the amount of needed 512 Byte sectors
673 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
673 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
674 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
674 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
675 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
675 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
676
676
677 # The root partition is EXT4
677 # The root partition is EXT4
678 # This means more space than the actual used space of the chroot is used.
678 # This means more space than the actual used space of the chroot is used.
679 # As overhead for journaling and reserved blocks 35% are added.
679 # As overhead for journaling and reserved blocks 35% are added.
680 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
680 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
681
681
682 # Calculate required image size in 512 Byte sectors
682 # Calculate required image size in 512 Byte sectors
683 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
683 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
684
684
685 # Prepare image file
685 # Prepare image file
686 if [ "$ENABLE_SPLITFS" = true ] ; then
686 if [ "$ENABLE_SPLITFS" = true ] ; then
687 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
687 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
688 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
688 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
689 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
689 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
690 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
690 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
691
691
692 # Write firmware/boot partition tables
692 # Write firmware/boot partition tables
693 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
693 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
694 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
694 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
695 EOM
695 EOM
696
696
697 # Write root partition table
697 # Write root partition table
698 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
698 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
699 ${TABLE_SECTORS},${ROOT_SECTORS},83
699 ${TABLE_SECTORS},${ROOT_SECTORS},83
700 EOM
700 EOM
701
701
702 # Setup temporary loop devices
702 # Setup temporary loop devices
703 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
703 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
704 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
704 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
705 else # ENABLE_SPLITFS=false
705 else # ENABLE_SPLITFS=false
706 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
706 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
707 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
707 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
708
708
709 # Write partition table
709 # Write partition table
710 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
710 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
711 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
711 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
712 ${ROOT_OFFSET},${ROOT_SECTORS},83
712 ${ROOT_OFFSET},${ROOT_SECTORS},83
713 EOM
713 EOM
714
714
715 # Setup temporary loop devices
715 # Setup temporary loop devices
716 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
716 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
717 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
717 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
718 fi
718 fi
719
719
720 if [ "$ENABLE_CRYPTFS" = true ] ; then
720 if [ "$ENABLE_CRYPTFS" = true ] ; then
721 # Create dummy ext4 fs
721 # Create dummy ext4 fs
722 mkfs.ext4 "$ROOT_LOOP"
722 mkfs.ext4 "$ROOT_LOOP"
723
723
724 # Setup password keyfile
724 # Setup password keyfile
725 touch .password
725 touch .password
726 chmod 600 .password
726 chmod 600 .password
727 echo -n ${CRYPTFS_PASSWORD} > .password
727 echo -n ${CRYPTFS_PASSWORD} > .password
728
728
729 # Initialize encrypted partition
729 # Initialize encrypted partition
730 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
730 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
731
731
732 # Open encrypted partition and setup mapping
732 # Open encrypted partition and setup mapping
733 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
733 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
734
734
735 # Secure delete password keyfile
735 # Secure delete password keyfile
736 shred -zu .password
736 shred -zu .password
737
737
738 # Update temporary loop device
738 # Update temporary loop device
739 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
739 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
740
740
741 # Wipe encrypted partition (encryption cipher is used for randomness)
741 # Wipe encrypted partition (encryption cipher is used for randomness)
742 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
742 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
743 fi
743 fi
744
744
745 # Build filesystems
745 # Build filesystems
746 mkfs.vfat "$FRMW_LOOP"
746 mkfs.vfat "$FRMW_LOOP"
747 mkfs.ext4 "$ROOT_LOOP"
747 mkfs.ext4 "$ROOT_LOOP"
748
748
749 # Mount the temporary loop devices
749 # Mount the temporary loop devices
750 mkdir -p "$BUILDDIR/mount"
750 mkdir -p "$BUILDDIR/mount"
751 mount "$ROOT_LOOP" "$BUILDDIR/mount"
751 mount "$ROOT_LOOP" "$BUILDDIR/mount"
752
752
753 mkdir -p "$BUILDDIR/mount/boot/firmware"
753 mkdir -p "$BUILDDIR/mount/boot/firmware"
754 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
754 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
755
755
756 # Copy all files from the chroot to the loop device mount point directory
756 # Copy all files from the chroot to the loop device mount point directory
757 rsync -a "${R}/" "$BUILDDIR/mount/"
757 rsync -a "${R}/" "$BUILDDIR/mount/"
758
758
759 # Unmount all temporary loop devices and mount points
759 # Unmount all temporary loop devices and mount points
760 cleanup
760 cleanup
761
761
762 # Create block map file(s) of image(s)
762 # Create block map file(s) of image(s)
763 if [ "$ENABLE_SPLITFS" = true ] ; then
763 if [ "$ENABLE_SPLITFS" = true ] ; then
764 # Create block map files for "bmaptool"
764 # Create block map files for "bmaptool"
765 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
765 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
766 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
766 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
767
767
768 # Image was successfully created
768 # Image was successfully created
769 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
769 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
770 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
770 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
771 else
771 else
772 # Create block map file for "bmaptool"
772 # Create block map file for "bmaptool"
773 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
773 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
774
774
775 # Image was successfully created
775 # Image was successfully created
776 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
776 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
777
777
778 # Create qemu qcow2 image
778 # Create qemu qcow2 image
779 if [ "$ENABLE_QEMU" = true ] ; then
779 if [ "$ENABLE_QEMU" = true ] ; then
780 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
780 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
781 QEMU_SIZE=16G
781 QEMU_SIZE=16G
782
782
783 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
783 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
784 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
784 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
785
785
786 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
786 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
787 fi
787 fi
788 fi
788 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant