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