##// END OF EJS Templates
fix: custom.d directory error
Jan Wagner -
r63:91f86cfb2544
parent child
Show More
@@ -1,302 +1,305
1 1 #!/bin/sh
2 2
3 3 ########################################################################
4 4 # rpi2-gen-image.sh ver2a 12/2015
5 5 #
6 6 # Advanced debian "jessie" bootstrap script for RPi2
7 7 #
8 8 # This program is free software; you can redistribute it and/or
9 9 # modify it under the terms of the GNU General Public License
10 10 # as published by the Free Software Foundation; either version 2
11 11 # of the License, or (at your option) any later version.
12 12 #
13 13 # some parts based on rpi2-build-image:
14 14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
15 15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
16 16 ########################################################################
17 17
18 18 source ./functions.sh
19 19
20 20 set -e
21 21 set -x
22 22
23 23 # Debian release
24 24 RELEASE=${RELEASE:=jessie}
25 25 KERNEL=${KERNEL:=3.18.0-trunk-rpi2}
26 26
27 27 # Build settings
28 28 BASEDIR=$(pwd)/images/${RELEASE}
29 29 BUILDDIR=${BASEDIR}/build
30 30
31 31 # General settings
32 32 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
33 33 PASSWORD=${PASSWORD:=raspberry}
34 34 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
35 35 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
36 36 XKBMODEL=${XKBMODEL:=""}
37 37 XKBLAYOUT=${XKBLAYOUT:=""}
38 38 XKBVARIANT=${XKBVARIANT:=""}
39 39 XKBOPTIONS=${XKBOPTIONS:=""}
40 40 EXPANDROOT=${EXPANDROOT:=true}
41 41
42 42 # Network settings
43 43 ENABLE_DHCP=${ENABLE_DHCP:=true}
44 44 # NET_* settings are ignored when ENABLE_DHCP=true
45 45 # NET_ADDRESS is an IPv4 or IPv6 address and its prefix, separated by "/"
46 46 NET_ADDRESS=${NET_ADDRESS:=""}
47 47 NET_GATEWAY=${NET_GATEWAY:=""}
48 48 NET_DNS_1=${NET_DNS_1:=""}
49 49 NET_DNS_2=${NET_DNS_2:=""}
50 50 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
51 51 NET_NTP_1=${NET_NTP_1:=""}
52 52 NET_NTP_2=${NET_NTP_2:=""}
53 53
54 54 # APT settings
55 55 APT_PROXY=${APT_PROXY:=""}
56 56 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
57 57
58 58 # Feature settings
59 59 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
60 60 ENABLE_IPV6=${ENABLE_IPV6:=true}
61 61 ENABLE_SSHD=${ENABLE_SSHD:=true}
62 62 ENABLE_SOUND=${ENABLE_SOUND:=true}
63 63 ENABLE_DBUS=${ENABLE_DBUS:=true}
64 64 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
65 65 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
66 66 ENABLE_XORG=${ENABLE_XORG:=false}
67 67 ENABLE_WM=${ENABLE_WM:=""}
68 68 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
69 69 ENABLE_USER=${ENABLE_USER:=true}
70 70 ENABLE_ROOT=${ENABLE_ROOT:=false}
71 71 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
72 72
73 73 # Advanced settings
74 74 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
75 75 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
76 76 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
77 77 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
78 78 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
79 79
80 80 # Kernel compilation settings
81 81 BUILD_KERNEL=${BUILD_KERNEL:=false}
82 82 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
83 83
84 84 # Image chroot path
85 85 R=${BUILDDIR}/chroot
86 86 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
87 87
88 88 # Packages required for bootstrapping
89 89 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core"
90 90
91 91 # Missing packages that need to be installed
92 92 MISSING_PACKAGES=""
93 93
94 94 # Packages required in the chroot build environment
95 95 APT_INCLUDES=${APT_INCLUDES:=""}
96 96 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,ca-certificates,debian-archive-keyring,dialog,sudo"
97 97
98 98 set +x
99 99
100 100 # Are we running as root?
101 101 if [ "$(id -u)" -ne "0" ] ; then
102 102 echo "this script must be executed with root privileges"
103 103 exit 1
104 104 fi
105 105
106 106 # Add packages required for kernel cross compilation
107 107 if [ "$BUILD_KERNEL" = true ] ; then
108 108 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
109 109 fi
110 110
111 111 # Check if all required packages are installed
112 112 for package in $REQUIRED_PACKAGES ; do
113 113 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
114 114 MISSING_PACKAGES="$MISSING_PACKAGES $package"
115 115 fi
116 116 done
117 117
118 118 # Ask if missing packages should get installed right now
119 119 if [ -n "$MISSING_PACKAGES" ] ; then
120 120 echo "the following packages needed by this script are not installed:"
121 121 echo "$MISSING_PACKAGES"
122 122
123 123 echo -n "\ndo you want to install the missing packages right now? [y/n] "
124 124 read confirm
125 125 if [ "$confirm" != "y" ] ; then
126 126 exit 1
127 127 fi
128 128 fi
129 129
130 130 # Make sure all required packages are installed
131 131 apt-get -qq -y install ${REQUIRED_PACKAGES}
132 132
133 133 # Don't clobber an old build
134 134 if [ -e "$BUILDDIR" ]; then
135 135 echo "directory $BUILDDIR already exists, not proceeding"
136 136 exit 1
137 137 fi
138 138
139 139 set -x
140 140
141 141 # Call "cleanup" function on various signals and errors
142 142 trap cleanup 0 1 2 3 6
143 143
144 144 # Set up chroot directory
145 145 mkdir -p $R
146 146
147 147 # Add required packages for the minbase installation
148 148 if [ "$ENABLE_MINBASE" = true ] ; then
149 149 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools"
150 150 else
151 151 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
152 152 fi
153 153
154 154 # Add parted package, required to get partprobe utility
155 155 if [ "$EXPANDROOT" = true ] ; then
156 156 APT_INCLUDES="${APT_INCLUDES},parted"
157 157 fi
158 158
159 159 # Add dbus package, recommended if using systemd
160 160 if [ "$ENABLE_DBUS" = true ] ; then
161 161 APT_INCLUDES="${APT_INCLUDES},dbus"
162 162 fi
163 163
164 164 # Add iptables IPv4/IPv6 package
165 165 if [ "$ENABLE_IPTABLES" = true ] ; then
166 166 APT_INCLUDES="${APT_INCLUDES},iptables"
167 167 fi
168 168
169 169 # Add openssh server package
170 170 if [ "$ENABLE_SSHD" = true ] ; then
171 171 APT_INCLUDES="${APT_INCLUDES},openssh-server"
172 172 fi
173 173
174 174 # Add alsa-utils package
175 175 if [ "$ENABLE_SOUND" = true ] ; then
176 176 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
177 177 fi
178 178
179 179 # Add rng-tools package
180 180 if [ "$ENABLE_HWRANDOM" = true ] ; then
181 181 APT_INCLUDES="${APT_INCLUDES},rng-tools"
182 182 fi
183 183
184 184 if [ "$ENABLE_USER" = true ]; then
185 185 APT_INCLUDES="${APT_INCLUDES},sudo"
186 186 fi
187 187
188 188 # Add fbturbo video driver
189 189 if [ "$ENABLE_FBTURBO" = true ] ; then
190 190 # Enable xorg package dependencies
191 191 ENABLE_XORG=true
192 192 fi
193 193
194 194 # Add user defined window manager package
195 195 if [ -n "$ENABLE_WM" ] ; then
196 196 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
197 197
198 198 # Enable xorg package dependencies
199 199 ENABLE_XORG=true
200 200 fi
201 201
202 202 # Add xorg package
203 203 if [ "$ENABLE_XORG" = true ] ; then
204 204 APT_INCLUDES="${APT_INCLUDES},xorg"
205 205 fi
206 206
207 207 ## Main bootstrap
208 208 for i in bootstrap.d/*.sh; do
209 209 . $i
210 210 done
211 211
212 ## Custom bootstrap scripts
213 if [ -d "custom.d" ]; then
212 214 for i in custom.d/*.sh; do
213 215 . $i
214 216 done
217 fi
215 218
216 219 # Invoke custom scripts
217 220 if [ -n "${CHROOT_SCRIPTS}" ]; then
218 221 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
219 222 LANG=C chroot $R bash -c 'for SCRIPT in /chroot_scripts/*; do if [ -f $SCRIPT -a -x $SCRIPT ]; then $SCRIPT; fi done;'
220 223 rm -rf "${R}/chroot_scripts"
221 224 fi
222 225
223 226 ## Cleanup
224 227 chroot_exec apt-get -y clean
225 228 chroot_exec apt-get -y autoclean
226 229 chroot_exec apt-get -y autoremove
227 230
228 231 # Unmount mounted filesystems
229 232 umount -l $R/proc
230 233 umount -l $R/sys
231 234
232 235 # Clean up files
233 236 rm -f $R/etc/apt/sources.list.save
234 237 rm -f $R/etc/resolvconf/resolv.conf.d/original
235 238 rm -rf $R/run
236 239 mkdir -p $R/run
237 240 rm -f $R/etc/*-
238 241 rm -f $R/root/.bash_history
239 242 rm -rf $R/tmp/*
240 243 rm -f $R/var/lib/urandom/random-seed
241 244 [ -L $R/var/lib/dbus/machine-id ] || rm -f $R/var/lib/dbus/machine-id
242 245 rm -f $R/etc/machine-id
243 246 rm -fr $R/etc/apt/apt.conf.d/10proxy
244 247 rm -f $R/etc/resolv.conf
245 248
246 249 # Calculate size of the chroot directory in KB
247 250 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`)
248 251
249 252 # Calculate the amount of needed 512 Byte sectors
250 253 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
251 254 BOOT_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
252 255 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS})
253 256
254 257 # The root partition is EXT4
255 258 # This means more space than the actual used space of the chroot is used.
256 259 # As overhead for journaling and reserved blocks 20% are added.
257 260 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
258 261
259 262 # Calculate required image size in 512 Byte sectors
260 263 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS} + ${ROOT_SECTORS})
261 264
262 265 # Prepare date string for image file name
263 266 DATE="$(date +%Y-%m-%d)"
264 267
265 268 # Prepare image file
266 269 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
267 270 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
268 271
269 272 # Write partition table
270 273 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
271 274 unit: sectors
272 275
273 276 1 : start= ${TABLE_SECTORS}, size= ${BOOT_SECTORS}, Id= c, bootable
274 277 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
275 278 3 : start= 0, size= 0, Id= 0
276 279 4 : start= 0, size= 0, Id= 0
277 280 EOM
278 281
279 282 # Set up temporary loop devices and build filesystems
280 283 VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
281 284 EXT4_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
282 285 mkfs.vfat "$VFAT_LOOP"
283 286 mkfs.ext4 "$EXT4_LOOP"
284 287
285 288 # Mount the temporary loop devices
286 289 mkdir -p "$BUILDDIR/mount"
287 290 mount "$EXT4_LOOP" "$BUILDDIR/mount"
288 291
289 292 mkdir -p "$BUILDDIR/mount/boot/firmware"
290 293 mount "$VFAT_LOOP" "$BUILDDIR/mount/boot/firmware"
291 294
292 295 # Copy all files from the chroot to the loop device mount point directory
293 296 rsync -a "$R/" "$BUILDDIR/mount/"
294 297
295 298 # Unmount all temporary loop devices and mount points
296 299 cleanup
297 300
298 301 # (optinal) create block map file for "bmaptool"
299 302 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
300 303
301 304 # Image was successfully created
302 305 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img (${IMAGE_SIZE})" ": successfully created"
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant