@@ -0,0 +1,72 | |||||
|
1 | # | |||
|
2 | # Reduce system disk usage | |||
|
3 | # | |||
|
4 | ||||
|
5 | # Load utility functions | |||
|
6 | . ./functions.sh | |||
|
7 | ||||
|
8 | # Reduce the image size by various operations | |||
|
9 | if [ "$ENABLE_REDUCE" = true ] ; then | |||
|
10 | if [ "$REDUCE_APT" = true ] ; then | |||
|
11 | # Install dpkg configuration file | |||
|
12 | if [ "$REDUCE_DOC" = true ] || [ "$REDUCE_MAN" = true ] ; then | |||
|
13 | install_readonly files/dpkg/01nodoc "$R/etc/dpkg/dpkg.cfg.d/01nodoc" | |||
|
14 | fi | |||
|
15 | ||||
|
16 | # Install APT configuration files | |||
|
17 | install_readonly files/apt/02nocache "$R/etc/apt/apt.conf.d/02nocache" | |||
|
18 | install_readonly files/apt/03compress "$R/etc/apt/apt.conf.d/03compress" | |||
|
19 | install_readonly files/apt/04norecommends "$R/etc/apt/apt.conf.d/04norecommends" | |||
|
20 | ||||
|
21 | # Remove APT cache files | |||
|
22 | rm -fr "$R/var/cache/apt/pkgcache.bin" | |||
|
23 | rm -fr "$R/var/cache/apt/srcpkgcache.bin" | |||
|
24 | fi | |||
|
25 | ||||
|
26 | # Remove all doc files | |||
|
27 | if [ "$REDUCE_DOC" = true ] ; then | |||
|
28 | find "$R/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true | |||
|
29 | find "$R/usr/share/doc" -empty | xargs rmdir || true | |||
|
30 | fi | |||
|
31 | ||||
|
32 | # Remove all man pages and info files | |||
|
33 | if [ "$REDUCE_MAN" = true ] ; then | |||
|
34 | rm -rf "$R/usr/share/man" "$R/usr/share/groff" "$R/usr/share/info" "$R/usr/share/lintian" "$R/usr/share/linda" "$R/var/cache/man" | |||
|
35 | fi | |||
|
36 | ||||
|
37 | # Remove all locale translation files | |||
|
38 | if [ "$REDUCE_LOCALE" = true ] ; then | |||
|
39 | find "$R/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r | |||
|
40 | fi | |||
|
41 | ||||
|
42 | # Remove hwdb PCI device classes (experimental) | |||
|
43 | if [ "$REDUCE_HWDB" = true ] ; then | |||
|
44 | rm -fr "/lib/udev/hwdb.d/20-pci-*" | |||
|
45 | fi | |||
|
46 | ||||
|
47 | # Replace bash shell by dash shell (experimental) | |||
|
48 | if [ "$REDUCE_BASH" = true ] ; then | |||
|
49 | echo "Yes, do as I say!" | chroot_exec apt-get purge -qq -y --force-yes bash | |||
|
50 | chroot_exec update-alternatives --install /bin/bash bash /bin/dash 100 | |||
|
51 | fi | |||
|
52 | ||||
|
53 | # Remove sound utils and libraries | |||
|
54 | if [ "$ENABLE_SOUND" = false ] ; then | |||
|
55 | chroot_exec apt-get -qq -y --force-yes purge alsa-utils libsamplerate0 libasound2 libasound2-data | |||
|
56 | fi | |||
|
57 | ||||
|
58 | # Re-install tools for managing kernel moduless | |||
|
59 | chroot_exec apt-get -qq -y --force-yes install module-init-tools | |||
|
60 | ||||
|
61 | # Remove GPU kernels | |||
|
62 | if [ "$ENABLE_MINGPU" = true ] ; then | |||
|
63 | rm -f "$R/boot/firmware/start.elf" | |||
|
64 | rm -f "$R/boot/firmware/fixup.dat" | |||
|
65 | rm -f "$R/boot/firmware/start_x.elf" | |||
|
66 | rm -f "$R/boot/firmware/fixup_x.dat" | |||
|
67 | fi | |||
|
68 | ||||
|
69 | # Clean APT list of repositories | |||
|
70 | rm -fr "$R/var/lib/apt/lists/*" | |||
|
71 | chroot_exec apt-get -qq -y update | |||
|
72 | fi |
@@ -131,7 +131,7 Install a user defined window manager for the X Window System. To make sure all | |||||
131 | Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB. |
|
131 | Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB. | |
132 |
|
132 | |||
133 | ##### `ENABLE_REDUCE`=false |
|
133 | ##### `ENABLE_REDUCE`=false | |
134 | Reduce the disk usage by deleting all man pages and doc files (harsh). APT will be configured to use compressed package repository lists and no package caching files. If `ENABLE_MINGPU`=true unnecessary start.elf and fixup.dat files will also be removed from the boot partition. This will make it possible to generate output OS images with about 160MB of used disk space. It's recommended to use this parameter in combination with `ENABLE_MINBASE`=true. |
|
134 | Reduce the disk usage by deleting packages and files. See `REDUCE_*` parameters for detailed information. | |
135 |
|
135 | |||
136 | ##### `ENABLE_UBOOT`=false |
|
136 | ##### `ENABLE_UBOOT`=false | |
137 | Replace default RPi2 second stage bootloader (bootcode.bin) with U-Boot bootloader. U-Boot can boot images via the network using the BOOTP/TFTP protocol. |
|
137 | Replace default RPi2 second stage bootloader (bootcode.bin) with U-Boot bootloader. U-Boot can boot images via the network using the BOOTP/TFTP protocol. | |
@@ -165,6 +165,9 Path to a directory with scripts that should be run in the chroot before the ima | |||||
165 | ##### `BUILD_KERNEL`=false |
|
165 | ##### `BUILD_KERNEL`=false | |
166 | Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used. Detailed configuration parameters for customizing the kernel and minor bug fixes still need to get implemented. feel free to help. |
|
166 | Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used. Detailed configuration parameters for customizing the kernel and minor bug fixes still need to get implemented. feel free to help. | |
167 |
|
167 | |||
|
168 | ##### `KERNEL_REDUCE`=false | |||
|
169 | Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental). | |||
|
170 | ||||
168 | ##### `KERNEL_THREADS`=1 |
|
171 | ##### `KERNEL_THREADS`=1 | |
169 | Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation. |
|
172 | Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation. | |
170 |
|
173 | |||
@@ -189,6 +192,33 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the k | |||||
189 | ##### `KERNELSRC_PREBUILT`=false |
|
192 | ##### `KERNELSRC_PREBUILT`=false | |
190 | With this parameter set to true the script expects the existing kernel sources directory to be already successfully cross-compiled. The parameters `KERNELSRC_CLEAN`, `KERNELSRC_CONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed. |
|
193 | With this parameter set to true the script expects the existing kernel sources directory to be already successfully cross-compiled. The parameters `KERNELSRC_CLEAN`, `KERNELSRC_CONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed. | |
191 |
|
194 | |||
|
195 | #### Reduce disk usage: | |||
|
196 | The following list of parameters is ignored if `ENABLE_REDUCE`=false. | |||
|
197 | ||||
|
198 | ##### `REDUCE_APT`=true | |||
|
199 | Configure APT to use compressed package repository lists and no package caching files. | |||
|
200 | ||||
|
201 | ##### `REDUCE_DOC`=true | |||
|
202 | Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations. | |||
|
203 | ||||
|
204 | ##### `REDUCE_MAN`=true | |||
|
205 | Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations. | |||
|
206 | ||||
|
207 | ##### `REDUCE_VIM`=true | |||
|
208 | Replace `vim-tiny` package by `levee` a tiny vim clone. | |||
|
209 | ||||
|
210 | ##### `REDUCE_BASH`=false | |||
|
211 | Remove `bash` package and switch to `dash` shell (experimental). | |||
|
212 | ||||
|
213 | ##### `REDUCE_HWDB`=true | |||
|
214 | Remove PCI related hwdb files (experimental). | |||
|
215 | ||||
|
216 | ##### `REDUCE_SSHD`=true | |||
|
217 | Replace `openssh-server` with dropbear. | |||
|
218 | ||||
|
219 | ##### `REDUCE_LOCALE`=true | |||
|
220 | Remove all `locale` translation files. | |||
|
221 | ||||
192 | ## Understanding the script |
|
222 | ## Understanding the script | |
193 | The functions of this script that are required for the different stages of the bootstrapping are split up into single files located inside the `bootstrap.d` directory. During the bootstrapping every script in this directory gets executed in lexicographical order: |
|
223 | The functions of this script that are required for the different stages of the bootstrapping are split up into single files located inside the `bootstrap.d` directory. During the bootstrapping every script in this directory gets executed in lexicographical order: | |
194 |
|
224 |
@@ -7,7 +7,7 | |||||
7 |
|
7 | |||
8 | # Base debootstrap (unpack only) |
|
8 | # Base debootstrap (unpack only) | |
9 | if [ "$ENABLE_MINBASE" = true ] ; then |
|
9 | if [ "$ENABLE_MINBASE" = true ] ; then | |
10 |
http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --variant=minbase |
|
10 | http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --variant=minbase --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian" | |
11 | else |
|
11 | else | |
12 | http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian" |
|
12 | http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian" | |
13 | fi |
|
13 | fi |
@@ -29,7 +29,44 if [ "$BUILD_KERNEL" = true ] ; then | |||||
29 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) |
|
29 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) | |
30 | fi |
|
30 | fi | |
31 |
|
31 | |||
|
32 | # Configure and build kernel | |||
32 | if [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
33 | if [ "$KERNELSRC_PREBUILT" = false ] ; then | |
|
34 | # Remove device, network and filesystem drivers from kernel configuration | |||
|
35 | if [ "$KERNEL_REDUCE" = true ] ; then | |||
|
36 | make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" | |||
|
37 | sed -i\ | |||
|
38 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ | |||
|
39 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ | |||
|
40 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ | |||
|
41 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ | |||
|
42 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ | |||
|
43 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ | |||
|
44 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ | |||
|
45 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ | |||
|
46 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ | |||
|
47 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ | |||
|
48 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ | |||
|
49 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ | |||
|
50 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ | |||
|
51 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ | |||
|
52 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ | |||
|
53 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ | |||
|
54 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ | |||
|
55 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ | |||
|
56 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ | |||
|
57 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ | |||
|
58 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ | |||
|
59 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ | |||
|
60 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ | |||
|
61 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ | |||
|
62 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ | |||
|
63 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ | |||
|
64 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ | |||
|
65 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ | |||
|
66 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ | |||
|
67 | "$R/usr/src/linux/.config" | |||
|
68 | fi | |||
|
69 | ||||
33 | if [ "$KERNELSRC_CONFIG" = true ] ; then |
|
70 | if [ "$KERNELSRC_CONFIG" = true ] ; then | |
34 | # Load default raspberry kernel configuration |
|
71 | # Load default raspberry kernel configuration | |
35 | make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
72 | make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" | |
@@ -62,7 +99,7 if [ "$BUILD_KERNEL" = true ] ; then | |||||
62 | fi |
|
99 | fi | |
63 |
|
100 | |||
64 | # Install kernel headers |
|
101 | # Install kernel headers | |
65 | if [ "$KERNEL_HEADERS" = true ] ; then |
|
102 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then | |
66 | make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install |
|
103 | make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install | |
67 | fi |
|
104 | fi | |
68 |
|
105 |
@@ -9,7 +9,7 | |||||
9 | cat files/firstboot/10-begin.sh > "$R/etc/rc.firstboot" |
|
9 | cat files/firstboot/10-begin.sh > "$R/etc/rc.firstboot" | |
10 |
|
10 | |||
11 | # Ensure openssh server host keys are regenerated on first boot |
|
11 | # Ensure openssh server host keys are regenerated on first boot | |
12 | if [ "$ENABLE_SSHD" = true ] ; then |
|
12 | if [ "$ENABLE_SSHD" = true ] && [ "$ENABLE_REDUCE" = false ]; then | |
13 | cat files/firstboot/21-generate-ssh-keys.sh >> "$R/etc/rc.firstboot" |
|
13 | cat files/firstboot/21-generate-ssh-keys.sh >> "$R/etc/rc.firstboot" | |
14 | rm -f "$R/etc/ssh/ssh_host_*" |
|
14 | rm -f "$R/etc/ssh/ssh_host_*" | |
15 | fi |
|
15 | fi |
@@ -1,4 +1,13 | |||||
1 | logger -t "rc.firstboot" "Creating /etc/resolv.conf symlink" |
|
1 | logger -t "rc.firstboot" "Creating /etc/resolv.conf symlink" | |
2 | if [ -f "/run/systemd/resolve/resolv.conf" ] ; then |
|
2 | ||
|
3 | ||||
|
4 | # Check if systemd resolve directory exists | |||
|
5 | if [ -d "/run/systemd/resolve" ] ; then | |||
|
6 | # Create resolv.conf file if it does not exists | |||
|
7 | if [ ! -f "/run/systemd/resolve/resolv.conf" ] ; then | |||
|
8 | touch /run/systemd/resolve/resolv.conf | |||
|
9 | fi | |||
|
10 | ||||
|
11 | # Create symlink to /etc/reolv.conf | |||
3 | ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf |
|
12 | ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf | |
4 | fi |
|
13 | fi |
@@ -15,6 +15,12 | |||||
15 | # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org> |
|
15 | # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org> | |
16 | ######################################################################## |
|
16 | ######################################################################## | |
17 |
|
17 | |||
|
18 | # Are we running as root? | |||
|
19 | if [ "$(id -u)" -ne "0" ] ; then | |||
|
20 | echo "error: this script must be executed with root privileges!" | |||
|
21 | exit 1 | |||
|
22 | fi | |||
|
23 | ||||
18 | # Check if ./functions.sh script exists |
|
24 | # Check if ./functions.sh script exists | |
19 | if [ ! -r "./functions.sh" ] ; then |
|
25 | if [ ! -r "./functions.sh" ] ; then | |
20 | echo "error: './functions.sh' required script not found. please reinstall the latest script version!" |
|
26 | echo "error: './functions.sh' required script not found. please reinstall the latest script version!" | |
@@ -38,9 +44,10 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} | |||||
38 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} |
|
44 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} | |
39 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} |
|
45 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} | |
40 |
|
46 | |||
41 | # Build settings |
|
47 | # Build directories | |
42 | BASEDIR=$(pwd)/images/${RELEASE} |
|
48 | BASEDIR=$(pwd)/images/${RELEASE} | |
43 | BUILDDIR=${BASEDIR}/build |
|
49 | BUILDDIR=${BASEDIR}/build | |
|
50 | R=${BUILDDIR}/chroot | |||
44 |
|
51 | |||
45 | # General settings |
|
52 | # General settings | |
46 | HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}} |
|
53 | HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}} | |
@@ -59,7 +66,6 XKB_OPTIONS=${XKB_OPTIONS:=""} | |||||
59 | ENABLE_DHCP=${ENABLE_DHCP:=true} |
|
66 | ENABLE_DHCP=${ENABLE_DHCP:=true} | |
60 |
|
67 | |||
61 | # Network settings (static) |
|
68 | # Network settings (static) | |
62 | # only used on ENABLE_DHCP=false |
|
|||
63 | NET_ADDRESS=${NET_ADDRESS:=""} |
|
69 | NET_ADDRESS=${NET_ADDRESS:=""} | |
64 | NET_GATEWAY=${NET_GATEWAY:=""} |
|
70 | NET_GATEWAY=${NET_GATEWAY:=""} | |
65 | NET_DNS_1=${NET_DNS_1:=""} |
|
71 | NET_DNS_1=${NET_DNS_1:=""} | |
@@ -98,6 +104,7 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} | |||||
98 |
|
104 | |||
99 | # Kernel compilation settings |
|
105 | # Kernel compilation settings | |
100 | BUILD_KERNEL=${BUILD_KERNEL:=false} |
|
106 | BUILD_KERNEL=${BUILD_KERNEL:=false} | |
|
107 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} | |||
101 | KERNEL_THREADS=${KERNEL_THREADS:=1} |
|
108 | KERNEL_THREADS=${KERNEL_THREADS:=1} | |
102 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} |
|
109 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} | |
103 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} |
|
110 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} | |
@@ -109,62 +116,40 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} | |||||
109 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} |
|
116 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} | |
110 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} |
|
117 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} | |
111 |
|
118 | |||
112 | # Image chroot path |
|
119 | # Reduce disk usage settings | |
113 | R=${BUILDDIR}/chroot |
|
120 | REDUCE_APT=${REDUCE_APT:=true} | |
|
121 | REDUCE_DOC=${REDUCE_DOC:=true} | |||
|
122 | REDUCE_MAN=${REDUCE_MAN:=true} | |||
|
123 | REDUCE_VIM=${REDUCE_VIM:=true} | |||
|
124 | REDUCE_BASH=${REDUCE_BASH:=false} | |||
|
125 | REDUCE_HWDB=${REDUCE_HWDB:=true} | |||
|
126 | REDUCE_SSHD=${REDUCE_SSHD:=true} | |||
|
127 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} | |||
|
128 | ||||
|
129 | # Chroot scripts directory | |||
114 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} |
|
130 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} | |
115 |
|
131 | |||
116 | # Packages required for bootstrapping |
|
|||
117 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core" |
|
|||
118 |
|
||||
119 | # Missing packages that need to be installed |
|
|||
120 | MISSING_PACKAGES="" |
|
|||
121 |
|
||||
122 | # Packages required in the chroot build environment |
|
132 | # Packages required in the chroot build environment | |
123 | APT_INCLUDES=${APT_INCLUDES:=""} |
|
133 | APT_INCLUDES=${APT_INCLUDES:=""} | |
124 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo" |
|
134 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo" | |
125 |
|
135 | |||
126 | set +x |
|
136 | # Packages required for bootstrapping | |
127 |
|
137 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core" | ||
128 | # Are we running as root? |
|
138 | MISSING_PACKAGES="" | |
129 | if [ "$(id -u)" -ne "0" ] ; then |
|
|||
130 | echo "error: this script must be executed with root privileges!" |
|
|||
131 | exit 1 |
|
|||
132 | fi |
|
|||
133 |
|
||||
134 | # Check if ./bootstrap.d directory exists |
|
|||
135 | if [ ! -d "./bootstrap.d/" ] ; then |
|
|||
136 | echo "error: './bootstrap.d' required directory not found. please reinstall the latest script version!" |
|
|||
137 | exit 1 |
|
|||
138 | fi |
|
|||
139 |
|
||||
140 | # Check if ./files directory exists |
|
|||
141 | if [ ! -d "./files/" ] ; then |
|
|||
142 | echo "error: './files' required directory not found. please reinstall the latest script version!" |
|
|||
143 | exit 1 |
|
|||
144 | fi |
|
|||
145 |
|
||||
146 | # Check if specified KERNELSRC_DIR directory exists |
|
|||
147 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then |
|
|||
148 | echo "error: ${KERNELSRC_DIR} (KERNELSRC_DIR) specified directory not found!" |
|
|||
149 | exit 1 |
|
|||
150 | fi |
|
|||
151 |
|
139 | |||
152 | # Check if specified CHROOT_SCRIPTS directory exists |
|
140 | set +x | |
153 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then |
|
|||
154 | echo "error: ${CHROOT_SCRIPTS} (CHROOT_SCRIPTS) specified directory not found!" |
|
|||
155 | exit 1 |
|
|||
156 | fi |
|
|||
157 |
|
141 | |||
158 | # Add packages required for kernel cross compilation |
|
142 | # Add packages required for kernel cross compilation | |
159 | if [ "$BUILD_KERNEL" = true ] ; then |
|
143 | if [ "$BUILD_KERNEL" = true ] ; then | |
160 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" |
|
144 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" | |
|
145 | fi | |||
161 |
|
146 | |||
162 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
147 | # Add libncurses5 to enable kernel menuconfig | |
163 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ncurses-dev" |
|
148 | if [ "$KERNEL_MENUCONFIG" = true ] ; then | |
164 | fi |
|
149 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev" | |
165 | fi |
|
150 | fi | |
166 |
|
151 | |||
167 | # Check if all required packages are installed |
|
152 | # Check if all required packages are installed on the build system | |
168 | for package in $REQUIRED_PACKAGES ; do |
|
153 | for package in $REQUIRED_PACKAGES ; do | |
169 | if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then |
|
154 | if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then | |
170 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" |
|
155 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" | |
@@ -178,14 +163,36 if [ -n "$MISSING_PACKAGES" ] ; then | |||||
178 |
|
163 | |||
179 | echo -n "\ndo you want to install the missing packages right now? [y/n] " |
|
164 | echo -n "\ndo you want to install the missing packages right now? [y/n] " | |
180 | read confirm |
|
165 | read confirm | |
181 |
|
|
166 | [ "$confirm" != "y" ] && exit 1 | |
182 | exit 1 |
|
|||
183 | fi |
|
|||
184 | fi |
|
167 | fi | |
185 |
|
168 | |||
186 | # Make sure all required packages are installed |
|
169 | # Make sure all required packages are installed | |
187 | apt-get -qq -y install ${REQUIRED_PACKAGES} |
|
170 | apt-get -qq -y install ${REQUIRED_PACKAGES} | |
188 |
|
171 | |||
|
172 | # Check if ./bootstrap.d directory exists | |||
|
173 | if [ ! -d "./bootstrap.d/" ] ; then | |||
|
174 | echo "error: './bootstrap.d' required directory not found!" | |||
|
175 | exit 1 | |||
|
176 | fi | |||
|
177 | ||||
|
178 | # Check if ./files directory exists | |||
|
179 | if [ ! -d "./files/" ] ; then | |||
|
180 | echo "error: './files' required directory not found!" | |||
|
181 | exit 1 | |||
|
182 | fi | |||
|
183 | ||||
|
184 | # Check if specified KERNELSRC_DIR directory exists | |||
|
185 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then | |||
|
186 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" | |||
|
187 | exit 1 | |||
|
188 | fi | |||
|
189 | ||||
|
190 | # Check if specified CHROOT_SCRIPTS directory exists | |||
|
191 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then | |||
|
192 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" | |||
|
193 | exit 1 | |||
|
194 | fi | |||
|
195 | ||||
189 | # Don't clobber an old build |
|
196 | # Don't clobber an old build | |
190 | if [ -e "$BUILDDIR" ] ; then |
|
197 | if [ -e "$BUILDDIR" ] ; then | |
191 | echo "error: directory ${BUILDDIR} already exists, not proceeding" |
|
198 | echo "error: directory ${BUILDDIR} already exists, not proceeding" | |
@@ -197,15 +204,10 mkdir -p "$R" | |||||
197 |
|
204 | |||
198 | # Check if build directory has enough of free disk space >512MB |
|
205 | # Check if build directory has enough of free disk space >512MB | |
199 | if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then |
|
206 | if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then | |
200 |
echo "error: ${BUILDDIR} not enough space left |
|
207 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" | |
201 | exit 1 |
|
208 | exit 1 | |
202 | fi |
|
209 | fi | |
203 |
|
210 | |||
204 | # Warn if build directory has low free disk space <1024MB |
|
|||
205 | if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "1048576" ] ; then |
|
|||
206 | echo `df -h --output=avail ${BUILDDIR} | sed "1 s|.*Avail|warning: $partition is low on free space:|"` |
|
|||
207 | fi |
|
|||
208 |
|
||||
209 | set -x |
|
211 | set -x | |
210 |
|
212 | |||
211 | # Call "cleanup" function on various signals and errors |
|
213 | # Call "cleanup" function on various signals and errors | |
@@ -267,30 +269,45 if [ "$ENABLE_XORG" = true ] ; then | |||||
267 | APT_INCLUDES="${APT_INCLUDES},xorg" |
|
269 | APT_INCLUDES="${APT_INCLUDES},xorg" | |
268 | fi |
|
270 | fi | |
269 |
|
271 | |||
270 | # Set KERNELSRC_CONFIG=true |
|
272 | # Replace selected packages with smaller clones | |
|
273 | if [ "$ENABLE_REDUCE" = true ] ; then | |||
|
274 | # Add levee package instead of vim-tiny | |||
|
275 | if [ "$REDUCE_VIM" = true ] ; then | |||
|
276 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" | |||
|
277 | fi | |||
|
278 | ||||
|
279 | # Add dropbear package instead of openssh-server | |||
|
280 | if [ "$REDUCE_SSHD" = true ] ; then | |||
|
281 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")" | |||
|
282 | fi | |||
|
283 | fi | |||
|
284 | ||||
|
285 | # Configure kernel sources if no KERNELSRC_DIR | |||
271 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then |
|
286 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then | |
272 | KERNELSRC_CONFIG=true |
|
287 | KERNELSRC_CONFIG=true | |
273 | fi |
|
288 | fi | |
274 |
|
289 | |||
275 | ## MAIN bootstrap |
|
290 | # Configure reduced kernel | |
|
291 | if [ "$KERNEL_REDUCE" = true ] ; then | |||
|
292 | KERNELSRC_CONFIG=false | |||
|
293 | fi | |||
|
294 | ||||
|
295 | # Execute bootstrap scripts | |||
276 | for SCRIPT in bootstrap.d/*.sh; do |
|
296 | for SCRIPT in bootstrap.d/*.sh; do | |
277 | # Execute bootstrap scripts (lexicographical order) |
|
|||
278 |
|
|
297 | head -n 3 "$SCRIPT" | |
279 | . "$SCRIPT" |
|
298 | . "$SCRIPT" | |
280 | done |
|
299 | done | |
281 |
|
300 | |||
282 |
## |
|
301 | ## Execute custom bootstrap scripts | |
283 | if [ -d "custom.d" ] ; then |
|
302 | if [ -d "custom.d" ] ; then | |
284 | # Execute custom bootstrap scripts (lexicographical order) |
|
|||
285 |
|
|
303 | for SCRIPT in custom.d/*.sh; do | |
286 | . "$SCRIPT" |
|
304 | . "$SCRIPT" | |
287 | done |
|
305 | done | |
288 | fi |
|
306 | fi | |
289 |
|
307 | |||
290 | # Invoke custom scripts |
|
308 | # Execute custom scripts inside the chroot | |
291 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then |
|
309 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then | |
292 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" |
|
310 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" | |
293 | # Execute scripts inside the chroot (lexicographical order) |
|
|||
294 |
|
|
311 | chroot_exec /bin/bash -x <<'EOF' | |
295 | for SCRIPT in /chroot_scripts/* ; do |
|
312 | for SCRIPT in /chroot_scripts/* ; do | |
296 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then |
|
313 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then | |
@@ -304,41 +321,6 fi | |||||
304 | # Remove apt-utils |
|
321 | # Remove apt-utils | |
305 | chroot_exec apt-get purge -qq -y --force-yes apt-utils |
|
322 | chroot_exec apt-get purge -qq -y --force-yes apt-utils | |
306 |
|
323 | |||
307 | # Reduce the image size by removing and compressing |
|
|||
308 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
|||
309 | # Install dpkg configuration fragment file |
|
|||
310 | install_readonly files/dpkg/01nodoc "$R/etc/dpkg/dpkg.cfg.d/01nodoc" |
|
|||
311 |
|
||||
312 | # Install APT configuration fragment files |
|
|||
313 | install_readonly files/apt/02nocache "$R/etc/apt/apt.conf.d/02nocache" |
|
|||
314 | install_readonly files/apt/03compress "$R/etc/apt/apt.conf.d/03compress" |
|
|||
315 | install_readonly files/apt/04norecommends "$R/etc/apt/apt.conf.d/04norecommends" |
|
|||
316 |
|
||||
317 | # Remove APT cache files |
|
|||
318 | rm -fr "$R/var/cache/apt/pkgcache.bin" |
|
|||
319 | rm -fr "$R/var/cache/apt/srcpkgcache.bin" |
|
|||
320 |
|
||||
321 | # Remove all doc and man files |
|
|||
322 | find "$R/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true |
|
|||
323 | find "$R/usr/share/doc" -empty | xargs rmdir || true |
|
|||
324 | rm -rf "$R/usr/share/man" "$R/usr/share/groff" "$R/usr/share/info" "$R/usr/share/lintian" "$R/usr/share/linda" "$R/var/cache/man" |
|
|||
325 |
|
||||
326 | # Remove all translation files |
|
|||
327 | find "$R/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r |
|
|||
328 |
|
||||
329 | # Clean APT list of repositories |
|
|||
330 | rm -fr "$R/var/lib/apt/lists/*" |
|
|||
331 | chroot_exec apt-get -qq -y update |
|
|||
332 |
|
||||
333 | # Remove GPU kernels |
|
|||
334 | if [ "$ENABLE_MINGPU" = true ] ; then |
|
|||
335 | rm -f "$R/boot/firmware/start.elf" |
|
|||
336 | rm -f "$R/boot/firmware/fixup.dat" |
|
|||
337 | rm -f "$R/boot/firmware/start_x.elf" |
|
|||
338 | rm -f "$R/boot/firmware/fixup_x.dat" |
|
|||
339 | fi |
|
|||
340 | fi |
|
|||
341 |
|
||||
342 | # APT Cleanup |
|
324 | # APT Cleanup | |
343 | chroot_exec apt-get -y clean |
|
325 | chroot_exec apt-get -y clean | |
344 | chroot_exec apt-get -y autoclean |
|
326 | chroot_exec apt-get -y autoclean |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant