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