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