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