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