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