##// END OF EJS Templates
move locales to defaults instead of set alternative iptables- save and -restore need to be installed
Unknown -
r315:ecfa43d496db
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,790 +1,785
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 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
246 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
247 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
247 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
248 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
248 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
249 RELEASE_ARCH=${RELEASE_ARCH:=armel}
249 RELEASE_ARCH=${RELEASE_ARCH:=armel}
250 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
250 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
251 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
251 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
252 fi
252 fi
253 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
253 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
254 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
254 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
255 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
255 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
256 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
256 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
257 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
257 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
258 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
258 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
259 fi
259 fi
260 #Device specific configuration
260 #Device specific configuration
261 case "$RPI_MODEL" in
261 case "$RPI_MODEL" in
262 0)
262 0)
263 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
263 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
264 ;;
264 ;;
265 1)
265 1)
266 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
266 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
267 ;;
267 ;;
268 1P)
268 1P)
269 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
269 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
270 ;;
270 ;;
271 2)
271 2)
272 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
272 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
273 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
273 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
274 ;;
274 ;;
275 3)
275 3)
276 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
276 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
277 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
277 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
278 ;;
278 ;;
279 3P)
279 3P)
280 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
280 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
281 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
281 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
282 ;;
282 ;;
283 *)
283 *)
284 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
284 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
285 exit 1
285 exit 1
286 ;;
286 ;;
287 esac
287 esac
288
288
289 #Device specific configuration
289 #Device specific configuration
290 # if [ "$RPI_MODEL" = 0 ] ; then
290 # if [ "$RPI_MODEL" = 0 ] ; then
291 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
291 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
292 # fi
292 # fi
293 # if [ "$RPI_MODEL" = 1 ] ; then
293 # if [ "$RPI_MODEL" = 1 ] ; then
294 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
294 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
295 # fi
295 # fi
296 # if [ "$RPI_MODEL" = 1P ] ; then
296 # if [ "$RPI_MODEL" = 1P ] ; then
297 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
297 # DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
298 # fi
298 # fi
299 # if [ "$RPI_MODEL" = 2 ] ; then
299 # if [ "$RPI_MODEL" = 2 ] ; then
300 # DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
300 # DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
301 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
301 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
302 # #Precompiled Kernel rpi2
302 # #Precompiled Kernel rpi2
303 # #COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
303 # #COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
304 # fi
304 # fi
305 # if [ "$RPI_MODEL" = 3 ] ; then
305 # if [ "$RPI_MODEL" = 3 ] ; then
306 # DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
306 # DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
307 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
307 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
308 # fi
308 # fi
309 # if [ "$RPI_MODEL" = 3P ] ; then
309 # if [ "$RPI_MODEL" = 3P ] ; then
310 # DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
310 # DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
311 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
311 # UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_32b_defconfig}
312 # fi
312 # fi
313 # if [ -z "$RPI_MODEL" ] ; then
313 # if [ -z "$RPI_MODEL" ] ; then
314 # echo "error: Raspberry Pi model $RPI_MODEL is not set!"
314 # echo "error: Raspberry Pi model $RPI_MODEL is not set!"
315 # exit 1
315 # exit 1
316 # fi
316 # fi
317
317
318 #end 32 bit
318 #end 32 bit
319 fi
319 fi
320 #SET_ARCH not set
320 #SET_ARCH not set
321 else
321 else
322 echo "error: Please set '32' or '64' as value for SET_ARCH"
322 echo "error: Please set '32' or '64' as value for SET_ARCH"
323 exit 1
323 exit 1
324 fi
324 fi
325
325
326 # Check if the internal wireless interface is supported by the RPi model
326 # Check if the internal wireless interface is supported by the RPi model
327 if [ "$ENABLE_WIRELESS" = true ] && { [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; } ; then
327 if [ "$ENABLE_WIRELESS" = true ] && { [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; } ; then
328 echo "error: The selected Raspberry Pi model has no internal wireless interface"
328 echo "error: The selected Raspberry Pi model has no internal wireless interface"
329 exit 1
329 exit 1
330 else
330 else
331 echo "Raspberry Pi model"
331 echo "Raspberry Pi model"
332 fi
332 fi
333
333
334 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
334 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
335 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
335 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
336 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
336 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
337 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
337 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
338 exit 1
338 exit 1
339 fi
339 fi
340 fi
340 fi
341
341
342 # Add libncurses5 to enable kernel menuconfig
342 # Add libncurses5 to enable kernel menuconfig
343 if [ "$KERNEL_MENUCONFIG" = true ] ; then
343 if [ "$KERNEL_MENUCONFIG" = true ] ; then
344 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
344 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
345 fi
345 fi
346
346
347 # Add ccache compiler cache for (faster) kernel cross (re)compilation
347 # Add ccache compiler cache for (faster) kernel cross (re)compilation
348 if [ "$KERNEL_CCACHE" = true ] ; then
348 if [ "$KERNEL_CCACHE" = true ] ; then
349 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
349 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
350 fi
350 fi
351
351
352 # Add cryptsetup package to enable filesystem encryption
352 # Add cryptsetup package to enable filesystem encryption
353 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
353 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
354 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
354 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
355 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
355 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
356
356
357 if [ -z "$CRYPTFS_PASSWORD" ] ; then
357 if [ -z "$CRYPTFS_PASSWORD" ] ; then
358 echo "error: no password defined (CRYPTFS_PASSWORD)!"
358 echo "error: no password defined (CRYPTFS_PASSWORD)!"
359 exit 1
359 exit 1
360 fi
360 fi
361 ENABLE_INITRAMFS=true
361 ENABLE_INITRAMFS=true
362 fi
362 fi
363
363
364 # Add initramfs generation tools
364 # Add initramfs generation tools
365 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
365 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
366 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
366 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
367 fi
367 fi
368
368
369 # Add device-tree-compiler required for building the U-Boot bootloader
369 # Add device-tree-compiler required for building the U-Boot bootloader
370 if [ "$ENABLE_UBOOT" = true ] ; then
370 if [ "$ENABLE_UBOOT" = true ] ; then
371 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex"
371 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex"
372 fi
372 fi
373
373
374 # Check if root SSH (v2) public key file exists
374 # Check if root SSH (v2) public key file exists
375 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
375 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
376 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
376 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
377 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
377 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
378 exit 1
378 exit 1
379 fi
379 fi
380 fi
380 fi
381
381
382 # Check if $USER_NAME SSH (v2) public key file exists
382 # Check if $USER_NAME SSH (v2) public key file exists
383 if [ -n "$SSH_USER_PUB_KEY" ] ; then
383 if [ -n "$SSH_USER_PUB_KEY" ] ; then
384 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
384 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
385 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
385 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
386 exit 1
386 exit 1
387 fi
387 fi
388 fi
388 fi
389
389
390 # Check if all required packages are installed on the build system
390 # Check if all required packages are installed on the build system
391 for package in $REQUIRED_PACKAGES ; do
391 for package in $REQUIRED_PACKAGES ; do
392 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
392 if [ "$(dpkg-query -W -f='${Status}' "$package")" != "install ok installed" ] ; then
393 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
393 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
394 fi
394 fi
395 done
395 done
396
396
397 # If there are missing packages ask confirmation for install, or exit
397 # If there are missing packages ask confirmation for install, or exit
398 if [ -n "$MISSING_PACKAGES" ] ; then
398 if [ -n "$MISSING_PACKAGES" ] ; then
399 echo "the following packages needed by this script are not installed:"
399 echo "the following packages needed by this script are not installed:"
400 echo "$MISSING_PACKAGES"
400 echo "$MISSING_PACKAGES"
401
401
402 printf "\ndo you want to install the missing packages right now? [y/n] "
402 printf "\ndo you want to install the missing packages right now? [y/n] "
403 read -r confirm
403 read -r confirm
404 [ "$confirm" != "y" ] && exit 1
404 [ "$confirm" != "y" ] && exit 1
405
405
406 # Make sure all missing required packages are installed
406 # Make sure all missing required packages are installed
407 apt-get -qq -y install "${MISSING_PACKAGES}"
407 apt-get -qq -y install "${MISSING_PACKAGES}"
408 fi
408 fi
409
409
410 # Check if ./bootstrap.d directory exists
410 # Check if ./bootstrap.d directory exists
411 if [ ! -d "./bootstrap.d/" ] ; then
411 if [ ! -d "./bootstrap.d/" ] ; then
412 echo "error: './bootstrap.d' required directory not found!"
412 echo "error: './bootstrap.d' required directory not found!"
413 exit 1
413 exit 1
414 fi
414 fi
415
415
416 # Check if ./files directory exists
416 # Check if ./files directory exists
417 if [ ! -d "./files/" ] ; then
417 if [ ! -d "./files/" ] ; then
418 echo "error: './files' required directory not found!"
418 echo "error: './files' required directory not found!"
419 exit 1
419 exit 1
420 fi
420 fi
421
421
422 # Check if specified KERNELSRC_DIR directory exists
422 # Check if specified KERNELSRC_DIR directory exists
423 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
423 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
424 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
424 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
425 exit 1
425 exit 1
426 fi
426 fi
427
427
428 # Check if specified UBOOTSRC_DIR directory exists
428 # Check if specified UBOOTSRC_DIR directory exists
429 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
429 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
430 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
430 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
431 exit 1
431 exit 1
432 fi
432 fi
433
433
434 # Check if specified FBTURBOSRC_DIR directory exists
434 # Check if specified FBTURBOSRC_DIR directory exists
435 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
435 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
436 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
436 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
437 exit 1
437 exit 1
438 fi
438 fi
439
439
440 # Check if specified CHROOT_SCRIPTS directory exists
440 # Check if specified CHROOT_SCRIPTS directory exists
441 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
441 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
442 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
442 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
443 exit 1
443 exit 1
444 fi
444 fi
445
445
446 # Check if specified device mapping already exists (will be used by cryptsetup)
446 # Check if specified device mapping already exists (will be used by cryptsetup)
447 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
447 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
448 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
448 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
449 exit 1
449 exit 1
450 fi
450 fi
451
451
452 # Don't clobber an old build
452 # Don't clobber an old build
453 if [ -e "$BUILDDIR" ] ; then
453 if [ -e "$BUILDDIR" ] ; then
454 echo "error: directory ${BUILDDIR} already exists, not proceeding"
454 echo "error: directory ${BUILDDIR} already exists, not proceeding"
455 exit 1
455 exit 1
456 fi
456 fi
457
457
458 # Setup chroot directory
458 # Setup chroot directory
459 mkdir -p "${R}"
459 mkdir -p "${R}"
460
460
461 # Check if build directory has enough of free disk space >512MB
461 # Check if build directory has enough of free disk space >512MB
462 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
462 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
463 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
463 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
464 exit 1
464 exit 1
465 fi
465 fi
466
466
467 set -x
467 set -x
468
468
469 # Call "cleanup" function on various signals and errors
469 # Call "cleanup" function on various signals and errors
470 trap cleanup 0 1 2 3 6
470 trap cleanup 0 1 2 3 6
471
471
472 # Add required packages for the minbase installation
472 # Add required packages for the minbase installation
473 if [ "$ENABLE_MINBASE" = true ] ; then
473 if [ "$ENABLE_MINBASE" = true ] ; then
474 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
474 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
475 fi
475 fi
476
476
477 # Add required locales packages
478 if [ "$DEFLOCAL" != "en_US.UTF-8" ] || { [ -n "$XKB_MODEL" ] || [ -n "$XKB_LAYOUT" ] || [ -n "$XKB_VARIANT" ] || [ -n "$XKB_OPTIONS" ] ; } ; then
479 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
480 fi
481
482 # Add parted package, required to get partprobe utility
477 # Add parted package, required to get partprobe utility
483 if [ "$EXPANDROOT" = true ] ; then
478 if [ "$EXPANDROOT" = true ] ; then
484 APT_INCLUDES="${APT_INCLUDES},parted"
479 APT_INCLUDES="${APT_INCLUDES},parted"
485 fi
480 fi
486
481
487 # Add dbus package, recommended if using systemd
482 # Add dbus package, recommended if using systemd
488 if [ "$ENABLE_DBUS" = true ] ; then
483 if [ "$ENABLE_DBUS" = true ] ; then
489 APT_INCLUDES="${APT_INCLUDES},dbus"
484 APT_INCLUDES="${APT_INCLUDES},dbus"
490 fi
485 fi
491
486
492 # Add iptables IPv4/IPv6 package
487 # Add iptables IPv4/IPv6 package
493 if [ "$ENABLE_IPTABLES" = true ] ; then
488 if [ "$ENABLE_IPTABLES" = true ] ; then
494 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
489 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
495 fi
490 fi
496
491
497 # Add openssh server package
492 # Add openssh server package
498 if [ "$ENABLE_SSHD" = true ] ; then
493 if [ "$ENABLE_SSHD" = true ] ; then
499 APT_INCLUDES="${APT_INCLUDES},openssh-server"
494 APT_INCLUDES="${APT_INCLUDES},openssh-server"
500 fi
495 fi
501
496
502 # Add alsa-utils package
497 # Add alsa-utils package
503 if [ "$ENABLE_SOUND" = true ] ; then
498 if [ "$ENABLE_SOUND" = true ] ; then
504 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
499 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
505 fi
500 fi
506
501
507 # Add rng-tools package
502 # Add rng-tools package
508 if [ "$ENABLE_HWRANDOM" = true ] ; then
503 if [ "$ENABLE_HWRANDOM" = true ] ; then
509 APT_INCLUDES="${APT_INCLUDES},rng-tools"
504 APT_INCLUDES="${APT_INCLUDES},rng-tools"
510 fi
505 fi
511
506
512 # Add fbturbo video driver
507 # Add fbturbo video driver
513 if [ "$ENABLE_FBTURBO" = true ] ; then
508 if [ "$ENABLE_FBTURBO" = true ] ; then
514 # Enable xorg package dependencies
509 # Enable xorg package dependencies
515 ENABLE_XORG=true
510 ENABLE_XORG=true
516 fi
511 fi
517
512
518 # Add user defined window manager package
513 # Add user defined window manager package
519 if [ -n "$ENABLE_WM" ] ; then
514 if [ -n "$ENABLE_WM" ] ; then
520 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
515 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
521
516
522 # Enable xorg package dependencies
517 # Enable xorg package dependencies
523 ENABLE_XORG=true
518 ENABLE_XORG=true
524 fi
519 fi
525
520
526 # Add xorg package
521 # Add xorg package
527 if [ "$ENABLE_XORG" = true ] ; then
522 if [ "$ENABLE_XORG" = true ] ; then
528 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
523 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
529 fi
524 fi
530
525
531 # Replace selected packages with smaller clones
526 # Replace selected packages with smaller clones
532 if [ "$ENABLE_REDUCE" = true ] ; then
527 if [ "$ENABLE_REDUCE" = true ] ; then
533 # Add levee package instead of vim-tiny
528 # Add levee package instead of vim-tiny
534 if [ "$REDUCE_VIM" = true ] ; then
529 if [ "$REDUCE_VIM" = true ] ; then
535 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
530 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
536 fi
531 fi
537
532
538 # Add dropbear package instead of openssh-server
533 # Add dropbear package instead of openssh-server
539 if [ "$REDUCE_SSHD" = true ] ; then
534 if [ "$REDUCE_SSHD" = true ] ; then
540 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
535 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
541 fi
536 fi
542 fi
537 fi
543
538
544 # Configure kernel sources if no KERNELSRC_DIR
539 # Configure kernel sources if no KERNELSRC_DIR
545 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
540 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
546 KERNELSRC_CONFIG=true
541 KERNELSRC_CONFIG=true
547 fi
542 fi
548
543
549 # Configure reduced kernel
544 # Configure reduced kernel
550 if [ "$KERNEL_REDUCE" = true ] ; then
545 if [ "$KERNEL_REDUCE" = true ] ; then
551 KERNELSRC_CONFIG=false
546 KERNELSRC_CONFIG=false
552 fi
547 fi
553
548
554 # Execute bootstrap scripts
549 # Execute bootstrap scripts
555 for SCRIPT in bootstrap.d/*.sh; do
550 for SCRIPT in bootstrap.d/*.sh; do
556 head -n 3 "$SCRIPT"
551 head -n 3 "$SCRIPT"
557 . "$SCRIPT"
552 . "$SCRIPT"
558 done
553 done
559
554
560 ## Execute custom bootstrap scripts
555 ## Execute custom bootstrap scripts
561 if [ -d "custom.d" ] ; then
556 if [ -d "custom.d" ] ; then
562 for SCRIPT in custom.d/*.sh; do
557 for SCRIPT in custom.d/*.sh; do
563 . "$SCRIPT"
558 . "$SCRIPT"
564 done
559 done
565 fi
560 fi
566
561
567 # Execute custom scripts inside the chroot
562 # Execute custom scripts inside the chroot
568 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
563 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
569 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
564 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
570 chroot_exec /bin/bash -x <<'EOF'
565 chroot_exec /bin/bash -x <<'EOF'
571 for SCRIPT in /chroot_scripts/* ; do
566 for SCRIPT in /chroot_scripts/* ; do
572 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
567 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
573 $SCRIPT
568 $SCRIPT
574 fi
569 fi
575 done
570 done
576 EOF
571 EOF
577 rm -rf "${R}/chroot_scripts"
572 rm -rf "${R}/chroot_scripts"
578 fi
573 fi
579
574
580 # Remove c/c++ build environment from the chroot
575 # Remove c/c++ build environment from the chroot
581 chroot_remove_cc
576 chroot_remove_cc
582
577
583 # Generate required machine-id
578 # Generate required machine-id
584 MACHINE_ID=$(dbus-uuidgen)
579 MACHINE_ID=$(dbus-uuidgen)
585 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
580 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
586 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
581 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
587
582
588 # APT Cleanup
583 # APT Cleanup
589 chroot_exec apt-get -y clean
584 chroot_exec apt-get -y clean
590 chroot_exec apt-get -y autoclean
585 chroot_exec apt-get -y autoclean
591 chroot_exec apt-get -y autoremove
586 chroot_exec apt-get -y autoremove
592
587
593 # Unmount mounted filesystems
588 # Unmount mounted filesystems
594 umount -l "${R}/proc"
589 umount -l "${R}/proc"
595 umount -l "${R}/sys"
590 umount -l "${R}/sys"
596
591
597 # Clean up directories
592 # Clean up directories
598 rm -rf "${R}/run/*"
593 rm -rf "${R}/run/*"
599 rm -rf "${R}/tmp/*"
594 rm -rf "${R}/tmp/*"
600
595
601 # Clean up files
596 # Clean up files
602 rm -f "${ETC_DIR}/ssh/ssh_host_*"
597 rm -f "${ETC_DIR}/ssh/ssh_host_*"
603 rm -f "${ETC_DIR}/dropbear/dropbear_*"
598 rm -f "${ETC_DIR}/dropbear/dropbear_*"
604 rm -f "${ETC_DIR}/apt/sources.list.save"
599 rm -f "${ETC_DIR}/apt/sources.list.save"
605 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
600 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
606 rm -f "${ETC_DIR}/*-"
601 rm -f "${ETC_DIR}/*-"
607 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
602 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
608 rm -f "${ETC_DIR}/resolv.conf"
603 rm -f "${ETC_DIR}/resolv.conf"
609 rm -f "${R}/root/.bash_history"
604 rm -f "${R}/root/.bash_history"
610 rm -f "${R}/var/lib/urandom/random-seed"
605 rm -f "${R}/var/lib/urandom/random-seed"
611 rm -f "${R}/initrd.img"
606 rm -f "${R}/initrd.img"
612 rm -f "${R}/vmlinuz"
607 rm -f "${R}/vmlinuz"
613 rm -f "${R}${QEMU_BINARY}"
608 rm -f "${R}${QEMU_BINARY}"
614
609
615 if [ "$ENABLE_QEMU" = true ] ; then
610 if [ "$ENABLE_QEMU" = true ] ; then
616 # Configure qemu compatible kernel
611 # Configure qemu compatible kernel
617 DTB_FILE=vexpress-v2p-ca15_a7.dtb
612 DTB_FILE=vexpress-v2p-ca15_a7.dtb
618 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
613 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
619 KERNEL_DEFCONFIG="vexpress_defconfig"
614 KERNEL_DEFCONFIG="vexpress_defconfig"
620 if [ "$KERNEL_MENUCONFIG" = false ] ; then
615 if [ "$KERNEL_MENUCONFIG" = false ] ; then
621 KERNEL_OLDDEFCONFIG=true
616 KERNEL_OLDDEFCONFIG=true
622 fi
617 fi
623
618
624 # Setup QEMU directory
619 # Setup QEMU directory
625 mkdir "${BASEDIR}/qemu"
620 mkdir "${BASEDIR}/qemu"
626
621
627 # Copy kernel image to QEMU directory
622 # Copy kernel image to QEMU directory
628 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
623 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
629
624
630 # Copy kernel config to QEMU directory
625 # Copy kernel config to QEMU directory
631 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
626 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
632
627
633 # Copy kernel dtbs to QEMU directory
628 # Copy kernel dtbs to QEMU directory
634 for dtb in "${BOOT_DIR}/"*.dtb ; do
629 for dtb in "${BOOT_DIR}/"*.dtb ; do
635 if [ -f "${dtb}" ] ; then
630 if [ -f "${dtb}" ] ; then
636 install_readonly "${dtb}" "${BASEDIR}/qemu/"
631 install_readonly "${dtb}" "${BASEDIR}/qemu/"
637 fi
632 fi
638 done
633 done
639
634
640 # Copy kernel overlays to QEMU directory
635 # Copy kernel overlays to QEMU directory
641 if [ -d "${BOOT_DIR}/overlays" ] ; then
636 if [ -d "${BOOT_DIR}/overlays" ] ; then
642 # Setup overlays dtbs directory
637 # Setup overlays dtbs directory
643 mkdir "${BASEDIR}/qemu/overlays"
638 mkdir "${BASEDIR}/qemu/overlays"
644
639
645 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
640 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
646 if [ -f "${dtb}" ] ; then
641 if [ -f "${dtb}" ] ; then
647 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
642 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
648 fi
643 fi
649 done
644 done
650 fi
645 fi
651
646
652 # Copy u-boot files to QEMU directory
647 # Copy u-boot files to QEMU directory
653 if [ "$ENABLE_UBOOT" = true ] ; then
648 if [ "$ENABLE_UBOOT" = true ] ; then
654 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
649 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
655 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
650 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
656 fi
651 fi
657 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
652 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
658 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
653 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
659 fi
654 fi
660 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
655 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
661 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
656 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
662 fi
657 fi
663 fi
658 fi
664
659
665 # Copy initramfs to QEMU directory
660 # Copy initramfs to QEMU directory
666 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
661 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
667 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
662 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
668 fi
663 fi
669 fi
664 fi
670
665
671 # Calculate size of the chroot directory in KB
666 # Calculate size of the chroot directory in KB
672 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
667 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
673
668
674 # Calculate the amount of needed 512 Byte sectors
669 # Calculate the amount of needed 512 Byte sectors
675 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
670 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
676 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
671 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
677 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
672 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
678
673
679 # The root partition is EXT4
674 # The root partition is EXT4
680 # This means more space than the actual used space of the chroot is used.
675 # This means more space than the actual used space of the chroot is used.
681 # As overhead for journaling and reserved blocks 35% are added.
676 # As overhead for journaling and reserved blocks 35% are added.
682 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
677 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
683
678
684 # Calculate required image size in 512 Byte sectors
679 # Calculate required image size in 512 Byte sectors
685 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
680 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
686
681
687 # Prepare image file
682 # Prepare image file
688 if [ "$ENABLE_SPLITFS" = true ] ; then
683 if [ "$ENABLE_SPLITFS" = true ] ; then
689 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
684 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
690 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
685 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
691 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
686 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
692 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
687 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
693
688
694 # Write firmware/boot partition tables
689 # Write firmware/boot partition tables
695 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
690 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
696 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
691 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
697 EOM
692 EOM
698
693
699 # Write root partition table
694 # Write root partition table
700 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
695 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
701 "${TABLE_SECTORS}","${ROOT_SECTORS}",83
696 "${TABLE_SECTORS}","${ROOT_SECTORS}",83
702 EOM
697 EOM
703
698
704 # Setup temporary loop devices
699 # Setup temporary loop devices
705 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
700 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
706 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
701 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
707 else # ENABLE_SPLITFS=false
702 else # ENABLE_SPLITFS=false
708 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
703 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
709 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
704 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
710
705
711 # Write partition table
706 # Write partition table
712 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
707 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
713 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
708 "${TABLE_SECTORS}","${FRMW_SECTORS}",c,*
714 "${ROOT_OFFSET}","${ROOT_SECTORS}",83
709 "${ROOT_OFFSET}","${ROOT_SECTORS}",83
715 EOM
710 EOM
716
711
717 # Setup temporary loop devices
712 # Setup temporary loop devices
718 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
713 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
719 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
714 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
720 fi
715 fi
721
716
722 if [ "$ENABLE_CRYPTFS" = true ] ; then
717 if [ "$ENABLE_CRYPTFS" = true ] ; then
723 # Create dummy ext4 fs
718 # Create dummy ext4 fs
724 mkfs.ext4 "$ROOT_LOOP"
719 mkfs.ext4 "$ROOT_LOOP"
725
720
726 # Setup password keyfile
721 # Setup password keyfile
727 touch .password
722 touch .password
728 chmod 600 .password
723 chmod 600 .password
729 echo -n "${CRYPTFS_PASSWORD}" > .password
724 echo -n "${CRYPTFS_PASSWORD}" > .password
730
725
731 # Initialize encrypted partition
726 # Initialize encrypted partition
732 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
727 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
733
728
734 # Open encrypted partition and setup mapping
729 # Open encrypted partition and setup mapping
735 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
730 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
736
731
737 # Secure delete password keyfile
732 # Secure delete password keyfile
738 shred -zu .password
733 shred -zu .password
739
734
740 # Update temporary loop device
735 # Update temporary loop device
741 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
736 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
742
737
743 # Wipe encrypted partition (encryption cipher is used for randomness)
738 # Wipe encrypted partition (encryption cipher is used for randomness)
744 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
739 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
745 fi
740 fi
746
741
747 # Build filesystems
742 # Build filesystems
748 mkfs.vfat "$FRMW_LOOP"
743 mkfs.vfat "$FRMW_LOOP"
749 mkfs.ext4 "$ROOT_LOOP"
744 mkfs.ext4 "$ROOT_LOOP"
750
745
751 # Mount the temporary loop devices
746 # Mount the temporary loop devices
752 mkdir -p "$BUILDDIR/mount"
747 mkdir -p "$BUILDDIR/mount"
753 mount "$ROOT_LOOP" "$BUILDDIR/mount"
748 mount "$ROOT_LOOP" "$BUILDDIR/mount"
754
749
755 mkdir -p "$BUILDDIR/mount/boot/firmware"
750 mkdir -p "$BUILDDIR/mount/boot/firmware"
756 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
751 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
757
752
758 # Copy all files from the chroot to the loop device mount point directory
753 # Copy all files from the chroot to the loop device mount point directory
759 rsync -a "${R}/" "$BUILDDIR/mount/"
754 rsync -a "${R}/" "$BUILDDIR/mount/"
760
755
761 # Unmount all temporary loop devices and mount points
756 # Unmount all temporary loop devices and mount points
762 cleanup
757 cleanup
763
758
764 # Create block map file(s) of image(s)
759 # Create block map file(s) of image(s)
765 if [ "$ENABLE_SPLITFS" = true ] ; then
760 if [ "$ENABLE_SPLITFS" = true ] ; then
766 # Create block map files for "bmaptool"
761 # Create block map files for "bmaptool"
767 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
762 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
768 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
763 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
769
764
770 # Image was successfully created
765 # Image was successfully created
771 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
766 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
772 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
767 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
773 else
768 else
774 # Create block map file for "bmaptool"
769 # Create block map file for "bmaptool"
775 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
770 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
776
771
777 # Image was successfully created
772 # Image was successfully created
778 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
773 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
779
774
780 # Create qemu qcow2 image
775 # Create qemu qcow2 image
781 if [ "$ENABLE_QEMU" = true ] ; then
776 if [ "$ENABLE_QEMU" = true ] ; then
782 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
777 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
783 QEMU_SIZE=16G
778 QEMU_SIZE=16G
784
779
785 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
780 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
786 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
781 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
787
782
788 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
783 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
789 fi
784 fi
790 fi
785 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant