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