##// END OF EJS Templates
Added variables to allow for arm64 and different branches.
Bobberty -
r146:e6b5c93408d5
parent child
Show More
@@ -1,629 +1,640
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" and "stretch" bootstrap script for RPi2/3
6 # Advanced Debian "jessie" and "stretch" 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 10+ github contributors!
15 # Big thanks for patches and enhancements by 10+ 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 [ ! -z "$CONFIG_TEMPLATE" ] ; then
34 if [ ! -z "$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 RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb}
45 RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb}
46 RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig}
46 RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig}
47 RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb}
47 RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb}
48 RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig}
48 RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig}
49
49
50 # Debian release
50 # Debian release
51 RELEASE=${RELEASE:=jessie}
51 RELEASE=${RELEASE:=jessie}
52 KERNEL_ARCH=${KERNEL_ARCH:=arm}
52 KERNEL_ARCH=${KERNEL_ARCH:=arm}
53 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
53 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
54 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
54 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
55 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
55 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
56 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
56 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
57 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
57 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
58 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
58 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
59 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
59
60
60 # URLs
61 # URLs
61 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
62 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
62 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
63 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
63 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm}
64 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm80211/brcm}
64 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
65 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
65 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
66 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
66 UBOOT_URL=${UBOOT_URL:=git://git.denx.de/u-boot.git}
67 UBOOT_URL=${UBOOT_URL:=git://git.denx.de/u-boot.git}
67
68
68 # Build directories
69 # Build directories
69 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
70 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
70 BUILDDIR="${BASEDIR}/build"
71 BUILDDIR="${BASEDIR}/build"
72
71 # Prepare date string for default image file name
73 # Prepare date string for default image file name
72 DATE="$(date +%Y-%m-%d)"
74 DATE="$(date +%Y-%m-%d)"
73 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-rpi${RPI_MODEL}-${RELEASE}}
75 if [ -z "$KERNEL_BRANCH" ] ; then
76 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
77 else
78 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
79 fi
74
80
75 # Chroot directories
81 # Chroot directories
76 R="${BUILDDIR}/chroot"
82 R="${BUILDDIR}/chroot"
77 ETC_DIR="${R}/etc"
83 ETC_DIR="${R}/etc"
78 LIB_DIR="${R}/lib"
84 LIB_DIR="${R}/lib"
79 BOOT_DIR="${R}/boot/firmware"
85 BOOT_DIR="${R}/boot/firmware"
80 KERNEL_DIR="${R}/usr/src/linux"
86 KERNEL_DIR="${R}/usr/src/linux"
81 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
87 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
82
88
83 # Firmware directory: Blank if download from github
89 # Firmware directory: Blank if download from github
84 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
90 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
85
91
86 # General settings
92 # General settings
87 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
93 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
88 PASSWORD=${PASSWORD:=raspberry}
94 PASSWORD=${PASSWORD:=raspberry}
89 USER_PASSWORD=${USER_PASSWORD:=raspberry}
95 USER_PASSWORD=${USER_PASSWORD:=raspberry}
90 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
96 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
91 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
97 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
92 EXPANDROOT=${EXPANDROOT:=true}
98 EXPANDROOT=${EXPANDROOT:=true}
93
99
94 # Keyboard settings
100 # Keyboard settings
95 XKB_MODEL=${XKB_MODEL:=""}
101 XKB_MODEL=${XKB_MODEL:=""}
96 XKB_LAYOUT=${XKB_LAYOUT:=""}
102 XKB_LAYOUT=${XKB_LAYOUT:=""}
97 XKB_VARIANT=${XKB_VARIANT:=""}
103 XKB_VARIANT=${XKB_VARIANT:=""}
98 XKB_OPTIONS=${XKB_OPTIONS:=""}
104 XKB_OPTIONS=${XKB_OPTIONS:=""}
99
105
100 # Network settings (DHCP)
106 # Network settings (DHCP)
101 ENABLE_DHCP=${ENABLE_DHCP:=true}
107 ENABLE_DHCP=${ENABLE_DHCP:=true}
102
108
103 # Network settings (static)
109 # Network settings (static)
104 NET_ADDRESS=${NET_ADDRESS:=""}
110 NET_ADDRESS=${NET_ADDRESS:=""}
105 NET_GATEWAY=${NET_GATEWAY:=""}
111 NET_GATEWAY=${NET_GATEWAY:=""}
106 NET_DNS_1=${NET_DNS_1:=""}
112 NET_DNS_1=${NET_DNS_1:=""}
107 NET_DNS_2=${NET_DNS_2:=""}
113 NET_DNS_2=${NET_DNS_2:=""}
108 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
114 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
109 NET_NTP_1=${NET_NTP_1:=""}
115 NET_NTP_1=${NET_NTP_1:=""}
110 NET_NTP_2=${NET_NTP_2:=""}
116 NET_NTP_2=${NET_NTP_2:=""}
111
117
112 # APT settings
118 # APT settings
113 APT_PROXY=${APT_PROXY:=""}
119 APT_PROXY=${APT_PROXY:=""}
114 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
120 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
115
121
116 # Feature settings
122 # Feature settings
117 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
123 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
118 ENABLE_I2C=${ENABLE_I2C:=false}
124 ENABLE_I2C=${ENABLE_I2C:=false}
119 ENABLE_SPI=${ENABLE_SPI:=false}
125 ENABLE_SPI=${ENABLE_SPI:=false}
120 ENABLE_IPV6=${ENABLE_IPV6:=true}
126 ENABLE_IPV6=${ENABLE_IPV6:=true}
121 ENABLE_SSHD=${ENABLE_SSHD:=true}
127 ENABLE_SSHD=${ENABLE_SSHD:=true}
122 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
128 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
123 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
129 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
124 ENABLE_SOUND=${ENABLE_SOUND:=true}
130 ENABLE_SOUND=${ENABLE_SOUND:=true}
125 ENABLE_DBUS=${ENABLE_DBUS:=true}
131 ENABLE_DBUS=${ENABLE_DBUS:=true}
126 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
132 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
127 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
133 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
128 ENABLE_XORG=${ENABLE_XORG:=false}
134 ENABLE_XORG=${ENABLE_XORG:=false}
129 ENABLE_WM=${ENABLE_WM:=""}
135 ENABLE_WM=${ENABLE_WM:=""}
130 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
136 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
131 ENABLE_USER=${ENABLE_USER:=true}
137 ENABLE_USER=${ENABLE_USER:=true}
132 USER_NAME=${USER_NAME:="pi"}
138 USER_NAME=${USER_NAME:="pi"}
133 ENABLE_ROOT=${ENABLE_ROOT:=false}
139 ENABLE_ROOT=${ENABLE_ROOT:=false}
134
140
135 # SSH settings
141 # SSH settings
136 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
142 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
137 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
143 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
138 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
144 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
139 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
145 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
140 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
146 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
141
147
142 # Advanced settings
148 # Advanced settings
143 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
149 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
144 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
150 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
145 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
151 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
146 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
152 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
147 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
153 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
148 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
154 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
149 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
155 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
150 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
156 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
151 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
157 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
152 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
158 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
153 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
159 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
154 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
160 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
155
161
156 # Kernel compilation settings
162 # Kernel compilation settings
157 BUILD_KERNEL=${BUILD_KERNEL:=false}
163 BUILD_KERNEL=${BUILD_KERNEL:=false}
158 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
164 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
159 KERNEL_THREADS=${KERNEL_THREADS:=1}
165 KERNEL_THREADS=${KERNEL_THREADS:=1}
160 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
166 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
161 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
167 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
162 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
168 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
169 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
163
170
164 # Kernel compilation from source directory settings
171 # Kernel compilation from source directory settings
165 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
172 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
166 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
173 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
167 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
174 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
168 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
175 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
169
176
170 # Reduce disk usage settings
177 # Reduce disk usage settings
171 REDUCE_APT=${REDUCE_APT:=true}
178 REDUCE_APT=${REDUCE_APT:=true}
172 REDUCE_DOC=${REDUCE_DOC:=true}
179 REDUCE_DOC=${REDUCE_DOC:=true}
173 REDUCE_MAN=${REDUCE_MAN:=true}
180 REDUCE_MAN=${REDUCE_MAN:=true}
174 REDUCE_VIM=${REDUCE_VIM:=false}
181 REDUCE_VIM=${REDUCE_VIM:=false}
175 REDUCE_BASH=${REDUCE_BASH:=false}
182 REDUCE_BASH=${REDUCE_BASH:=false}
176 REDUCE_HWDB=${REDUCE_HWDB:=true}
183 REDUCE_HWDB=${REDUCE_HWDB:=true}
177 REDUCE_SSHD=${REDUCE_SSHD:=true}
184 REDUCE_SSHD=${REDUCE_SSHD:=true}
178 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
185 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
179
186
180 # Encrypted filesystem settings
187 # Encrypted filesystem settings
181 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
188 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
182 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
189 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
183 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
190 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
184 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
191 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
185 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
192 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
186
193
187 # Stop the Crypto Wars
194 # Stop the Crypto Wars
188 DISABLE_FBI=${DISABLE_FBI:=false}
195 DISABLE_FBI=${DISABLE_FBI:=false}
189
196
190 # Chroot scripts directory
197 # Chroot scripts directory
191 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
198 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
192
199
193 # Packages required in the chroot build environment
200 # Packages required in the chroot build environment
194 APT_INCLUDES=${APT_INCLUDES:=""}
201 APT_INCLUDES=${APT_INCLUDES:=""}
195 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
202 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
196
203
197 # Packages required for bootstrapping
204 # Packages required for bootstrapping
198 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
205 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
199 MISSING_PACKAGES=""
206 MISSING_PACKAGES=""
200
207
201 # Packages installed for c/c++ build environment in chroot (keep empty)
208 # Packages installed for c/c++ build environment in chroot (keep empty)
202 COMPILER_PACKAGES=""
209 COMPILER_PACKAGES=""
203
210
204 set +x
211 set +x
205
212
206 # Set Raspberry Pi model specific configuration
213 # Set Raspberry Pi model specific configuration
207 if [ "$RPI_MODEL" = 2 ] ; then
214 if [ "$RPI_MODEL" = 2 ] ; then
208 DTB_FILE=${RPI2_DTB_FILE}
215 DTB_FILE=${RPI2_DTB_FILE}
209 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
216 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
210 elif [ "$RPI_MODEL" = 3 ] ; then
217 elif [ "$RPI_MODEL" = 3 ] ; then
211 DTB_FILE=${RPI3_DTB_FILE}
218 DTB_FILE=${RPI3_DTB_FILE}
212 UBOOT_CONFIG=${RPI3_UBOOT_CONFIG}
219 UBOOT_CONFIG=${RPI3_UBOOT_CONFIG}
213 BUILD_KERNEL=true
220 BUILD_KERNEL=true
214 else
221 else
215 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
222 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
216 exit 1
223 exit 1
217 fi
224 fi
218
225
219 # Check if the internal wireless interface is supported by the RPi model
226 # Check if the internal wireless interface is supported by the RPi model
220 if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" != 3 ] ; then
227 if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" != 3 ] ; then
221 echo "error: The selected Raspberry Pi model has no internal wireless interface"
228 echo "error: The selected Raspberry Pi model has no internal wireless interface"
222 exit 1
229 exit 1
223 fi
230 fi
224
231
225 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
232 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
226 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
233 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
227 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
234 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
228 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
235 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
229 exit 1
236 exit 1
230 fi
237 fi
231 fi
238 fi
232
239
233 # Build RPi2/3 Linux kernel if required by Debian release
240 # Build RPi2/3 Linux kernel if required by Debian release
234 if [ "$RELEASE" = "stretch" ] ; then
241 if [ "$RELEASE" = "stretch" ] ; then
235 BUILD_KERNEL=true
242 BUILD_KERNEL=true
236 fi
243 fi
237
244
238 # Add packages required for kernel cross compilation
245 # Add packages required for kernel cross compilation
239 if [ "$BUILD_KERNEL" = true ] ; then
246 if [ "$BUILD_KERNEL" = true ] ; then
240 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
247 if [ "$KERNEL_ARCH" = "arm" ] ; then
248 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
249 else
250 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
251 fi
241 fi
252 fi
242
253
243 # Add libncurses5 to enable kernel menuconfig
254 # Add libncurses5 to enable kernel menuconfig
244 if [ "$KERNEL_MENUCONFIG" = true ] ; then
255 if [ "$KERNEL_MENUCONFIG" = true ] ; then
245 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
256 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
246 fi
257 fi
247
258
248 # Stop the Crypto Wars
259 # Stop the Crypto Wars
249 if [ "$DISABLE_FBI" = true ] ; then
260 if [ "$DISABLE_FBI" = true ] ; then
250 ENABLE_CRYPTFS=true
261 ENABLE_CRYPTFS=true
251 fi
262 fi
252
263
253 # Add cryptsetup package to enable filesystem encryption
264 # Add cryptsetup package to enable filesystem encryption
254 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
265 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
255 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
266 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
256 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
267 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
257
268
258 if [ -z "$CRYPTFS_PASSWORD" ] ; then
269 if [ -z "$CRYPTFS_PASSWORD" ] ; then
259 echo "error: no password defined (CRYPTFS_PASSWORD)!"
270 echo "error: no password defined (CRYPTFS_PASSWORD)!"
260 exit 1
271 exit 1
261 fi
272 fi
262 ENABLE_INITRAMFS=true
273 ENABLE_INITRAMFS=true
263 fi
274 fi
264
275
265 # Add initramfs generation tools
276 # Add initramfs generation tools
266 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
277 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
267 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
278 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
268 fi
279 fi
269
280
270 # Add device-tree-compiler required for building the U-Boot bootloader
281 # Add device-tree-compiler required for building the U-Boot bootloader
271 if [ "$ENABLE_UBOOT" = true ] ; then
282 if [ "$ENABLE_UBOOT" = true ] ; then
272 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler"
283 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler"
273 fi
284 fi
274
285
275 # Check if root SSH (v2) public key file exists
286 # Check if root SSH (v2) public key file exists
276 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
287 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
277 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
288 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
278 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
289 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
279 exit 1
290 exit 1
280 fi
291 fi
281 fi
292 fi
282
293
283 # Check if $USER_NAME SSH (v2) public key file exists
294 # Check if $USER_NAME SSH (v2) public key file exists
284 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
295 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
285 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
296 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
286 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
297 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
287 exit 1
298 exit 1
288 fi
299 fi
289 fi
300 fi
290
301
291 # Check if all required packages are installed on the build system
302 # Check if all required packages are installed on the build system
292 for package in $REQUIRED_PACKAGES ; do
303 for package in $REQUIRED_PACKAGES ; do
293 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
304 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
294 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
305 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
295 fi
306 fi
296 done
307 done
297
308
298 # If there are missing packages ask confirmation for install, or exit
309 # If there are missing packages ask confirmation for install, or exit
299 if [ -n "$MISSING_PACKAGES" ] ; then
310 if [ -n "$MISSING_PACKAGES" ] ; then
300 echo "the following packages needed by this script are not installed:"
311 echo "the following packages needed by this script are not installed:"
301 echo "$MISSING_PACKAGES"
312 echo "$MISSING_PACKAGES"
302
313
303 echo -n "\ndo you want to install the missing packages right now? [y/n] "
314 echo -n "\ndo you want to install the missing packages right now? [y/n] "
304 read confirm
315 read confirm
305 [ "$confirm" != "y" ] && exit 1
316 [ "$confirm" != "y" ] && exit 1
306
317
307 # Make sure all missing required packages are installed
318 # Make sure all missing required packages are installed
308 apt-get -qq -y install ${MISSING_PACKAGES}
319 apt-get -qq -y install ${MISSING_PACKAGES}
309 fi
320 fi
310
321
311 # Check if ./bootstrap.d directory exists
322 # Check if ./bootstrap.d directory exists
312 if [ ! -d "./bootstrap.d/" ] ; then
323 if [ ! -d "./bootstrap.d/" ] ; then
313 echo "error: './bootstrap.d' required directory not found!"
324 echo "error: './bootstrap.d' required directory not found!"
314 exit 1
325 exit 1
315 fi
326 fi
316
327
317 # Check if ./files directory exists
328 # Check if ./files directory exists
318 if [ ! -d "./files/" ] ; then
329 if [ ! -d "./files/" ] ; then
319 echo "error: './files' required directory not found!"
330 echo "error: './files' required directory not found!"
320 exit 1
331 exit 1
321 fi
332 fi
322
333
323 # Check if specified KERNELSRC_DIR directory exists
334 # Check if specified KERNELSRC_DIR directory exists
324 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
335 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
325 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
336 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
326 exit 1
337 exit 1
327 fi
338 fi
328
339
329 # Check if specified UBOOTSRC_DIR directory exists
340 # Check if specified UBOOTSRC_DIR directory exists
330 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
341 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
331 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
342 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
332 exit 1
343 exit 1
333 fi
344 fi
334
345
335 # Check if specified FBTURBOSRC_DIR directory exists
346 # Check if specified FBTURBOSRC_DIR directory exists
336 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
347 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
337 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
348 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
338 exit 1
349 exit 1
339 fi
350 fi
340
351
341 # Check if specified CHROOT_SCRIPTS directory exists
352 # Check if specified CHROOT_SCRIPTS directory exists
342 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
353 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
343 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
354 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
344 exit 1
355 exit 1
345 fi
356 fi
346
357
347 # Check if specified device mapping already exists (will be used by cryptsetup)
358 # Check if specified device mapping already exists (will be used by cryptsetup)
348 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
359 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
349 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
360 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
350 exit 1
361 exit 1
351 fi
362 fi
352
363
353 # Don't clobber an old build
364 # Don't clobber an old build
354 if [ -e "$BUILDDIR" ] ; then
365 if [ -e "$BUILDDIR" ] ; then
355 echo "error: directory ${BUILDDIR} already exists, not proceeding"
366 echo "error: directory ${BUILDDIR} already exists, not proceeding"
356 exit 1
367 exit 1
357 fi
368 fi
358
369
359 # Setup chroot directory
370 # Setup chroot directory
360 mkdir -p "${R}"
371 mkdir -p "${R}"
361
372
362 # Check if build directory has enough of free disk space >512MB
373 # Check if build directory has enough of free disk space >512MB
363 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
374 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
364 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
375 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
365 exit 1
376 exit 1
366 fi
377 fi
367
378
368 set -x
379 set -x
369
380
370 # Call "cleanup" function on various signals and errors
381 # Call "cleanup" function on various signals and errors
371 trap cleanup 0 1 2 3 6
382 trap cleanup 0 1 2 3 6
372
383
373 # Add required packages for the minbase installation
384 # Add required packages for the minbase installation
374 if [ "$ENABLE_MINBASE" = true ] ; then
385 if [ "$ENABLE_MINBASE" = true ] ; then
375 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
386 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
376 fi
387 fi
377
388
378 # Add required locales packages
389 # Add required locales packages
379 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
390 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
380 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
391 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
381 fi
392 fi
382
393
383 # Add parted package, required to get partprobe utility
394 # Add parted package, required to get partprobe utility
384 if [ "$EXPANDROOT" = true ] ; then
395 if [ "$EXPANDROOT" = true ] ; then
385 APT_INCLUDES="${APT_INCLUDES},parted"
396 APT_INCLUDES="${APT_INCLUDES},parted"
386 fi
397 fi
387
398
388 # Add dbus package, recommended if using systemd
399 # Add dbus package, recommended if using systemd
389 if [ "$ENABLE_DBUS" = true ] ; then
400 if [ "$ENABLE_DBUS" = true ] ; then
390 APT_INCLUDES="${APT_INCLUDES},dbus"
401 APT_INCLUDES="${APT_INCLUDES},dbus"
391 fi
402 fi
392
403
393 # Add iptables IPv4/IPv6 package
404 # Add iptables IPv4/IPv6 package
394 if [ "$ENABLE_IPTABLES" = true ] ; then
405 if [ "$ENABLE_IPTABLES" = true ] ; then
395 APT_INCLUDES="${APT_INCLUDES},iptables"
406 APT_INCLUDES="${APT_INCLUDES},iptables"
396 fi
407 fi
397
408
398 # Add openssh server package
409 # Add openssh server package
399 if [ "$ENABLE_SSHD" = true ] ; then
410 if [ "$ENABLE_SSHD" = true ] ; then
400 APT_INCLUDES="${APT_INCLUDES},openssh-server"
411 APT_INCLUDES="${APT_INCLUDES},openssh-server"
401 fi
412 fi
402
413
403 # Add alsa-utils package
414 # Add alsa-utils package
404 if [ "$ENABLE_SOUND" = true ] ; then
415 if [ "$ENABLE_SOUND" = true ] ; then
405 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
416 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
406 fi
417 fi
407
418
408 # Add rng-tools package
419 # Add rng-tools package
409 if [ "$ENABLE_HWRANDOM" = true ] ; then
420 if [ "$ENABLE_HWRANDOM" = true ] ; then
410 APT_INCLUDES="${APT_INCLUDES},rng-tools"
421 APT_INCLUDES="${APT_INCLUDES},rng-tools"
411 fi
422 fi
412
423
413 # Add fbturbo video driver
424 # Add fbturbo video driver
414 if [ "$ENABLE_FBTURBO" = true ] ; then
425 if [ "$ENABLE_FBTURBO" = true ] ; then
415 # Enable xorg package dependencies
426 # Enable xorg package dependencies
416 ENABLE_XORG=true
427 ENABLE_XORG=true
417 fi
428 fi
418
429
419 # Add user defined window manager package
430 # Add user defined window manager package
420 if [ -n "$ENABLE_WM" ] ; then
431 if [ -n "$ENABLE_WM" ] ; then
421 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
432 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
422
433
423 # Enable xorg package dependencies
434 # Enable xorg package dependencies
424 ENABLE_XORG=true
435 ENABLE_XORG=true
425 fi
436 fi
426
437
427 # Add xorg package
438 # Add xorg package
428 if [ "$ENABLE_XORG" = true ] ; then
439 if [ "$ENABLE_XORG" = true ] ; then
429 APT_INCLUDES="${APT_INCLUDES},xorg"
440 APT_INCLUDES="${APT_INCLUDES},xorg"
430 fi
441 fi
431
442
432 # Replace selected packages with smaller clones
443 # Replace selected packages with smaller clones
433 if [ "$ENABLE_REDUCE" = true ] ; then
444 if [ "$ENABLE_REDUCE" = true ] ; then
434 # Add levee package instead of vim-tiny
445 # Add levee package instead of vim-tiny
435 if [ "$REDUCE_VIM" = true ] ; then
446 if [ "$REDUCE_VIM" = true ] ; then
436 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
447 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
437 fi
448 fi
438
449
439 # Add dropbear package instead of openssh-server
450 # Add dropbear package instead of openssh-server
440 if [ "$REDUCE_SSHD" = true ] ; then
451 if [ "$REDUCE_SSHD" = true ] ; then
441 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
452 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
442 fi
453 fi
443 fi
454 fi
444
455
445 # Configure kernel sources if no KERNELSRC_DIR
456 # Configure kernel sources if no KERNELSRC_DIR
446 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
457 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
447 KERNELSRC_CONFIG=true
458 KERNELSRC_CONFIG=true
448 fi
459 fi
449
460
450 # Configure reduced kernel
461 # Configure reduced kernel
451 if [ "$KERNEL_REDUCE" = true ] ; then
462 if [ "$KERNEL_REDUCE" = true ] ; then
452 KERNELSRC_CONFIG=false
463 KERNELSRC_CONFIG=false
453 fi
464 fi
454
465
455 # Execute bootstrap scripts
466 # Execute bootstrap scripts
456 for SCRIPT in bootstrap.d/*.sh; do
467 for SCRIPT in bootstrap.d/*.sh; do
457 head -n 3 "$SCRIPT"
468 head -n 3 "$SCRIPT"
458 . "$SCRIPT"
469 . "$SCRIPT"
459 done
470 done
460
471
461 ## Execute custom bootstrap scripts
472 ## Execute custom bootstrap scripts
462 if [ -d "custom.d" ] ; then
473 if [ -d "custom.d" ] ; then
463 for SCRIPT in custom.d/*.sh; do
474 for SCRIPT in custom.d/*.sh; do
464 . "$SCRIPT"
475 . "$SCRIPT"
465 done
476 done
466 fi
477 fi
467
478
468 # Execute custom scripts inside the chroot
479 # Execute custom scripts inside the chroot
469 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
480 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
470 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
481 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
471 chroot_exec /bin/bash -x <<'EOF'
482 chroot_exec /bin/bash -x <<'EOF'
472 for SCRIPT in /chroot_scripts/* ; do
483 for SCRIPT in /chroot_scripts/* ; do
473 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
484 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
474 $SCRIPT
485 $SCRIPT
475 fi
486 fi
476 done
487 done
477 EOF
488 EOF
478 rm -rf "${R}/chroot_scripts"
489 rm -rf "${R}/chroot_scripts"
479 fi
490 fi
480
491
481 # Remove c/c++ build environment from the chroot
492 # Remove c/c++ build environment from the chroot
482 chroot_remove_cc
493 chroot_remove_cc
483
494
484 # Remove apt-utils
495 # Remove apt-utils
485 if [ "$RELEASE" = "jessie" ] ; then
496 if [ "$RELEASE" = "jessie" ] ; then
486 chroot_exec apt-get purge -qq -y --force-yes apt-utils
497 chroot_exec apt-get purge -qq -y --force-yes apt-utils
487 fi
498 fi
488
499
489 # Generate required machine-id
500 # Generate required machine-id
490 MACHINE_ID=$(dbus-uuidgen)
501 MACHINE_ID=$(dbus-uuidgen)
491 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
502 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
492 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
503 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
493
504
494 # APT Cleanup
505 # APT Cleanup
495 chroot_exec apt-get -y clean
506 chroot_exec apt-get -y clean
496 chroot_exec apt-get -y autoclean
507 chroot_exec apt-get -y autoclean
497 chroot_exec apt-get -y autoremove
508 chroot_exec apt-get -y autoremove
498
509
499 # Unmount mounted filesystems
510 # Unmount mounted filesystems
500 umount -l "${R}/proc"
511 umount -l "${R}/proc"
501 umount -l "${R}/sys"
512 umount -l "${R}/sys"
502
513
503 # Clean up directories
514 # Clean up directories
504 rm -rf "${R}/run/*"
515 rm -rf "${R}/run/*"
505 rm -rf "${R}/tmp/*"
516 rm -rf "${R}/tmp/*"
506
517
507 # Clean up files
518 # Clean up files
508 rm -f "${ETC_DIR}/ssh/ssh_host_*"
519 rm -f "${ETC_DIR}/ssh/ssh_host_*"
509 rm -f "${ETC_DIR}/dropbear/dropbear_*"
520 rm -f "${ETC_DIR}/dropbear/dropbear_*"
510 rm -f "${ETC_DIR}/apt/sources.list.save"
521 rm -f "${ETC_DIR}/apt/sources.list.save"
511 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
522 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
512 rm -f "${ETC_DIR}/*-"
523 rm -f "${ETC_DIR}/*-"
513 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
524 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
514 rm -f "${ETC_DIR}/resolv.conf"
525 rm -f "${ETC_DIR}/resolv.conf"
515 rm -f "${R}/root/.bash_history"
526 rm -f "${R}/root/.bash_history"
516 rm -f "${R}/var/lib/urandom/random-seed"
527 rm -f "${R}/var/lib/urandom/random-seed"
517 rm -f "${R}/initrd.img"
528 rm -f "${R}/initrd.img"
518 rm -f "${R}/vmlinuz"
529 rm -f "${R}/vmlinuz"
519 rm -f "${R}${QEMU_BINARY}"
530 rm -f "${R}${QEMU_BINARY}"
520
531
521 # Calculate size of the chroot directory in KB
532 # Calculate size of the chroot directory in KB
522 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
533 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
523
534
524 # Calculate the amount of needed 512 Byte sectors
535 # Calculate the amount of needed 512 Byte sectors
525 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
536 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
526 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
537 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
527 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
538 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
528
539
529 # The root partition is EXT4
540 # The root partition is EXT4
530 # This means more space than the actual used space of the chroot is used.
541 # This means more space than the actual used space of the chroot is used.
531 # As overhead for journaling and reserved blocks 25% are added.
542 # As overhead for journaling and reserved blocks 25% are added.
532 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 25) \* 1024 \/ 512)
543 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 25) \* 1024 \/ 512)
533
544
534 # Calculate required image size in 512 Byte sectors
545 # Calculate required image size in 512 Byte sectors
535 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
546 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
536
547
537 # Prepare image file
548 # Prepare image file
538 if [ "$ENABLE_SPLITFS" = true ] ; then
549 if [ "$ENABLE_SPLITFS" = true ] ; then
539 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
550 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
540 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
551 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
541 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
552 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
542 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
553 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
543
554
544 # Write firmware/boot partition tables
555 # Write firmware/boot partition tables
545 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
556 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
546 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
557 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
547 EOM
558 EOM
548
559
549 # Write root partition table
560 # Write root partition table
550 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
561 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
551 ${TABLE_SECTORS},${ROOT_SECTORS},83
562 ${TABLE_SECTORS},${ROOT_SECTORS},83
552 EOM
563 EOM
553
564
554 # Setup temporary loop devices
565 # Setup temporary loop devices
555 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
566 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
556 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
567 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
557 else # ENABLE_SPLITFS=false
568 else # ENABLE_SPLITFS=false
558 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
569 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
559 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
570 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
560
571
561 # Write partition table
572 # Write partition table
562 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
573 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
563 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
574 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
564 ${ROOT_OFFSET},${ROOT_SECTORS},83
575 ${ROOT_OFFSET},${ROOT_SECTORS},83
565 EOM
576 EOM
566
577
567 # Setup temporary loop devices
578 # Setup temporary loop devices
568 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
579 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
569 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
580 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
570 fi
581 fi
571
582
572 if [ "$ENABLE_CRYPTFS" = true ] ; then
583 if [ "$ENABLE_CRYPTFS" = true ] ; then
573 # Create dummy ext4 fs
584 # Create dummy ext4 fs
574 mkfs.ext4 "$ROOT_LOOP"
585 mkfs.ext4 "$ROOT_LOOP"
575
586
576 # Setup password keyfile
587 # Setup password keyfile
577 touch .password
588 touch .password
578 chmod 600 .password
589 chmod 600 .password
579 echo -n ${CRYPTFS_PASSWORD} > .password
590 echo -n ${CRYPTFS_PASSWORD} > .password
580
591
581 # Initialize encrypted partition
592 # Initialize encrypted partition
582 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
593 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
583
594
584 # Open encrypted partition and setup mapping
595 # Open encrypted partition and setup mapping
585 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
596 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
586
597
587 # Secure delete password keyfile
598 # Secure delete password keyfile
588 shred -zu .password
599 shred -zu .password
589
600
590 # Update temporary loop device
601 # Update temporary loop device
591 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
602 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
592
603
593 # Wipe encrypted partition (encryption cipher is used for randomness)
604 # Wipe encrypted partition (encryption cipher is used for randomness)
594 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
605 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
595 fi
606 fi
596
607
597 # Build filesystems
608 # Build filesystems
598 mkfs.vfat "$FRMW_LOOP"
609 mkfs.vfat "$FRMW_LOOP"
599 mkfs.ext4 "$ROOT_LOOP"
610 mkfs.ext4 "$ROOT_LOOP"
600
611
601 # Mount the temporary loop devices
612 # Mount the temporary loop devices
602 mkdir -p "$BUILDDIR/mount"
613 mkdir -p "$BUILDDIR/mount"
603 mount "$ROOT_LOOP" "$BUILDDIR/mount"
614 mount "$ROOT_LOOP" "$BUILDDIR/mount"
604
615
605 mkdir -p "$BUILDDIR/mount/boot/firmware"
616 mkdir -p "$BUILDDIR/mount/boot/firmware"
606 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
617 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
607
618
608 # Copy all files from the chroot to the loop device mount point directory
619 # Copy all files from the chroot to the loop device mount point directory
609 rsync -a "${R}/" "$BUILDDIR/mount/"
620 rsync -a "${R}/" "$BUILDDIR/mount/"
610
621
611 # Unmount all temporary loop devices and mount points
622 # Unmount all temporary loop devices and mount points
612 cleanup
623 cleanup
613
624
614 # Create block map file(s) of image(s)
625 # Create block map file(s) of image(s)
615 if [ "$ENABLE_SPLITFS" = true ] ; then
626 if [ "$ENABLE_SPLITFS" = true ] ; then
616 # Create block map files for "bmaptool"
627 # Create block map files for "bmaptool"
617 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
628 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
618 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
629 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
619
630
620 # Image was successfully created
631 # Image was successfully created
621 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
632 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
622 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
633 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
623 else
634 else
624 # Create block map file for "bmaptool"
635 # Create block map file for "bmaptool"
625 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
636 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
626
637
627 # Image was successfully created
638 # Image was successfully created
628 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
639 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
629 fi
640 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant