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