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