@@ -1,520 +1,520 | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 |
|
2 | |||
3 | ######################################################################## |
|
3 | ######################################################################## | |
4 | # rpi2-gen-image.sh 2015-2016 |
|
4 | # rpi2-gen-image.sh 2015-2016 | |
5 | # |
|
5 | # | |
6 | # Advanced debian "jessie" bootstrap script for RPi2 |
|
6 | # Advanced debian "jessie" bootstrap script for RPi2 | |
7 | # |
|
7 | # | |
8 | # This program is free software; you can redistribute it and/or |
|
8 | # This program is free software; you can redistribute it and/or | |
9 | # modify it under the terms of the GNU General Public License |
|
9 | # modify it under the terms of the GNU General Public License | |
10 | # as published by the Free Software Foundation; either version 2 |
|
10 | # as published by the Free Software Foundation; either version 2 | |
11 | # of the License, or (at your option) any later version. |
|
11 | # of the License, or (at your option) any later version. | |
12 | # |
|
12 | # | |
13 | # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu> |
|
13 | # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu> | |
14 | # |
|
14 | # | |
15 | # Big thanks for patches and enhancements by 10+ github contributors! |
|
15 | # Big thanks for patches and enhancements by 10+ github contributors! | |
16 | ######################################################################## |
|
16 | ######################################################################## | |
17 |
|
17 | |||
18 | # Are we running as root? |
|
18 | # Are we running as root? | |
19 | if [ "$(id -u)" -ne "0" ] ; then |
|
19 | if [ "$(id -u)" -ne "0" ] ; then | |
20 | echo "error: this script must be executed with root privileges!" |
|
20 | echo "error: this script must be executed with root privileges!" | |
21 | exit 1 |
|
21 | exit 1 | |
22 | fi |
|
22 | fi | |
23 |
|
23 | |||
24 | # Check if ./functions.sh script exists |
|
24 | # Check if ./functions.sh script exists | |
25 | if [ ! -r "./functions.sh" ] ; then |
|
25 | if [ ! -r "./functions.sh" ] ; then | |
26 | echo "error: './functions.sh' required script not found!" |
|
26 | echo "error: './functions.sh' required script not found!" | |
27 | exit 1 |
|
27 | exit 1 | |
28 | fi |
|
28 | fi | |
29 |
|
29 | |||
30 | # Load utility functions |
|
30 | # Load utility functions | |
31 | . ./functions.sh |
|
31 | . ./functions.sh | |
32 |
|
32 | |||
33 | # Introduce settings |
|
33 | # Introduce settings | |
34 | set -e |
|
34 | set -e | |
35 | echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n" |
|
35 | echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n" | |
36 | set -x |
|
36 | set -x | |
37 |
|
37 | |||
38 | # Debian release |
|
38 | # Debian release | |
39 | RELEASE=${RELEASE:=jessie} |
|
39 | RELEASE=${RELEASE:=jessie} | |
40 | KERNEL_ARCH=${KERNEL_ARCH:=arm} |
|
40 | KERNEL_ARCH=${KERNEL_ARCH:=arm} | |
41 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} |
|
41 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} | |
42 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} |
|
42 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} | |
43 | COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} |
|
43 | COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} | |
44 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} |
|
44 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} | |
45 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} |
|
45 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} | |
46 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} |
|
46 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} | |
47 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} |
|
47 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} | |
48 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} |
|
48 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} | |
49 |
|
49 | |||
50 | # Build directories |
|
50 | # Build directories | |
51 | BASEDIR="$(pwd)/images/${RELEASE}" |
|
51 | BASEDIR="$(pwd)/images/${RELEASE}" | |
52 | BUILDDIR="${BASEDIR}/build" |
|
52 | BUILDDIR="${BASEDIR}/build" | |
53 |
|
53 | |||
54 | # Chroot directories |
|
54 | # Chroot directories | |
55 | R="${BUILDDIR}/chroot" |
|
55 | R="${BUILDDIR}/chroot" | |
56 | ETCDIR="${R}/etc" |
|
56 | ETCDIR="${R}/etc" | |
57 | BOOTDIR="${R}/boot/firmware" |
|
57 | BOOTDIR="${R}/boot/firmware" | |
58 | KERNELDIR="${R}/usr/src/linux" |
|
58 | KERNELDIR="${R}/usr/src/linux" | |
59 |
|
59 | |||
60 | # Firmware directory: Blank if download from github |
|
60 | # Firmware directory: Blank if download from github | |
61 | FIRMWAREDIR=${FIRMWAREDIR:=""} |
|
61 | FIRMWAREDIR=${FIRMWAREDIR:=""} | |
62 |
|
62 | |||
63 | # General settings |
|
63 | # General settings | |
64 | HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}} |
|
64 | HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}} | |
65 | PASSWORD=${PASSWORD:=raspberry} |
|
65 | PASSWORD=${PASSWORD:=raspberry} | |
66 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} |
|
66 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} | |
67 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} |
|
67 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} | |
68 | EXPANDROOT=${EXPANDROOT:=true} |
|
68 | EXPANDROOT=${EXPANDROOT:=true} | |
69 |
|
69 | |||
70 | # Keyboard settings |
|
70 | # Keyboard settings | |
71 | XKB_MODEL=${XKB_MODEL:=""} |
|
71 | XKB_MODEL=${XKB_MODEL:=""} | |
72 | XKB_LAYOUT=${XKB_LAYOUT:=""} |
|
72 | XKB_LAYOUT=${XKB_LAYOUT:=""} | |
73 | XKB_VARIANT=${XKB_VARIANT:=""} |
|
73 | XKB_VARIANT=${XKB_VARIANT:=""} | |
74 | XKB_OPTIONS=${XKB_OPTIONS:=""} |
|
74 | XKB_OPTIONS=${XKB_OPTIONS:=""} | |
75 |
|
75 | |||
76 | # Network settings (DHCP) |
|
76 | # Network settings (DHCP) | |
77 | ENABLE_DHCP=${ENABLE_DHCP:=true} |
|
77 | ENABLE_DHCP=${ENABLE_DHCP:=true} | |
78 |
|
78 | |||
79 | # Network settings (static) |
|
79 | # Network settings (static) | |
80 | NET_ADDRESS=${NET_ADDRESS:=""} |
|
80 | NET_ADDRESS=${NET_ADDRESS:=""} | |
81 | NET_GATEWAY=${NET_GATEWAY:=""} |
|
81 | NET_GATEWAY=${NET_GATEWAY:=""} | |
82 | NET_DNS_1=${NET_DNS_1:=""} |
|
82 | NET_DNS_1=${NET_DNS_1:=""} | |
83 | NET_DNS_2=${NET_DNS_2:=""} |
|
83 | NET_DNS_2=${NET_DNS_2:=""} | |
84 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} |
|
84 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} | |
85 | NET_NTP_1=${NET_NTP_1:=""} |
|
85 | NET_NTP_1=${NET_NTP_1:=""} | |
86 | NET_NTP_2=${NET_NTP_2:=""} |
|
86 | NET_NTP_2=${NET_NTP_2:=""} | |
87 |
|
87 | |||
88 | # APT settings |
|
88 | # APT settings | |
89 | APT_PROXY=${APT_PROXY:=""} |
|
89 | APT_PROXY=${APT_PROXY:=""} | |
90 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} |
|
90 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} | |
91 |
|
91 | |||
92 | # Feature settings |
|
92 | # Feature settings | |
93 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} |
|
93 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} | |
94 | ENABLE_IPV6=${ENABLE_IPV6:=true} |
|
94 | ENABLE_IPV6=${ENABLE_IPV6:=true} | |
95 | ENABLE_SSHD=${ENABLE_SSHD:=true} |
|
95 | ENABLE_SSHD=${ENABLE_SSHD:=true} | |
96 | ENABLE_SOUND=${ENABLE_SOUND:=true} |
|
96 | ENABLE_SOUND=${ENABLE_SOUND:=true} | |
97 | ENABLE_DBUS=${ENABLE_DBUS:=true} |
|
97 | ENABLE_DBUS=${ENABLE_DBUS:=true} | |
98 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} |
|
98 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} | |
99 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} |
|
99 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} | |
100 | ENABLE_XORG=${ENABLE_XORG:=false} |
|
100 | ENABLE_XORG=${ENABLE_XORG:=false} | |
101 | ENABLE_WM=${ENABLE_WM:=""} |
|
101 | ENABLE_WM=${ENABLE_WM:=""} | |
102 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} |
|
102 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} | |
103 | ENABLE_USER=${ENABLE_USER:=true} |
|
103 | ENABLE_USER=${ENABLE_USER:=true} | |
104 | USER_NAME=${USER_NAME:="pi"} |
|
104 | USER_NAME=${USER_NAME:="pi"} | |
105 | ENABLE_ROOT=${ENABLE_ROOT:=false} |
|
105 | ENABLE_ROOT=${ENABLE_ROOT:=false} | |
106 | ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false} |
|
106 | ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false} | |
107 |
|
107 | |||
108 | # Advanced settings |
|
108 | # Advanced settings | |
109 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} |
|
109 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} | |
110 |
ENABLE_REDUCE=${ENABLE_REDUCE:=f |
|
110 | ENABLE_REDUCE=${ENABLE_REDUCE:=false} | |
111 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} |
|
111 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} | |
112 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} |
|
112 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} | |
113 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} |
|
113 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} | |
114 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} |
|
114 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} | |
115 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} |
|
115 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} | |
116 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} |
|
116 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} | |
117 |
|
117 | |||
118 | # Kernel compilation settings |
|
118 | # Kernel compilation settings | |
119 | BUILD_KERNEL=${BUILD_KERNEL:=false} |
|
119 | BUILD_KERNEL=${BUILD_KERNEL:=false} | |
120 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} |
|
120 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} | |
121 | KERNEL_THREADS=${KERNEL_THREADS:=1} |
|
121 | KERNEL_THREADS=${KERNEL_THREADS:=1} | |
122 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} |
|
122 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} | |
123 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} |
|
123 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} | |
124 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} |
|
124 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} | |
125 |
|
125 | |||
126 | # Kernel compilation from source directory settings |
|
126 | # Kernel compilation from source directory settings | |
127 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} |
|
127 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} | |
128 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} |
|
128 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} | |
129 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} |
|
129 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} | |
130 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} |
|
130 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} | |
131 |
|
131 | |||
132 | # Reduce disk usage settings |
|
132 | # Reduce disk usage settings | |
133 | REDUCE_APT=${REDUCE_APT:=true} |
|
133 | REDUCE_APT=${REDUCE_APT:=true} | |
134 | REDUCE_DOC=${REDUCE_DOC:=true} |
|
134 | REDUCE_DOC=${REDUCE_DOC:=true} | |
135 | REDUCE_MAN=${REDUCE_MAN:=true} |
|
135 | REDUCE_MAN=${REDUCE_MAN:=true} | |
136 | REDUCE_VIM=${REDUCE_VIM:=false} |
|
136 | REDUCE_VIM=${REDUCE_VIM:=false} | |
137 | REDUCE_BASH=${REDUCE_BASH:=false} |
|
137 | REDUCE_BASH=${REDUCE_BASH:=false} | |
138 | REDUCE_HWDB=${REDUCE_HWDB:=true} |
|
138 | REDUCE_HWDB=${REDUCE_HWDB:=true} | |
139 | REDUCE_SSHD=${REDUCE_SSHD:=true} |
|
139 | REDUCE_SSHD=${REDUCE_SSHD:=true} | |
140 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} |
|
140 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} | |
141 |
|
141 | |||
142 | # Encrypted filesystem settings |
|
142 | # Encrypted filesystem settings | |
143 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} |
|
143 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} | |
144 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} |
|
144 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} | |
145 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} |
|
145 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} | |
146 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} |
|
146 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} | |
147 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} |
|
147 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} | |
148 |
|
148 | |||
149 | # Stop the Crypto Wars |
|
149 | # Stop the Crypto Wars | |
150 | DISABLE_FBI=${DISABLE_FBI:=false} |
|
150 | DISABLE_FBI=${DISABLE_FBI:=false} | |
151 |
|
151 | |||
152 | # Chroot scripts directory |
|
152 | # Chroot scripts directory | |
153 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} |
|
153 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} | |
154 |
|
154 | |||
155 | # Packages required in the chroot build environment |
|
155 | # Packages required in the chroot build environment | |
156 | APT_INCLUDES=${APT_INCLUDES:=""} |
|
156 | APT_INCLUDES=${APT_INCLUDES:=""} | |
157 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo" |
|
157 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo" | |
158 |
|
158 | |||
159 | # Packages required for bootstrapping |
|
159 | # Packages required for bootstrapping | |
160 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git" |
|
160 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git" | |
161 | MISSING_PACKAGES="" |
|
161 | MISSING_PACKAGES="" | |
162 |
|
162 | |||
163 | set +x |
|
163 | set +x | |
164 |
|
164 | |||
165 | # Add packages required for kernel cross compilation |
|
165 | # Add packages required for kernel cross compilation | |
166 | if [ "$BUILD_KERNEL" = true ] ; then |
|
166 | if [ "$BUILD_KERNEL" = true ] ; then | |
167 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" |
|
167 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" | |
168 | fi |
|
168 | fi | |
169 |
|
169 | |||
170 | # Add libncurses5 to enable kernel menuconfig |
|
170 | # Add libncurses5 to enable kernel menuconfig | |
171 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
171 | if [ "$KERNEL_MENUCONFIG" = true ] ; then | |
172 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev" |
|
172 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev" | |
173 | fi |
|
173 | fi | |
174 |
|
174 | |||
175 | # Stop the Crypto Wars |
|
175 | # Stop the Crypto Wars | |
176 | if [ "$DISABLE_FBI" = true ] ; then |
|
176 | if [ "$DISABLE_FBI" = true ] ; then | |
177 | ENABLE_CRYPTFS=true |
|
177 | ENABLE_CRYPTFS=true | |
178 | fi |
|
178 | fi | |
179 |
|
179 | |||
180 | # Add cryptsetup package to enable filesystem encryption |
|
180 | # Add cryptsetup package to enable filesystem encryption | |
181 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
181 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | |
182 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" |
|
182 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" | |
183 | APT_INCLUDES="${APT_INCLUDES},cryptsetup" |
|
183 | APT_INCLUDES="${APT_INCLUDES},cryptsetup" | |
184 |
|
184 | |||
185 | if [ -z "$CRYPTFS_PASSWORD" ] ; then |
|
185 | if [ -z "$CRYPTFS_PASSWORD" ] ; then | |
186 | echo "error: no password defined (CRYPTFS_PASSWORD)!" |
|
186 | echo "error: no password defined (CRYPTFS_PASSWORD)!" | |
187 | exit 1 |
|
187 | exit 1 | |
188 | fi |
|
188 | fi | |
189 | ENABLE_INITRAMFS=true |
|
189 | ENABLE_INITRAMFS=true | |
190 | fi |
|
190 | fi | |
191 |
|
191 | |||
192 | # Add initramfs generation tools |
|
192 | # Add initramfs generation tools | |
193 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
193 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then | |
194 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" |
|
194 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" | |
195 | fi |
|
195 | fi | |
196 |
|
196 | |||
197 | # Check if all required packages are installed on the build system |
|
197 | # Check if all required packages are installed on the build system | |
198 | for package in $REQUIRED_PACKAGES ; do |
|
198 | for package in $REQUIRED_PACKAGES ; do | |
199 | if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then |
|
199 | if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then | |
200 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" |
|
200 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" | |
201 | fi |
|
201 | fi | |
202 | done |
|
202 | done | |
203 |
|
203 | |||
204 | # Ask if missing packages should get installed right now |
|
204 | # Ask if missing packages should get installed right now | |
205 | if [ -n "$MISSING_PACKAGES" ] ; then |
|
205 | if [ -n "$MISSING_PACKAGES" ] ; then | |
206 | echo "the following packages needed by this script are not installed:" |
|
206 | echo "the following packages needed by this script are not installed:" | |
207 | echo "$MISSING_PACKAGES" |
|
207 | echo "$MISSING_PACKAGES" | |
208 |
|
208 | |||
209 | echo -n "\ndo you want to install the missing packages right now? [y/n] " |
|
209 | echo -n "\ndo you want to install the missing packages right now? [y/n] " | |
210 | read confirm |
|
210 | read confirm | |
211 | [ "$confirm" != "y" ] && exit 1 |
|
211 | [ "$confirm" != "y" ] && exit 1 | |
212 | fi |
|
212 | fi | |
213 |
|
213 | |||
214 | # Make sure all required packages are installed |
|
214 | # Make sure all required packages are installed | |
215 | apt-get -qq -y install ${REQUIRED_PACKAGES} |
|
215 | apt-get -qq -y install ${REQUIRED_PACKAGES} | |
216 |
|
216 | |||
217 | # Check if ./bootstrap.d directory exists |
|
217 | # Check if ./bootstrap.d directory exists | |
218 | if [ ! -d "./bootstrap.d/" ] ; then |
|
218 | if [ ! -d "./bootstrap.d/" ] ; then | |
219 | echo "error: './bootstrap.d' required directory not found!" |
|
219 | echo "error: './bootstrap.d' required directory not found!" | |
220 | exit 1 |
|
220 | exit 1 | |
221 | fi |
|
221 | fi | |
222 |
|
222 | |||
223 | # Check if ./files directory exists |
|
223 | # Check if ./files directory exists | |
224 | if [ ! -d "./files/" ] ; then |
|
224 | if [ ! -d "./files/" ] ; then | |
225 | echo "error: './files' required directory not found!" |
|
225 | echo "error: './files' required directory not found!" | |
226 | exit 1 |
|
226 | exit 1 | |
227 | fi |
|
227 | fi | |
228 |
|
228 | |||
229 | # Check if specified KERNELSRC_DIR directory exists |
|
229 | # Check if specified KERNELSRC_DIR directory exists | |
230 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then |
|
230 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then | |
231 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" |
|
231 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" | |
232 | exit 1 |
|
232 | exit 1 | |
233 | fi |
|
233 | fi | |
234 |
|
234 | |||
235 | # Check if specified CHROOT_SCRIPTS directory exists |
|
235 | # Check if specified CHROOT_SCRIPTS directory exists | |
236 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then |
|
236 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then | |
237 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" |
|
237 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" | |
238 | exit 1 |
|
238 | exit 1 | |
239 | fi |
|
239 | fi | |
240 |
|
240 | |||
241 | # Check if specified device mapping already exists (will be used by cryptsetup) |
|
241 | # Check if specified device mapping already exists (will be used by cryptsetup) | |
242 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then |
|
242 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then | |
243 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" |
|
243 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" | |
244 | exit 1 |
|
244 | exit 1 | |
245 | fi |
|
245 | fi | |
246 |
|
246 | |||
247 | # Don't clobber an old build |
|
247 | # Don't clobber an old build | |
248 | if [ -e "$BUILDDIR" ] ; then |
|
248 | if [ -e "$BUILDDIR" ] ; then | |
249 | echo "error: directory ${BUILDDIR} already exists, not proceeding" |
|
249 | echo "error: directory ${BUILDDIR} already exists, not proceeding" | |
250 | exit 1 |
|
250 | exit 1 | |
251 | fi |
|
251 | fi | |
252 |
|
252 | |||
253 | # Setup chroot directory |
|
253 | # Setup chroot directory | |
254 | mkdir -p "${R}" |
|
254 | mkdir -p "${R}" | |
255 |
|
255 | |||
256 | # Check if build directory has enough of free disk space >512MB |
|
256 | # Check if build directory has enough of free disk space >512MB | |
257 | if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then |
|
257 | if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then | |
258 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" |
|
258 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" | |
259 | exit 1 |
|
259 | exit 1 | |
260 | fi |
|
260 | fi | |
261 |
|
261 | |||
262 | set -x |
|
262 | set -x | |
263 |
|
263 | |||
264 | # Call "cleanup" function on various signals and errors |
|
264 | # Call "cleanup" function on various signals and errors | |
265 | trap cleanup 0 1 2 3 6 |
|
265 | trap cleanup 0 1 2 3 6 | |
266 |
|
266 | |||
267 | # Add required packages for the minbase installation |
|
267 | # Add required packages for the minbase installation | |
268 | if [ "$ENABLE_MINBASE" = true ] ; then |
|
268 | if [ "$ENABLE_MINBASE" = true ] ; then | |
269 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" |
|
269 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" | |
270 | fi |
|
270 | fi | |
271 |
|
271 | |||
272 | # Add required locales packages |
|
272 | # Add required locales packages | |
273 | if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then |
|
273 | if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then | |
274 | APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup" |
|
274 | APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup" | |
275 | fi |
|
275 | fi | |
276 |
|
276 | |||
277 | # Add parted package, required to get partprobe utility |
|
277 | # Add parted package, required to get partprobe utility | |
278 | if [ "$EXPANDROOT" = true ] ; then |
|
278 | if [ "$EXPANDROOT" = true ] ; then | |
279 | APT_INCLUDES="${APT_INCLUDES},parted" |
|
279 | APT_INCLUDES="${APT_INCLUDES},parted" | |
280 | fi |
|
280 | fi | |
281 |
|
281 | |||
282 | # Add dbus package, recommended if using systemd |
|
282 | # Add dbus package, recommended if using systemd | |
283 | if [ "$ENABLE_DBUS" = true ] ; then |
|
283 | if [ "$ENABLE_DBUS" = true ] ; then | |
284 | APT_INCLUDES="${APT_INCLUDES},dbus" |
|
284 | APT_INCLUDES="${APT_INCLUDES},dbus" | |
285 | fi |
|
285 | fi | |
286 |
|
286 | |||
287 | # Add iptables IPv4/IPv6 package |
|
287 | # Add iptables IPv4/IPv6 package | |
288 | if [ "$ENABLE_IPTABLES" = true ] ; then |
|
288 | if [ "$ENABLE_IPTABLES" = true ] ; then | |
289 | APT_INCLUDES="${APT_INCLUDES},iptables" |
|
289 | APT_INCLUDES="${APT_INCLUDES},iptables" | |
290 | fi |
|
290 | fi | |
291 |
|
291 | |||
292 | # Add openssh server package |
|
292 | # Add openssh server package | |
293 | if [ "$ENABLE_SSHD" = true ] ; then |
|
293 | if [ "$ENABLE_SSHD" = true ] ; then | |
294 | APT_INCLUDES="${APT_INCLUDES},openssh-server" |
|
294 | APT_INCLUDES="${APT_INCLUDES},openssh-server" | |
295 | fi |
|
295 | fi | |
296 |
|
296 | |||
297 | # Add alsa-utils package |
|
297 | # Add alsa-utils package | |
298 | if [ "$ENABLE_SOUND" = true ] ; then |
|
298 | if [ "$ENABLE_SOUND" = true ] ; then | |
299 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" |
|
299 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" | |
300 | fi |
|
300 | fi | |
301 |
|
301 | |||
302 | # Add rng-tools package |
|
302 | # Add rng-tools package | |
303 | if [ "$ENABLE_HWRANDOM" = true ] ; then |
|
303 | if [ "$ENABLE_HWRANDOM" = true ] ; then | |
304 | APT_INCLUDES="${APT_INCLUDES},rng-tools" |
|
304 | APT_INCLUDES="${APT_INCLUDES},rng-tools" | |
305 | fi |
|
305 | fi | |
306 |
|
306 | |||
307 | # Add fbturbo video driver |
|
307 | # Add fbturbo video driver | |
308 | if [ "$ENABLE_FBTURBO" = true ] ; then |
|
308 | if [ "$ENABLE_FBTURBO" = true ] ; then | |
309 | # Enable xorg package dependencies |
|
309 | # Enable xorg package dependencies | |
310 | ENABLE_XORG=true |
|
310 | ENABLE_XORG=true | |
311 | fi |
|
311 | fi | |
312 |
|
312 | |||
313 | # Add user defined window manager package |
|
313 | # Add user defined window manager package | |
314 | if [ -n "$ENABLE_WM" ] ; then |
|
314 | if [ -n "$ENABLE_WM" ] ; then | |
315 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" |
|
315 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" | |
316 |
|
316 | |||
317 | # Enable xorg package dependencies |
|
317 | # Enable xorg package dependencies | |
318 | ENABLE_XORG=true |
|
318 | ENABLE_XORG=true | |
319 | fi |
|
319 | fi | |
320 |
|
320 | |||
321 | # Add xorg package |
|
321 | # Add xorg package | |
322 | if [ "$ENABLE_XORG" = true ] ; then |
|
322 | if [ "$ENABLE_XORG" = true ] ; then | |
323 | APT_INCLUDES="${APT_INCLUDES},xorg" |
|
323 | APT_INCLUDES="${APT_INCLUDES},xorg" | |
324 | fi |
|
324 | fi | |
325 |
|
325 | |||
326 | # Replace selected packages with smaller clones |
|
326 | # Replace selected packages with smaller clones | |
327 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
327 | if [ "$ENABLE_REDUCE" = true ] ; then | |
328 | # Add levee package instead of vim-tiny |
|
328 | # Add levee package instead of vim-tiny | |
329 | if [ "$REDUCE_VIM" = true ] ; then |
|
329 | if [ "$REDUCE_VIM" = true ] ; then | |
330 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" |
|
330 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" | |
331 | fi |
|
331 | fi | |
332 |
|
332 | |||
333 | # Add dropbear package instead of openssh-server |
|
333 | # Add dropbear package instead of openssh-server | |
334 | if [ "$REDUCE_SSHD" = true ] ; then |
|
334 | if [ "$REDUCE_SSHD" = true ] ; then | |
335 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")" |
|
335 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")" | |
336 | fi |
|
336 | fi | |
337 | fi |
|
337 | fi | |
338 |
|
338 | |||
339 | # Configure kernel sources if no KERNELSRC_DIR |
|
339 | # Configure kernel sources if no KERNELSRC_DIR | |
340 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then |
|
340 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then | |
341 | KERNELSRC_CONFIG=true |
|
341 | KERNELSRC_CONFIG=true | |
342 | fi |
|
342 | fi | |
343 |
|
343 | |||
344 | # Configure reduced kernel |
|
344 | # Configure reduced kernel | |
345 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
345 | if [ "$KERNEL_REDUCE" = true ] ; then | |
346 | KERNELSRC_CONFIG=false |
|
346 | KERNELSRC_CONFIG=false | |
347 | fi |
|
347 | fi | |
348 |
|
348 | |||
349 | # Execute bootstrap scripts |
|
349 | # Execute bootstrap scripts | |
350 | for SCRIPT in bootstrap.d/*.sh; do |
|
350 | for SCRIPT in bootstrap.d/*.sh; do | |
351 | head -n 3 "$SCRIPT" |
|
351 | head -n 3 "$SCRIPT" | |
352 | . "$SCRIPT" |
|
352 | . "$SCRIPT" | |
353 | done |
|
353 | done | |
354 |
|
354 | |||
355 | ## Execute custom bootstrap scripts |
|
355 | ## Execute custom bootstrap scripts | |
356 | if [ -d "custom.d" ] ; then |
|
356 | if [ -d "custom.d" ] ; then | |
357 | for SCRIPT in custom.d/*.sh; do |
|
357 | for SCRIPT in custom.d/*.sh; do | |
358 | . "$SCRIPT" |
|
358 | . "$SCRIPT" | |
359 | done |
|
359 | done | |
360 | fi |
|
360 | fi | |
361 |
|
361 | |||
362 | # Execute custom scripts inside the chroot |
|
362 | # Execute custom scripts inside the chroot | |
363 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then |
|
363 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then | |
364 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" |
|
364 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" | |
365 | chroot_exec /bin/bash -x <<'EOF' |
|
365 | chroot_exec /bin/bash -x <<'EOF' | |
366 | for SCRIPT in /chroot_scripts/* ; do |
|
366 | for SCRIPT in /chroot_scripts/* ; do | |
367 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then |
|
367 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then | |
368 | $SCRIPT |
|
368 | $SCRIPT | |
369 | fi |
|
369 | fi | |
370 | done |
|
370 | done | |
371 | EOF |
|
371 | EOF | |
372 | rm -rf "${R}/chroot_scripts" |
|
372 | rm -rf "${R}/chroot_scripts" | |
373 | fi |
|
373 | fi | |
374 |
|
374 | |||
375 | # Remove apt-utils |
|
375 | # Remove apt-utils | |
376 | chroot_exec apt-get purge -qq -y --force-yes apt-utils |
|
376 | chroot_exec apt-get purge -qq -y --force-yes apt-utils | |
377 |
|
377 | |||
378 | # Generate required machine-id |
|
378 | # Generate required machine-id | |
379 | MACHINE_ID=$(dbus-uuidgen) |
|
379 | MACHINE_ID=$(dbus-uuidgen) | |
380 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" |
|
380 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" | |
381 | echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id" |
|
381 | echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id" | |
382 |
|
382 | |||
383 | # APT Cleanup |
|
383 | # APT Cleanup | |
384 | chroot_exec apt-get -y clean |
|
384 | chroot_exec apt-get -y clean | |
385 | chroot_exec apt-get -y autoclean |
|
385 | chroot_exec apt-get -y autoclean | |
386 | chroot_exec apt-get -y autoremove |
|
386 | chroot_exec apt-get -y autoremove | |
387 |
|
387 | |||
388 | # Unmount mounted filesystems |
|
388 | # Unmount mounted filesystems | |
389 | umount -l "${R}/proc" |
|
389 | umount -l "${R}/proc" | |
390 | umount -l "${R}/sys" |
|
390 | umount -l "${R}/sys" | |
391 |
|
391 | |||
392 | # Clean up directories |
|
392 | # Clean up directories | |
393 | rm -rf "${R}/run/*" |
|
393 | rm -rf "${R}/run/*" | |
394 | rm -rf "${R}/tmp/*" |
|
394 | rm -rf "${R}/tmp/*" | |
395 |
|
395 | |||
396 | # Clean up files |
|
396 | # Clean up files | |
397 | rm -f "${ETCDIR}/ssh/ssh_host_*" |
|
397 | rm -f "${ETCDIR}/ssh/ssh_host_*" | |
398 | rm -f "${ETCDIR}/dropbear/dropbear_*" |
|
398 | rm -f "${ETCDIR}/dropbear/dropbear_*" | |
399 | rm -f "${ETCDIR}/apt/sources.list.save" |
|
399 | rm -f "${ETCDIR}/apt/sources.list.save" | |
400 | rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original" |
|
400 | rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original" | |
401 | rm -f "${ETCDIR}/*-" |
|
401 | rm -f "${ETCDIR}/*-" | |
402 | rm -f "${ETCDIR}/apt/apt.conf.d/10proxy" |
|
402 | rm -f "${ETCDIR}/apt/apt.conf.d/10proxy" | |
403 | rm -f "${ETCDIR}/resolv.conf" |
|
403 | rm -f "${ETCDIR}/resolv.conf" | |
404 | rm -f "${R}/root/.bash_history" |
|
404 | rm -f "${R}/root/.bash_history" | |
405 | rm -f "${R}/var/lib/urandom/random-seed" |
|
405 | rm -f "${R}/var/lib/urandom/random-seed" | |
406 | rm -f "${R}/initrd.img" |
|
406 | rm -f "${R}/initrd.img" | |
407 | rm -f "${R}/vmlinuz" |
|
407 | rm -f "${R}/vmlinuz" | |
408 | rm -f "${R}${QEMU_BINARY}" |
|
408 | rm -f "${R}${QEMU_BINARY}" | |
409 |
|
409 | |||
410 | # Calculate size of the chroot directory in KB |
|
410 | # Calculate size of the chroot directory in KB | |
411 | CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`) |
|
411 | CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`) | |
412 |
|
412 | |||
413 | # Calculate the amount of needed 512 Byte sectors |
|
413 | # Calculate the amount of needed 512 Byte sectors | |
414 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) |
|
414 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) | |
415 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) |
|
415 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) | |
416 | ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS}) |
|
416 | ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS}) | |
417 |
|
417 | |||
418 | # The root partition is EXT4 |
|
418 | # The root partition is EXT4 | |
419 | # This means more space than the actual used space of the chroot is used. |
|
419 | # This means more space than the actual used space of the chroot is used. | |
420 | # As overhead for journaling and reserved blocks 20% are added. |
|
420 | # As overhead for journaling and reserved blocks 20% are added. | |
421 | ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512) |
|
421 | ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512) | |
422 |
|
422 | |||
423 | # Calculate required image size in 512 Byte sectors |
|
423 | # Calculate required image size in 512 Byte sectors | |
424 | IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS}) |
|
424 | IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS}) | |
425 |
|
425 | |||
426 | # Prepare date string for image file name |
|
426 | # Prepare date string for image file name | |
427 | DATE="$(date +%Y-%m-%d)" |
|
427 | DATE="$(date +%Y-%m-%d)" | |
428 |
|
428 | |||
429 | # Prepare image file |
|
429 | # Prepare image file | |
430 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
430 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
431 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS} |
|
431 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS} | |
432 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS} |
|
432 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS} | |
433 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS} |
|
433 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS} | |
434 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS} |
|
434 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS} | |
435 |
|
435 | |||
436 | # Write firmware/boot partition tables |
|
436 | # Write firmware/boot partition tables | |
437 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM |
|
437 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM | |
438 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
438 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | |
439 | EOM |
|
439 | EOM | |
440 |
|
440 | |||
441 | # Write root partition table |
|
441 | # Write root partition table | |
442 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM |
|
442 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM | |
443 | ${TABLE_SECTORS},${ROOT_SECTORS},83 |
|
443 | ${TABLE_SECTORS},${ROOT_SECTORS},83 | |
444 | EOM |
|
444 | EOM | |
445 |
|
445 | |||
446 | # Setup temporary loop devices |
|
446 | # Setup temporary loop devices | |
447 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)" |
|
447 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)" | |
448 | ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)" |
|
448 | ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)" | |
449 | else # ENABLE_SPLITFS=false |
|
449 | else # ENABLE_SPLITFS=false | |
450 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} |
|
450 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} | |
451 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} |
|
451 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} | |
452 |
|
452 | |||
453 | # Write partition table |
|
453 | # Write partition table | |
454 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM |
|
454 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM | |
455 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
455 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* | |
456 | ${ROOT_OFFSET},${ROOT_SECTORS},83 |
|
456 | ${ROOT_OFFSET},${ROOT_SECTORS},83 | |
457 | EOM |
|
457 | EOM | |
458 |
|
458 | |||
459 | # Setup temporary loop devices |
|
459 | # Setup temporary loop devices | |
460 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" |
|
460 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" | |
461 | ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" |
|
461 | ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" | |
462 | fi |
|
462 | fi | |
463 |
|
463 | |||
464 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
464 | if [ "$ENABLE_CRYPTFS" = true ] ; then | |
465 | # Create dummy ext4 fs |
|
465 | # Create dummy ext4 fs | |
466 | mkfs.ext4 "$ROOT_LOOP" |
|
466 | mkfs.ext4 "$ROOT_LOOP" | |
467 |
|
467 | |||
468 | # Setup password keyfile |
|
468 | # Setup password keyfile | |
469 | echo -n ${CRYPTFS_PASSWORD} > .password |
|
469 | echo -n ${CRYPTFS_PASSWORD} > .password | |
470 | chmod 600 .password |
|
470 | chmod 600 .password | |
471 |
|
471 | |||
472 | # Initialize encrypted partition |
|
472 | # Initialize encrypted partition | |
473 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password |
|
473 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password | |
474 |
|
474 | |||
475 | # Open encrypted partition and setup mapping |
|
475 | # Open encrypted partition and setup mapping | |
476 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" |
|
476 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" | |
477 |
|
477 | |||
478 | # Secure delete password keyfile |
|
478 | # Secure delete password keyfile | |
479 | shred -zu .password |
|
479 | shred -zu .password | |
480 |
|
480 | |||
481 | # Update temporary loop device |
|
481 | # Update temporary loop device | |
482 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" |
|
482 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" | |
483 |
|
483 | |||
484 | # Wipe encrypted partition (encryption cipher is used for randomness) |
|
484 | # Wipe encrypted partition (encryption cipher is used for randomness) | |
485 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}") |
|
485 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}") | |
486 | fi |
|
486 | fi | |
487 |
|
487 | |||
488 | # Build filesystems |
|
488 | # Build filesystems | |
489 | mkfs.vfat "$FRMW_LOOP" |
|
489 | mkfs.vfat "$FRMW_LOOP" | |
490 | mkfs.ext4 "$ROOT_LOOP" |
|
490 | mkfs.ext4 "$ROOT_LOOP" | |
491 |
|
491 | |||
492 | # Mount the temporary loop devices |
|
492 | # Mount the temporary loop devices | |
493 | mkdir -p "$BUILDDIR/mount" |
|
493 | mkdir -p "$BUILDDIR/mount" | |
494 | mount "$ROOT_LOOP" "$BUILDDIR/mount" |
|
494 | mount "$ROOT_LOOP" "$BUILDDIR/mount" | |
495 |
|
495 | |||
496 | mkdir -p "$BUILDDIR/mount/boot/firmware" |
|
496 | mkdir -p "$BUILDDIR/mount/boot/firmware" | |
497 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" |
|
497 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" | |
498 |
|
498 | |||
499 | # Copy all files from the chroot to the loop device mount point directory |
|
499 | # Copy all files from the chroot to the loop device mount point directory | |
500 | rsync -a "${R}/" "$BUILDDIR/mount/" |
|
500 | rsync -a "${R}/" "$BUILDDIR/mount/" | |
501 |
|
501 | |||
502 | # Unmount all temporary loop devices and mount points |
|
502 | # Unmount all temporary loop devices and mount points | |
503 | cleanup |
|
503 | cleanup | |
504 |
|
504 | |||
505 | # Create block map file(s) of image(s) |
|
505 | # Create block map file(s) of image(s) | |
506 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
506 | if [ "$ENABLE_SPLITFS" = true ] ; then | |
507 | # Create block map files for "bmaptool" |
|
507 | # Create block map files for "bmaptool" | |
508 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" |
|
508 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" | |
509 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" |
|
509 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" | |
510 |
|
510 | |||
511 | # Image was successfully created |
|
511 | # Image was successfully created | |
512 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
512 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
513 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
513 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
514 | else |
|
514 | else | |
515 | # Create block map file for "bmaptool" |
|
515 | # Create block map file for "bmaptool" | |
516 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img" |
|
516 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img" | |
517 |
|
517 | |||
518 | # Image was successfully created |
|
518 | # Image was successfully created | |
519 | echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
519 | echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" | |
520 | fi |
|
520 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant