Merge lp:~hrw/cirros/add-uefi-grub-support into lp:cirros

Proposed by Marcin Juszkiewicz on 2016-07-05
Status: Merged
Merged at revision: 371
Proposed branch: lp:~hrw/cirros/add-uefi-grub-support
Merge into: lp:cirros
Diff against target: 2250 lines (+1018/-603)
15 files modified
README (+7/-0)
bin/build-arch (+12/-7)
bin/build-efi-images (+161/-0)
bin/build-initramfs (+35/-39)
bin/build-release (+84/-68)
bin/bundle (+162/-140)
bin/common-functions.sh (+43/-0)
bin/grab-grub-efi (+114/-0)
bin/grab-kernels (+39/-25)
bin/mirror-dump-sstream-data (+83/-76)
bin/mkcabundle (+1/-0)
bin/part2disk (+165/-149)
bin/prepare-grub (+18/-17)
bin/system-setup (+22/-20)
bin/xmakedevs (+72/-62)
To merge this branch: bzr merge lp:~hrw/cirros/add-uefi-grub-support
Reviewer Review Type Date Requested Status
Scott Moser 2016-07-05 Approve on 2016-07-21
Review via email: mp+299185@code.launchpad.net

Description of the Change

This changeset adds support for UEFI booting on AArch64 and x86-64 architectures.

Grub2-efi from CentOS is used (as this distribution provides ready to use EFI binaries).

Disk images are switched to GPT scheme. Part1 is rootfs (from part.img as it was), part15 is EFI System Partition with EFI grub in place (on aarch64 and x86-64 only).

Also enabled ARM disk images to be part of release.

Boot tested:

- aarch64/uefi - grub
- aarch64/uefi - direct kernel
- arm - direct kernel
- i686/bios
- x86-64/bios
- x86-64/uefi

All those images booted fine. Not tested PPC ones yet.

To post a comment you must log in.
Scott Moser (smoser) wrote :

per hrw in irc
<hrw> 10:38:45> aarch64/uefi boots, x86-64/uefi boots, arm/direct-kernel boots, x86-64/bios boots but very slow, i686/bios same as x86-64/bios
<hrw> 10:44:02> looks like x86 bios boots have issue with lack of entropy as it takes ~199s before 'random: nonblocking pool is initialized' gets printed

Scott Moser (smoser) wrote :

i wonder why bios boots would boot slower than efi. thats odd.

Also, could you add some doc or something on how you've booted these.

ideally we have some test suite at some point that can do all that, but for now at least something like README-powerpc in doc/

overally this is very good. and thank you.
some comments inline.

review: Needs Fixing
lp:~hrw/cirros/add-uefi-grub-support updated on 2016-07-20
374. By Marcin Juszkiewicz on 2016-07-12

grab-grub-efi: add missing script

375. By Marcin Juszkiewicz on 2016-07-12

part2disk: update usage information

376. By Marcin Juszkiewicz on 2016-07-12

part2disk: cleanup in case of failure

377. By Marcin Juszkiewicz on 2016-07-12

system-setup: install dosfstools for mkfs.vfat for EFI system partition

378. By Marcin Juszkiewicz on 2016-07-12

part2disk: drop ip=dhcp from kernel cmdline

379. By Marcin Juszkiewicz on 2016-07-12

README: add note about fetching EFI grub from CentOS

380. By Marcin Juszkiewicz on 2016-07-12

part2disk: indent continuued line

381. By Marcin Juszkiewicz on 2016-07-15

use grub-efi from Ubuntu

382. By Marcin Juszkiewicz on 2016-07-15

Added license and author info to files I modified

383. By Marcin Juszkiewicz on 2016-07-15

part2disk: use bash by default

384. By Marcin Juszkiewicz on 2016-07-15

grab-kernels: remove temporary dir at the end

385. By Marcin Juszkiewicz on 2016-07-20

build-release: use Ubuntu grub-efi

386. By Marcin Juszkiewicz on 2016-07-20

part2disk: search for root partition to avoid 256KB sector size issue

387. By Marcin Juszkiewicz on 2016-07-20

Use build-efi-images from grub2 package to get working binaries

Marcin Juszkiewicz (hrw) wrote :

aarch64 boots fine, x86_64 complains about non-signed kernel

lp:~hrw/cirros/add-uefi-grub-support updated on 2016-07-20
388. By Marcin Juszkiewicz on 2016-07-20

part2disk: do not use linuxefi command so boot on x86-64/uefi works

389. By Marcin Juszkiewicz on 2016-07-20

bundle: stop stripping modules from initramfs - virtio_scsi is needed for storage

390. By Marcin Juszkiewicz on 2016-07-20

ship EFI grub for aarch64, arm, i386, x86-64

391. By Marcin Juszkiewicz on 2016-07-20

README: point to grub-efi from Ubuntu

392. By Marcin Juszkiewicz on 2016-07-20

move common functions into shared script

error() fail() dl() etc are present in most of scripts
so I moved them to common file as it may allow to easy
change them if needed

Scott Moser (smoser) wrote :

overall, please fix white spaces in bin/ to be 4 spaces indentation, no tabs.
other comments in line.
they're all nit picks and small things.
you have done great here, thank you!

lp:~hrw/cirros/add-uefi-grub-support updated on 2016-07-20
393. By Marcin Juszkiewicz on 2016-07-20

use bash for all scripts

394. By Marcin Juszkiewicz on 2016-07-20

build-efi-images: added note about original source

395. By Marcin Juszkiewicz on 2016-07-20

quote path for common-functions.sh

396. By Marcin Juszkiewicz on 2016-07-20

build-release: drop copyright message

As suggested by Scott in review.

397. By Marcin Juszkiewicz on 2016-07-20

build-release: quote GVER just in case

398. By Marcin Juszkiewicz on 2016-07-20

use quotes where needed

Marcin Juszkiewicz (hrw) :
lp:~hrw/cirros/add-uefi-grub-support updated on 2016-07-21
399. By Marcin Juszkiewicz on 2016-07-21

whitespace cleanup

all scripts (except build-efi-images) got converted to 4 spaces instead of tab
vim settings unified in all files
some blank lines added here and there for readability (few duplicated removed)

400. By Marcin Juszkiewicz on 2016-07-21

use getopt for all arguments, not just for a few

I found use of var=${X} (where X is a number) disguisting in script which
also uses getopt.

Scott Moser (smoser) wrote :

Hi,
I'm marking this as 'merged'. Ive taken everything into trunk at revno 398 except for revno 389. I'd like to avoid complete waste of space that is /lib/modules duplication in initramfs and /lib/modules in the filesystem.

The things remaining from this branch in roughly the order of importance are:
a.) test powerpc and ppc64el
b.) bin/part2disk cleanup to not re-cleanup and basically better tracking
    of the work it needs to un-do (mounts and kpartx -d). We
    want to leave the system in as best state as we can.
c.) address the '.smaller' (please see my comment in bin/bundle)
d.) getopt changes
e.) softtabstop= and such

Thank you Marcin!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2015-09-22 17:11:50 +0000
3+++ README 2016-07-21 10:53:24 +0000
4@@ -46,6 +46,13 @@
5 $ kver="3.19.0-20.20~14.04.1"
6 $ ./bin/grab-kernels "$kver"
7
8+ * Download EFI grub to use.
9+ The grub-efi input to bundle will be in tar.gz format.
10+
11+ # gver is newest from https://launchpad.net/ubuntu/+source/grub2
12+ $ gver="2.02~beta2-36ubuntu8"
13+ $ ./bin/grab-grub-efi "$gver"
14+
15 * build disk images using bin/bundle
16 $ sudo ./bin/bundle -v --arch=$ARCH output/$ARCH/rootfs.tar \
17 download/kernel-$ARCH.deb output/$ARCH/images
18
19=== modified file 'bin/build-arch'
20--- bin/build-arch 2011-09-12 15:06:55 +0000
21+++ bin/build-arch 2016-07-21 10:53:24 +0000
22@@ -1,7 +1,9 @@
23-#!/bin/sh
24+#!/bin/bash
25+
26+source "${0%/*}/common-functions.sh"
27
28 Usage() {
29- cat <<EOF
30+ cat <<EOF
31 ${0##*/} buildroot-dir arch output [confd]
32
33 build the buildroot dir in buildroot-dir
34@@ -9,11 +11,8 @@
35 EOF
36 }
37
38-error() { echo "$@" 1>&2; }
39-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
40-
41 [ $# -eq 3 -o $# -eq 4 ] ||
42- { Usage 1>&2; exit 1; }
43+ { Usage 1>&2; exit 1; }
44 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
45
46
47@@ -22,19 +21,25 @@
48 out=${3}
49 shift 3
50 confd=""
51+
52 [ $# -eq 0 ] && set -- make
53
54 [ -n "$confd" ] || confd=$( cd "${0%/*}/../conf" && pwd) ||
55- fail "failed to find conf dir"
56+ fail "failed to find conf dir"
57
58 mkdir -p "$out" || fail "failed to make outdir $out"
59+
60 out=$(cd "${out}" && pwd)
61+
62 [ -e "$confd/.config" ] ||
63 cp "$confd/buildroot-$arch.config" "$confd/.config" ||
64 fail "failed to copy buildroot config"
65+
66 [ -e "$confd/busybox.config" ] ||
67 cp "$confd/busybox.config" "$out/busybox.config" ||
68 fail "failed to copy busybox config"
69
70 cd "$bdir"
71 make "O=$BR_OUT" "BUSYBOX_CONFIG_FILE=$out/busybox.config" "$@"
72+
73+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
74
75=== added file 'bin/build-efi-images'
76--- bin/build-efi-images 1970-01-01 00:00:00 +0000
77+++ bin/build-efi-images 2016-07-21 10:53:24 +0000
78@@ -0,0 +1,161 @@
79+#! /bin/bash
80+set -e
81+
82+#
83+# Script taken from grub2 Ubuntu package.
84+# it is debian/build-efi-images
85+#
86+
87+# Copyright (C) 2010, 2011, 2012 Canonical Ltd.
88+# Author: Colin Watson <cjwatson@ubuntu.com>
89+#
90+# This program is free software; you can redistribute it and/or modify it
91+# under the terms of the GNU General Public License as published by the Free
92+# Software Foundation; either version 2, or (at your option) any later
93+# version.
94+#
95+# This program is distributed in the hope that it will be useful, but
96+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
97+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
98+# for more details.
99+#
100+# You should have received a copy of the GNU General Public License along
101+# with this program; if not, write to the Free Software Foundation, Inc.,
102+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
103+
104+# Make EFI boot images for signing.
105+
106+if [ $# -lt 5 ]; then
107+ echo "usage: $0 GRUB-MKIMAGE GRUB-CORE OUTPUT-DIRECTORY PLATFORM EFI-NAME"
108+fi
109+
110+grub_mkimage="$1"
111+grub_core="$2"
112+outdir="$3"
113+platform="$4"
114+efi_name="$5"
115+
116+workdir=
117+
118+cleanup () {
119+ [ -z "$workdir" ] || rm -rf "$workdir"
120+}
121+trap cleanup EXIT HUP INT QUIT TERM
122+
123+rm -rf "$outdir"
124+mkdir -p "$outdir"
125+
126+workdir="$(mktemp -d build-efi-images.XXXXXX)"
127+
128+# GRUB's rescue parser doesn't understand 'if'.
129+echo 'normal (memdisk)/grub.cfg' >"$workdir/grub-bootstrap.cfg"
130+
131+# Skeleton configuration file which finds the real boot disk.
132+cat >"$workdir/grub.cfg" <<EOF
133+if [ -z "\$prefix" -o ! -e "\$prefix" ]; then
134+ if ! search --file --set=root /.disk/info; then
135+ search --file --set=root /.disk/mini-info
136+ fi
137+ set prefix=(\$root)/boot/grub
138+fi
139+if [ -e \$prefix/$platform/grub.cfg ]; then
140+ source \$prefix/$platform/grub.cfg
141+elif [ -e \$prefix/grub.cfg ]; then
142+ source \$prefix/grub.cfg
143+else
144+ source \$cmdpath/grub.cfg
145+fi
146+EOF
147+
148+cat >"$workdir/grub-netboot.cfg" <<EOF
149+if [ -e \$prefix/$platform/grub.cfg ]; then
150+ source \$prefix/$platform/grub.cfg
151+else
152+ source \$prefix/grub.cfg
153+fi
154+EOF
155+
156+mkfs.msdos -C "$workdir/memdisk.fat" 64
157+mcopy -i "$workdir/memdisk.fat" "$workdir/grub.cfg" ::grub.cfg
158+
159+mkfs.msdos -C "$workdir/memdisk-netboot.fat" 64
160+mcopy -i "$workdir/memdisk-netboot.fat" "$workdir/grub-netboot.cfg" ::grub.cfg
161+
162+CD_MODULES="
163+ all_video
164+ boot
165+ btrfs
166+ cat
167+ chain
168+ configfile
169+ echo
170+ efifwsetup
171+ efinet
172+ ext2
173+ fat
174+ font
175+ gettext
176+ gfxmenu
177+ gfxterm
178+ gfxterm_background
179+ gzio
180+ halt
181+ hfsplus
182+ iso9660
183+ jpeg
184+ keystatus
185+ loadenv
186+ linux
187+ lsefi
188+ lsefimmap
189+ lsefisystab
190+ lssal
191+ memdisk
192+ minicmd
193+ normal
194+ part_apple
195+ part_msdos
196+ part_gpt
197+ password_pbkdf2
198+ png
199+ reboot
200+ search
201+ search_fs_uuid
202+ search_fs_file
203+ search_label
204+ sleep
205+ test
206+ true
207+ video
208+ "
209+
210+# Platform-specific modules
211+case $platform in
212+ x86_64-efi)
213+ CD_MODULES="$CD_MODULES
214+ linuxefi
215+ "
216+ ;;
217+esac
218+
219+GRUB_MODULES="$CD_MODULES
220+ lvm
221+ mdraid09
222+ mdraid1x
223+ "
224+NET_MODULES="$CD_MODULES
225+ tftp
226+ "
227+
228+"$grub_mkimage" -O "$platform" -o "$outdir/gcd$efi_name.efi" \
229+ -d "$grub_core" \
230+ -c "$workdir/grub-bootstrap.cfg" -m "$workdir/memdisk.fat" \
231+ -p /boot/grub \
232+ $CD_MODULES
233+"$grub_mkimage" -O "$platform" -o "$outdir/grub$efi_name.efi" \
234+ -d "$grub_core" -p /EFI/ubuntu $GRUB_MODULES
235+"$grub_mkimage" -O "$platform" -o "$outdir/grubnet$efi_name.efi" \
236+ -d "$grub_core" -c "$workdir/grub-bootstrap.cfg" \
237+ -m "$workdir/memdisk-netboot.fat" -p /grub $NET_MODULES
238+
239+exit 0
240
241=== modified file 'bin/build-initramfs'
242--- bin/build-initramfs 2011-10-05 07:34:10 +0000
243+++ bin/build-initramfs 2016-07-21 10:53:24 +0000
244@@ -1,17 +1,11 @@
245 #!/bin/bash
246-# vi: ts=4 noexpandtab
247+
248+source "${0%/*}/common-functions.sh"
249
250 TEMP_D=""
251
252-error() { echo "$@" 1>&2; }
253-debug() {
254- [ "${DEBUG}" -ge "${1}" ] || return 0;
255- shift;
256- error "$@"
257-}
258-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
259 Usage() {
260- cat <<EOF
261+ cat <<EOF
262 Usage: ${0##*/} initramfs_dir root_dir
263 create an initramfs from initramfs_dir, copying files from root_dir
264
265@@ -19,26 +13,25 @@
266 ${0##*/} initramfs/ rootfs/ > my.initramfs.img
267 EOF
268 }
269-bad_Usage() { Usage 1>&2; fail "$@"; }
270 cleanup() {
271- [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
272+ [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
273 }
274
275 short_opts="hv"
276 long_opts="help,verbose"
277 getopt_out=$(getopt --name "${0##*/}" \
278- --options "${short_opts}" --long "${long_opts}" -- "$@") &&
279- eval set -- "${getopt_out}" ||
280- bad_Usage
281+ --options "${short_opts}" --long "${long_opts}" -- "$@") &&
282+ eval set -- "${getopt_out}" ||
283+ bad_Usage
284
285 while [ $# -ne 0 ]; do
286- cur=${1}; next=${2};
287- case "$cur" in
288- -h|--help) Usage; exit 0;;
289- -v|--verbose) DEBUG=$((${DEBUG}+1));;
290- --) shift; break;;
291- esac
292- shift;
293+ cur=${1}; next=${2};
294+ case "$cur" in
295+ -h|--help) Usage; exit 0;;
296+ -v|--verbose) DEBUG=$((${DEBUG}+1));;
297+ --) shift; break;;
298+ esac
299+ shift;
300 done
301
302 [ $# -eq 2 ] || bad_Usage "must give initramfs_dir and root_dir"
303@@ -49,7 +42,7 @@
304 [ -d "$root_d" ] || fail "$root_d is not a dir"
305
306 TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") ||
307- fail "failed to make tempd"
308+ fail "failed to make tempd"
309 trap cleanup EXIT
310
311 work_d="${TEMP_D}/workd"
312@@ -62,32 +55,35 @@
313 mkdir -p "${work_d}/"{bin,sbin,usr/bin,usr/sbin}
314
315 while read need; do
316- need=${need%%#*}; need=${need% };
317- [ -n "$need" ] || continue
318- [ "${need#*..}" = "${need}" ] || fail "paths cannot have ..: $need"
319- if [ -e "$root_d/$need" ]; then
320- mkdir -p "$work_d/${need%/*}" &&
321- cp -a "$root_d/$need" "$work_d/$need" ||
322- fail "failed to copy $need to working dir"
323- else
324- fail "$need not found in $root_d"
325- fi
326+ need=${need%%#*}; need=${need% };
327+ [ -n "$need" ] || continue
328+ [ "${need#*..}" = "${need}" ] || fail "paths cannot have ..: $need"
329+ if [ -e "$root_d/$need" ]; then
330+ mkdir -p "$work_d/${need%/*}" &&
331+ cp -a "$root_d/$need" "$work_d/$need" ||
332+ fail "failed to copy $need to working dir"
333+ else
334+ fail "$need not found in $root_d"
335+ fi
336 done < $needs
337
338 loaders=$(cd "$root_d" &&
339- echo lib/ld-uClibc.so.0 lib/ld-uClibc-*.so \
340- lib/ld64-uClibc.so.0 lib/ld64-uClibc-*.so)
341+ echo lib/ld-uClibc.so.0 lib/ld-uClibc-*.so \
342+ lib/ld64-uClibc.so.0 lib/ld64-uClibc-*.so)
343
344 for f in $loaders; do
345- [ -f "$root_d/$f" ] || continue
346- mkdir -p "${work_d}/${f%/*}" &&
347- cp -a "$root_d/$f" "$work_d/$f" ||
348- fail "failed to copy $f"
349+
350+ [ -f "$root_d/$f" ] || continue
351+
352+ mkdir -p "${work_d}/${f%/*}" &&
353+ cp -a "$root_d/$f" "$work_d/$f" ||
354+ fail "failed to copy $f"
355 done
356
357 rsync -a "$src_d/" "$work_d" ||
358- fail "failed to sync $src_d to working dir"
359+ fail "failed to sync $src_d to working dir"
360
361 ( cd "${work_d}" && find . | cpio --quiet --dereference -o -H newc | gzip -9 )
362
363 exit 0
364+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
365
366=== modified file 'bin/build-release'
367--- bin/build-release 2016-06-29 19:37:37 +0000
368+++ bin/build-release 2016-07-21 10:53:24 +0000
369@@ -1,18 +1,37 @@
370 #!/bin/bash
371+#
372+# Authors: Scott Moser <smoser@canonical.com>
373+# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
374+#
375+# This program is free software: you can redistribute it and/or modify
376+# it under the terms of the GNU General Public License as published by
377+# the Free Software Foundation, version 3 of the License.
378+#
379+# This program is distributed in the hope that it will be useful,
380+# but WITHOUT ANY WARRANTY; without even the implied warranty of
381+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
382+# GNU General Public License for more details.
383+#
384+# You should have received a copy of the GNU General Public License
385+# along with this program. If not, see <http://www.gnu.org/licenses/>.
386
387 [ $# -ge 1 ] || { echo "must give version"; exit 1; }
388
389+source "${0%/*}/common-functions.sh"
390+
391 VER=$1
392 daily=false
393 if [ "$1" = "daily" ]; then
394- VER="d$(date +%y%m%d)"
395- daily=true
396+ VER="d$(date +%y%m%d)"
397+ daily=true
398 fi
399 shift
400+
401 pre=cirros-$VER
402 BR_VER="2015.05"
403 ARCHES="${ARCHES:-i386 x86_64 arm powerpc aarch64 ppc64 ppc64le}"
404-KVER="4.4.0-28.47"
405+KVER="4.4.0-28.47" # Ubuntu 16.04
406+GVER="2.02~beta2-36ubuntu8"
407 ME=$(readlink -f "$0")
408 MY_D=${ME%/*}
409 PATH=${MY_D}:$PATH
410@@ -25,40 +44,29 @@
411 export TMPDIR="$OUT/tmp"
412 mkdir -p "$OUT" "$TMPDIR"
413
414-dl() {
415- local url="$1" target="$2" tfile="" t=""
416- [ -f "$target" ] && return
417- t=$(dirname "$target")
418- tfile=$(mktemp "$t/.${0##*/}.XXXXXX") || return
419- wget "$url" -O "$tfile" &&
420- mv "$tfile" "$target" ||
421- { t=$?; rm -f "$tfile"; return $t; }
422-}
423 msg() {
424- echo "$@" >> "$LOGFILE"
425- echo "$@"
426+ echo "$@" >> "$LOGFILE"
427+ echo "$@"
428 }
429+
430 logevent() {
431- # logevent(msg, [from])
432- # log the message in $1 and time since $2, defaulting to last call.
433- local up delta msg="$1" ref="$2"
434- up=${SECONDS}
435- if [ "$ref" = "-" ]; then
436- ref=""
437- elif [ "$ref" = "" ]; then
438- ref="${_LAST_UP}"
439- fi
440- if [ -n "$ref" ]; then
441- delta="$(($up-$ref))"
442- fi
443- msg "$(date -R)" "$msg" "${delta:+[${delta}s]}"
444- _LAST_UP=$up
445- _RET=${_LAST_UP}
446+ # logevent(msg, [from])
447+ # log the message in $1 and time since $2, defaulting to last call.
448+ local up delta msg="$1" ref="$2"
449+ up=${SECONDS}
450+ if [ "$ref" = "-" ]; then
451+ ref=""
452+ elif [ "$ref" = "" ]; then
453+ ref="${_LAST_UP}"
454+ fi
455+ if [ -n "$ref" ]; then
456+ delta="$(($up-$ref))"
457+ fi
458+ msg "$(date -R)" "$msg" "${delta:+[${delta}s]}"
459+ _LAST_UP=$up
460+ _RET=${_LAST_UP}
461 }
462
463-error() { echo "$@" 1>&2; }
464-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
465-
466 build_arch() {
467 local arch="" quiet=false cmd="" log=""
468 if [ "$1" = "quiet" ]; then
469@@ -147,23 +155,29 @@
470 "$0" "$VER" build_arch quiet {} ::: ${ARCHES}
471 else
472 for arch in ${ARCHES}; do
473- build_arch "$arch"
474+ build_arch "$arch"
475 done;
476 fi
477
478+logevent "start grub EFI download" -
479+grab-grub-efi "$GVER" $ARCHES
480+logevent "end grub EFI download"
481+
482 for arch in ${ARCHES}; do
483- mkdir -p "$OUT/stage/$arch"
484+ mkdir -p "$OUT/stage/$arch"
485 done
486
487 logevent "start bundling" -
488 for arch in ${ARCHES}; do
489- case "$arch" in
490- powerpc|ppc*|aarch64) size=96M;;
491- *) size="";;
492- esac
493- sudo ./bin/bundle -v ${size:+--size=$size} --arch="$arch" \
494- "$OUT/build/$arch/rootfs.tar" \
495- ./download/kernel-$arch.tar.gz "$OUT/stage/$arch";
496+ case "$arch" in
497+ powerpc|ppc*|aarch64) size=96M;;
498+ *) size="";;
499+ esac
500+ sudo ./bin/bundle -v ${size:+--size=$size} --arch="$arch" \
501+ --rootfs "$OUT/build/$arch/rootfs.tar" \
502+ --kernel ./download/kernel-$arch.tar.gz \
503+ --grub-efi-tar ./download/grub-efi-$arch.tar.gz \
504+ --outdir "$OUT/stage/$arch";
505 done
506 logevent "finish bundling"
507
508@@ -175,52 +189,54 @@
509 #bzr export -r "tag:$VER" --format=tgz --root="cirros-$VER" "$srctgz"
510 #echo "wrote source tgz: $srctgz"
511 if ! $daily; then
512- ( srcd="$PWD" && tmpd=$(mktemp -d) && cd "$tmpd" &&
513- bzr branch "$srcd" -r tag:$VER cirros-$VER &&
514- rm -Rf cirros-$VER/.bzr &&
515- echo "$VER" > "cirros-$VER/src/etc/cirros/version" &&
516- tar cvzf - cirros-$VER ) > "$OUT/release/cirros-$VER-source.tar.gz"
517+ ( srcd="$PWD" && tmpd=$(mktemp -d) && cd "$tmpd" &&
518+ bzr branch "$srcd" -r tag:$VER cirros-$VER &&
519+ rm -Rf cirros-$VER/.bzr &&
520+ echo "$VER" > "cirros-$VER/src/etc/cirros/version" &&
521+ tar cvzf - cirros-$VER ) > "$OUT/release/cirros-$VER-source.tar.gz"
522 fi
523
524 rm -f "$OUT/stage"/*/"$pre"*
525 for arch in ${ARCHES}; do
526- p=$pre-$arch
527- ( cd "$OUT/stage/$arch" &&
528- ln kernel $p-vmlinuz && ln kernel $p-kernel &&
529- ln initramfs $p-initrd && ln initramfs $p-initramfs &&
530- ln part.img $p-rootfs.img &&
531- ln blank.img $p-blank.img &&
532- ln disk.img $p-disk.img &&
533- ln filesys.tar.gz $p-lxc.tar.gz &&
534- true
535- ); done
536+ p=$pre-$arch
537+ ( cd "$OUT/stage/$arch" &&
538+ ln kernel $p-vmlinuz && ln kernel $p-kernel &&
539+ ln initramfs $p-initrd && ln initramfs $p-initramfs &&
540+ ln part.img $p-rootfs.img &&
541+ ln blank.img $p-blank.img &&
542+ ln disk.img $p-disk.img &&
543+ ln filesys.tar.gz $p-lxc.tar.gz &&
544+ true
545+ );
546+done
547
548 logevent "start populating release" -
549 for arch in ${ARCHES}; do
550- p=$pre-$arch
551- ( cd "$OUT/stage/$arch" &&
552- cp $p-kernel $p-initramfs $p-lxc.tar.gz "$OUT/release/" &&
553- gzip -9 -c $p-rootfs.img > $OUT/release/$p-rootfs.img.gz ) &&
554- ( cd "$OUT/stage/$arch" &&
555- tar cvzf - $p-blank.img $p-vmlinuz $p-initrd ) > \
556- "$OUT/release/$p-uec.tar.gz"
557- [ "$arch" = "arm" ] ||
558- cp "$OUT/stage/$arch/$p-disk.img" "$OUT/release/$p-disk.img"
559+ p=$pre-$arch
560+ ( cd "$OUT/stage/$arch" &&
561+ cp $p-kernel $p-initramfs $p-lxc.tar.gz "$OUT/release/" &&
562+ gzip -9 -c $p-rootfs.img > $OUT/release/$p-rootfs.img.gz ) &&
563+ ( cd "$OUT/stage/$arch" &&
564+ tar cvzf - $p-blank.img $p-vmlinuz $p-initrd ) > \
565+ "$OUT/release/$p-uec.tar.gz"
566+ cp "$OUT/stage/$arch/$p-disk.img" "$OUT/release/$p-disk.img"
567 done
568
569 mkdir -p "$OUT/release/buildroot_rootfs"
570 for arch in ${ARCHES}; do
571- t="$OUT/release/buildroot_rootfs/buildroot-$VER-$arch.tar"
572- cp "$OUT/build/$arch/rootfs.tar" "$t" && gzip --force -9 "$t"
573+ t="$OUT/release/buildroot_rootfs/buildroot-$VER-$arch.tar"
574+ cp "$OUT/build/$arch/rootfs.tar" "$t" && gzip --force -9 "$t"
575 done
576
577 chmod u+rwX,go+rX -R "$OUT/release/"*
578
579 sumfiles=$(cd "$OUT/release" && for f in *; do
580- [ -f "$f" -a "$f" != MD5SUMS ] && echo "$f"; done)
581+ [ -f "$f" -a "$f" != MD5SUMS ] && echo "$f"; done)
582 ( cd "$OUT/release" && md5sum $sumfiles > MD5SUMS )
583
584 logevent "finish populate release" -
585 msg "output in $OUT/release"
586 msg "entire process took $SECONDS seconds"
587 logevent "finished" "$tstart"
588+
589+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
590
591=== modified file 'bin/bundle'
592--- bin/bundle 2016-06-29 19:31:13 +0000
593+++ bin/bundle 2016-07-21 10:53:24 +0000
594@@ -1,22 +1,32 @@
595 #!/bin/bash
596-# vi: ts=4 noexpandtab
597-#
598+#
599+# Copyright (C) 2010 Canonical Ltd.
600+#
601+# Authors: Scott Moser <smoser@canonical.com>
602+# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
603+#
604+# This program is free software: you can redistribute it and/or modify
605+# it under the terms of the GNU General Public License as published by
606+# the Free Software Foundation, version 3 of the License.
607+#
608+# This program is distributed in the hope that it will be useful,
609+# but WITHOUT ANY WARRANTY; without even the implied warranty of
610+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
611+# GNU General Public License for more details.
612+#
613+# You should have received a copy of the GNU General Public License
614+# along with this program. If not, see <http://www.gnu.org/licenses/>.
615+#
616+
617+source "${0%/*}/common-functions.sh"
618
619 TEMP_D=""
620 UMOUNT=""
621 DEF_SIZE=${DEF_SIZE:-32M}
622-DEBUG=0
623 DEF_MODULES="acpiphp e1000 ne2k-pci 8139cp pcnet32 ip_tables"
624
625-error() { echo "$@" 1>&2; }
626-debug() {
627- [ "${DEBUG}" -ge "${1}" ] || return 0;
628- shift;
629- error "$@"
630-}
631-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
632 Usage() {
633- cat <<EOF
634+ cat <<EOF
635 Usage: ${0##*/} rootfs.tar kpkg.deb output_dir
636 [re]Bundle a buildroot rootfs into a mini-cloud image
637
638@@ -28,44 +38,48 @@
639 ${0##*/} rootfs.tar linux-image-*-virtuaal*.deb build-output/
640 EOF
641 }
642-bad_Usage() { Usage 1>&2; fail "$@"; }
643+
644 cleanup() {
645- [ -z "${UMOUNT}" ] || umount "${UMOUNT}"
646- [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
647+ [ -z "${UMOUNT}" ] || umount "${UMOUNT}"
648+ [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
649 }
650+
651 xrsync() {
652- rsync --archive --xattrs --hard-links --acls --sparse "$@"
653+ rsync --archive --xattrs --hard-links --acls --sparse "$@"
654 }
655
656+size=${DEF_SIZE}
657+arch=
658+rootfs_in=
659+kpkg_in=
660+grub_efi_in=
661+out_d_in=
662+
663 short_opts="hs:v"
664-long_opts="arch:,initrd-busybox:,help,size:,verbose"
665+long_opts="arch:,initrd-busybox:,help,size:,verbose,rootfs:,kernel:,grub-efi-tar:,outdir:"
666 getopt_out=$(getopt --name "${0##*/}" \
667- --options "${short_opts}" --long "${long_opts}" -- "$@") &&
668- eval set -- "${getopt_out}" ||
669- bad_Usage
670+ --options "${short_opts}" --long "${long_opts}" -- "$@") &&
671+ eval set -- "${getopt_out}" ||
672+ bad_Usage
673+while [ $# -ne 0 ]; do
674+ cur=${1}; next=${2};
675+ case "$cur" in
676+ -h|--help) Usage; exit 0;;
677+ -s|--size) size=${next}; shift;;
678+ --arch) arch=${next}; shift;;
679+ --rootfs) rootfs_in=${next}; shift;;
680+ --kernel) kpkg_in=${next}; shift;;
681+ --grub-efi-tar) grub_efi_in=${next}; shift;;
682+ --outdir) out_d_in=${next}; shift;;
683+ -v|--verbose) DEBUG=$((${DEBUG}+1));;
684+ --) shift; break;;
685+ esac
686+ shift;
687+done
688
689 topdir=$(cd "${0%/*}/.." && pwd)
690-size=${DEF_SIZE}
691 FS_LABEL="cirros-rootfs"
692 fs_type="ext3"
693-arch=""
694-
695-while [ $# -ne 0 ]; do
696- cur=${1}; next=${2};
697- case "$cur" in
698- -h|--help) Usage; exit 0;;
699- -s|--size) size=${next}; shift;;
700- --arch) arch=${next}; shift;;
701- -v|--verbose) DEBUG=$((${DEBUG}+1));;
702- --) shift; break;;
703- esac
704- shift;
705-done
706-
707-[ $# -eq 3 ] || bad_Usage "must give rootfs.tar, kernel pkg, out_dir"
708-rootfs_in=${1}
709-kpkg_in=${2}
710-out_d_in=${3}
711
712 PATH="$topdir/bin:$PATH"
713 src_dir="${topdir}/src"
714@@ -79,13 +93,13 @@
715 [ -d "${src_dir}" ] || fail "no source dir ${src_d}"
716
717 TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") ||
718- fail "failed to make tempd"
719+ fail "failed to make tempd"
720 trap cleanup EXIT
721
722 mkdir -p "${out_d_in}" && out_d=$(readlink -f "${out_d_in}") &&
723- rootfs=$(readlink -f "${rootfs_in}") &&
724- kpkg=$(readlink -f "${kpkg_in}") ||
725- fail "failed to get full path for input"
726+ rootfs=$(readlink -f "${rootfs_in}") &&
727+ kpkg=$(readlink -f "${kpkg_in}") ||
728+ fail "failed to get full path for input"
729
730 out_partimg="${out_d}/part.img"
731 out_diskimg="${out_d}/disk.img"
732@@ -112,199 +126,206 @@
733
734 modfile="$src_dir/etc/modules"
735 if [ -f "$modfile" ]; then
736- MODULES=$("$src_dir/etc/init.d/load-modules" parse_modules \
737+ MODULES=$("$src_dir/etc/init.d/load-modules" parse_modules \
738 "$modfile" "$arch") ||
739- fail "failed to read modules"
740- MODULES=$(echo "$MODULES" | sed 's, .*,,' | tr '\n' ' ')
741+ fail "failed to read modules"
742+ MODULES=$(echo "$MODULES" | sed 's, .*,,' | tr '\n' ' ')
743 else
744- MODULES=${DEF_MODULES}
745+ MODULES=${DEF_MODULES}
746 fi
747 debug 1 "modules: $MODULES"
748
749 prepare-grub "$xgrubd" ||
750- fail "failed to get grub binary"
751+ fail "failed to get grub binary"
752
753 mkdir -p "${mp}" "${kernel_d}" "${overlay_d}" \
754- "${initramfs_d}" "$inter_d" "$stage_d" ||
755- fail "failed to make temp dirs"
756+ "${initramfs_d}" "$inter_d" "$stage_d" ||
757+ fail "failed to make temp dirs"
758
759 debug 1 "creating filesystem in ${out_partimg}"
760 rm -f "$out_partimg"
761 truncate "--size=${size}" "${out_partimg}" ||
762- fail "failed to create ${out_partimg} of size ${size}"
763+ fail "failed to create ${out_partimg} of size ${size}"
764
765 out=$("mkfs.${fs_type}" -F "${out_partimg}" -L "${FS_LABEL}" 2>&1) ||
766- fail "failed to make filesystem of type ${fs_type}: ${out}"
767+ fail "failed to make filesystem of type ${fs_type}: ${out}"
768
769 cp "$out_partimg" "$out_blankimg" ||
770- fail "failed to to copy blank partition image"
771+ fail "failed to to copy blank partition image"
772
773 debug 1 "preparing kernel overlay"
774 # creating kernel tarball
775 case "$kpkg_in" in
776- *.deb)
777- dpkg -x "${kpkg_in}" "${kernel_d}" ||
778- fail "failed extracting kernel deb package in ${kpkg_in}"
779- ;;
780- *.tar*)
781- tar -C "$kernel_d" -xf "$kpkg_in" ||
782- fail "failed extracting kernel tarball in ${kpkg_in}"
783- ;;
784- *) fail "unknown file format for $kpkg_in";;
785+ *.deb)
786+ dpkg -x "${kpkg_in}" "${kernel_d}" ||
787+ fail "failed extracting kernel deb package in ${kpkg_in}"
788+ ;;
789+ *.tar*)
790+ tar -C "$kernel_d" -xf "$kpkg_in" ||
791+ fail "failed extracting kernel tarball in ${kpkg_in}"
792+ ;;
793+ *) fail "unknown file format for $kpkg_in";;
794 esac
795
796 ( cd "${kernel_d}" && find * -type f ) > "${kern_list_full}" ||
797- fail "failed to extract kernel to ${kernel_d}"
798+ fail "failed to extract kernel to ${kernel_d}"
799
800 kver=""
801 for x in "$kernel_d/lib/modules"/*; do
802- [ -d "$x/kernel" ] || continue
803- [ -z "$kver" ] ||
804- fail "2 or more things looked like kernels in lib/modules of $kpkg_in"
805- kver="${x##*/}"
806+ [ -d "$x/kernel" ] || continue
807+ [ -z "$kver" ] ||
808+ fail "2 or more things looked like kernels in lib/modules of $kpkg_in"
809+ kver="${x##*/}"
810 done
811 [ -n "$kver" ] ||
812- fail "failed to find kernel version. no lib/modules/* ?"
813+ fail "failed to find kernel version. no lib/modules/* ?"
814
815 depmod -a --basedir "${kernel_d}" "${kver}" ||
816- fail "failed to run depmod"
817+ fail "failed to run depmod"
818
819 mdep="${kernel_d}/lib/modules/${kver}/modules.dep"
820 for x in ${MODULES}; do
821- grep -q "/${x}.ko" "${mdep}" ||
822- { error "WARNING: no ${x} in kernel package!"; continue; }
823- awk -F: '$1 ~ mat {
824- sub(":","",$1)
825- printf("%s/%s\n",p,$1)
826- leng=split($0,deps," ")
827- x=2 # strange, but 0 contains nothing, 1 contains first field (with :)
828- while ( x<=leng ) {
829- printf("%s/%s\n", p, deps[x]);
830- x++
831- }
832- }' mat="/${x}.ko$" p="lib/modules/${kver}" "${mdep}"
833+ grep -q "/${x}.ko" "${mdep}" ||
834+ { error "WARNING: no ${x} in kernel package!"; continue; }
835+ awk -F: '$1 ~ mat {
836+ sub(":","",$1)
837+ printf("%s/%s\n",p,$1)
838+ leng=split($0,deps," ")
839+ x=2 # strange, but 0 contains nothing, 1 contains first field (with :)
840+ while ( x<=leng ) {
841+ printf("%s/%s\n", p, deps[x]);
842+ x++
843+ }
844+ }' mat="/${x}.ko$" p="lib/modules/${kver}" "${mdep}"
845 done > "${kern_modules}"
846 sort -u "${kern_modules}" > "${kern_files}"
847 vmlinuz=$( cd "${kernel_d}" && [ -f boot/vmlinu?-* ] &&
848- echo boot/vmlinu?-* ) && echo "${vmlinuz}" >> "${kern_files}" &&
849- ln -sf "$vmlinuz" "$kernel_d/vmlinuz" && echo "vmlinuz" >> "$kern_files" ||
850- fail "no kernel (boot/vmlinuz-*) found in ${kpkg_in}"
851+ echo boot/vmlinu?-* ) && echo "${vmlinuz}" >> "${kern_files}" &&
852+ ln -sf "$vmlinuz" "$kernel_d/vmlinuz" && echo "vmlinuz" >> "$kern_files" ||
853+ fail "no kernel (boot/vmlinuz-*) found in ${kpkg_in}"
854 echo "boot/config-$kver" >> "$kern_files"
855
856 tar -C "${kernel_d}" -cpf - \
857- --files-from "${kern_files}" > "${kernel_tar}" ||
858- fail "failed to collect kernel files"
859+ --files-from "${kern_files}" > "${kernel_tar}" ||
860+ fail "failed to collect kernel files"
861
862 debug 1 "preparing source overlay from ${src_dir}"
863 xrsync "${src_dir}/" "${overlay_d}" ||
864- fail "failed to copy source dir"
865+ fail "failed to copy source dir"
866
867 chown -R 0:0 "${overlay_d}" || fail "failed to chown files in overlay"
868-
869+
870 if [ -f "${src_symlinks}" ]; then
871- ( cd "${overlay_d}" &&
872- while read src target; do
873- { [ -d "${target%/*}" ] || mkdir -p "${target%/*}"; } ||
874- { error "could not create ${target%/*}"; exit 1; }
875- ln -sf "${src}" "${target}" || exit 1
876- done < "${src_symlinks}"
877- ) || fail "failed to create symlinks"
878+ ( cd "${overlay_d}" &&
879+ while read src target; do
880+ { [ -d "${target%/*}" ] || mkdir -p "${target%/*}"; } ||
881+ { error "could not create ${target%/*}"; exit 1; }
882+ ln -sf "${src}" "${target}" || exit 1
883+ done < "${src_symlinks}"
884+ ) || fail "failed to create symlinks"
885 fi
886 if [ -f "${makedevs_list}" ]; then
887- xmakedevs "$makedevs_list" "$overlay_d" ||
888- fail "failed to makedevs on overlay"
889+ xmakedevs "$makedevs_list" "$overlay_d" ||
890+ fail "failed to makedevs on overlay"
891 fi
892
893 ( cd "$overlay_d" && tar -cpf - * ) > "$overlay_tar" ||
894- fail "failed to make overlay_tar"
895+ fail "failed to make overlay_tar"
896
897 debug 1 "populating staging directory"
898 tar -C "$stage_d" -xpf - < "$rootfs_in" ||
899- fail "failed to extract rootfs_tar"
900+ fail "failed to extract rootfs_tar"
901 tar -C "$stage_d" -xpf - < "$overlay_tar" ||
902- fail "failed to extract overlay_tar"
903+ fail "failed to extract overlay_tar"
904
905 if [ -x "${fixup_fs}" ]; then
906- "${fixup_fs}" "${stage_d}" ||
907- fail "failed to fixup filesystem"
908+ "${fixup_fs}" "${stage_d}" ||
909+ fail "failed to fixup filesystem"
910 fi
911
912 ( cd "$stage_d" && tar -Scpzf - -- * ) > "$out_filesys_lxc" ||
913- fail "failed to create filesys tarball"
914+ fail "failed to create filesys tarball"
915
916 tar -C "$stage_d" -xpf - < "$kernel_tar" ||
917- fail "failed to extract kernel_tar"
918+ fail "failed to extract kernel_tar"
919 tar -C "$stage_d" -xpf - < "$xgrubd/bootgrub.tar" ||
920- fail "failed to extract bootgrub"
921+ fail "failed to extract bootgrub"
922
923 depmod -a --basedir "$stage_d" "${kver}" ||
924- fail "failed to run depmod for kver ${kver} in output"
925+ fail "failed to run depmod for kver ${kver} in output"
926
927 debug 1 "creating initramfs"
928 xrsync "$stage_d/" "$initramfs_d" ||
929- fail "failed to copy to initramfs_d"
930+ fail "failed to copy to initramfs_d"
931+
932 rm -Rf "$initramfs_d/vmlinuz" "$initramfs_d/boot" ||
933- fail "failed to remove files in initramfs staging dir"
934-
935-( cd "$initramfs_d" && find . | cpio --quiet -o -H newc |
936- gzip -9 ) > "$initramfs"
937-
938-rm -Rf "$initramfs_d/lib/modules/$kver" ||
939- fail "failed to remove lib/modules for mini initramfs"
940-
941-( cd "$initramfs_d" && find . | cpio --quiet -o -H newc |
942- gzip -9 ) > "${initramfs}.smaller"
943-
944-cp "${initramfs}.smaller" "$stage_d/boot/initrd.img-${kver}" &&
945- ln -s "boot/initrd.img-${kver}" "${stage_d}/initrd.img" ||
946- fail "failed to copy initramfs to stage dir"
947+ fail "failed to remove files in initramfs staging dir"
948+
949+( cd "$initramfs_d" && find . | cpio --quiet -o -H newc |
950+ gzip -9 ) > "$initramfs"
951+
952+cp "${initramfs}" "$stage_d/boot/initrd.img-${kver}" &&
953+ ln -s "boot/initrd.img-${kver}" "${stage_d}/initrd.img" ||
954+ fail "failed to copy initramfs to stage dir"
955
956 debug 1 "packing clean kernel_tar"
957 tar -C "$stage_d" -cpf - \
958- vmlinuz initrd.img boot/ lib/modules/ > "$kernel_tar" ||
959- fail "failed to create clean kerne_tar"
960+ vmlinuz initrd.img boot/ lib/modules/ > "$kernel_tar" ||
961+ fail "failed to create clean kerne_tar"
962
963 ( cd "$stage_d" && tar -cpf - * ) > "$filesys_tar" ||
964- fail "failed to create filesys_tar"
965+ fail "failed to create filesys_tar"
966
967 debug 1 "populating image"
968 mount -o loop "${out_partimg}" "${mp}" && UMOUNT=${mp} ||
969- fail "failed to mount ${out_partimg} loopback"
970+ fail "failed to mount ${out_partimg} loopback"
971
972 tar -C "$mp" -xpf - < "$filesys_tar" ||
973- fail "failed to populate mount point"
974+ fail "failed to populate mount point"
975
976 umount "${mp}" && UMOUNT="" ||
977- fail "failed to unmount ${out_partimg}"
978+ fail "failed to unmount ${out_partimg}"
979
980 cp "${kernel_d}/${vmlinuz}" "${out_kernel}" ||
981- fail "failed to copy kernel to ${out_kernel}"
982+ fail "failed to copy kernel to ${out_kernel}"
983
984-{ [ -z "${out_initramfs}" ] || cp "${initramfs}" "${out_initramfs}"; } ||
985- fail "failed to copy initramfs to ${out_initramfs}"
986+{ [ -z "${out_initramfs}" ] || cp "${initramfs}" "${out_initramfs}"; } ||
987+ fail "failed to copy initramfs to ${out_initramfs}"
988
989 debug 1 "fixing grub entry in partimg"
990 tmp_part="$TEMP_D/part.img.disk"
991+
992 cp "$out_partimg" "$tmp_part" &&
993- mount -o loop "$tmp_part" "$mp" && UMOUNT="$mp" ||
994- fail "failed to mount $tmp_part"
995+ mount -o loop "$tmp_part" "$mp" && UMOUNT="$mp" ||
996+ fail "failed to mount $tmp_part"
997+
998 sed -i 's/(hd0)/(hd0,0)/' "$mp/boot/grub/menu.lst" ||
999- fail "failed to edit /boot/grub/menu.lst in image"
1000+ fail "failed to edit /boot/grub/menu.lst in image"
1001+
1002 umount "$mp" && UMOUNT="" ||
1003- fail "failed to unmount partimg"
1004+ fail "failed to unmount partimg"
1005+
1006+case $arch in
1007+ i386|x86_64) grub_options="--grub1 --grub-efi";;
1008+ arm|aarch64) grub_options="--grub-efi";;
1009+ *) grub_options=;;
1010+esac
1011
1012 debug 1 "creating disk image"
1013-out=$(PATH=$xgrubd:$PATH part2disk --grub1 "$tmp_part" "$out_diskimg.raw" 2>&1) ||
1014- fail "failed to create disk image: $out"
1015+out=$(PATH=$xgrubd:$PATH part2disk $grub_options --partition "$tmp_part" \
1016+ --grub-efi-tar "${grub_efi_in}" --arch $arch --disk "$out_diskimg.raw" 2>&1) ||
1017+ fail "failed to create disk image: $out"
1018+
1019 qemu-img convert -O qcow2 -c "$out_diskimg.raw" "$out_diskimg" ||
1020- fail "failed to convert disk image"
1021+ fail "failed to convert disk image"
1022+
1023 rm -f "$out_diskimg.raw" "$tmp_part"
1024
1025 if [ -n "${SUDO_USER}" ]; then
1026- u=${SUDO_USER}
1027- g=$(id -g "${u}") || g=${u}
1028- chown "${u}:${g}" -R "$out_d" ||
1029- fail "failed to grant ownership of ${u}:${g} to ${u}:${g}"
1030+ u=${SUDO_USER}
1031+ g=$(id -g "${u}") || g=${u}
1032+ chown "${u}:${g}" -R "$out_d" ||
1033+ fail "failed to grant ownership of ${u}:${g} to ${u}:${g}"
1034 fi
1035
1036 echo "wrote ${out_partimg}"
1037@@ -315,3 +336,4 @@
1038 echo "wrote ${out_filesys_lxc}"
1039
1040 exit 0
1041+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1042
1043=== added file 'bin/common-functions.sh'
1044--- bin/common-functions.sh 1970-01-01 00:00:00 +0000
1045+++ bin/common-functions.sh 2016-07-21 10:53:24 +0000
1046@@ -0,0 +1,43 @@
1047+#!/bin/bash
1048+#
1049+# Copyright (C) 2010 Canonical Ltd.
1050+#
1051+# Authors: Scott Moser <smoser@canonical.com>
1052+# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
1053+#
1054+# This program is free software: you can redistribute it and/or modify
1055+# it under the terms of the GNU General Public License as published by
1056+# the Free Software Foundation, version 3 of the License.
1057+#
1058+# This program is distributed in the hope that it will be useful,
1059+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1060+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1061+# GNU General Public License for more details.
1062+#
1063+# You should have received a copy of the GNU General Public License
1064+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1065+#
1066+
1067+DEBUG=0
1068+
1069+error() { echo "$@" 1>&2; }
1070+debug() {
1071+ [ "${DEBUG}" -ge "${1:-0}" ] && shift || return 0;
1072+ error "$@";
1073+}
1074+fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
1075+bad_Usage() { Usage 1>&2; fail "$@"; }
1076+
1077+dl() {
1078+ local url="$1" target="$2" tfile="" t=""
1079+
1080+ [ -f "$target" ] && return
1081+
1082+ t=$(dirname "$target")
1083+ tfile=$(mktemp "$t/.${0##*/}.XXXXXX") || return
1084+
1085+ wget "$url" -O "$tfile" &&
1086+ mv "$tfile" "$target" ||
1087+ { t=$?; rm -f "$tfile"; return $t; }
1088+}
1089+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1090
1091=== added file 'bin/grab-grub-efi'
1092--- bin/grab-grub-efi 1970-01-01 00:00:00 +0000
1093+++ bin/grab-grub-efi 2016-07-21 10:53:24 +0000
1094@@ -0,0 +1,114 @@
1095+#!/bin/bash
1096+#
1097+# Copyright (C) 2016 Linaro Ltd
1098+#
1099+# Authors: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
1100+#
1101+# This program is free software: you can redistribute it and/or modify
1102+# it under the terms of the GNU General Public License as published by
1103+# the Free Software Foundation, version 3 of the License.
1104+#
1105+# This program is distributed in the hope that it will be useful,
1106+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1107+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1108+# GNU General Public License for more details.
1109+#
1110+# You should have received a copy of the GNU General Public License
1111+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1112+#
1113+
1114+source "${0%/*}/common-functions.sh"
1115+
1116+burl="https://launchpad.net/ubuntu/+archive/primary/+files/"
1117+outdir="./download"
1118+def_arches="x86_64 aarch64 i386 arm"
1119+
1120+[ "$1" = "--outdir" ] && { outdir="$1" && shift; }
1121+
1122+gver="$1"
1123+shift
1124+
1125+if [ $# -eq 0 ]; then
1126+ set -- ${def_arches}
1127+fi
1128+
1129+[ -d "$outdir" ] || mkdir -p "$outdir" ||
1130+ fail "failed mkdir $outdir"
1131+
1132+[ -n "$gver" ] || fail "must give grub version"
1133+
1134+deb2tar() {
1135+
1136+ local deb="$1" tar="$2" efiarch=$3 format=$4
1137+
1138+ t=$(dirname "$deb")
1139+ tdir=$(mktemp -d "$t/.XXXXXX") || return
1140+
1141+ debug 1 "creating $out in tempdir at $tdir"
1142+
1143+ mkdir -p "$tdir/deb"
1144+ dpkg -x "$deb" "$tdir/deb" || fail "failed to unpack $deb"
1145+
1146+ efibin=boot${efiarch}.efi
1147+
1148+ "${0%/*}/build-efi-images" grub-mkimage "${tdir}/deb/usr/lib/grub/$format" \
1149+ "${tdir}/out/" $format $efiarch
1150+
1151+ mv "${tdir}/out/grub${efiarch}.efi" "${tdir}/boot${efiarch}.efi"
1152+ rm -rf "$tdir/{deb,out}"
1153+ debug 2 "creating grub.tar.gz"
1154+ tar -C "$tdir/" -czf "$tdir/grub.tar.gz" $efibin &&
1155+ mv "$tdir/grub.tar.gz" "$tar" || {
1156+ error "failed creating tarball";
1157+ rm -Rf "$tdir"
1158+ return 1;
1159+ }
1160+ rm -Rf "$tdir"
1161+ return 0
1162+}
1163+
1164+for arch in "$@"; do
1165+ case "$arch" in
1166+ aarch64)
1167+ efiarch='aa64'
1168+ debarch='arm64'
1169+ pkgarch='arm64'
1170+ format='arm64-efi'
1171+ ;;
1172+ x86_64)
1173+ efiarch='x64'
1174+ debarch='amd64'
1175+ pkgarch='amd64'
1176+ format='x86_64-efi'
1177+ ;;
1178+ i386)
1179+ efiarch='ia32'
1180+ debarch='i386'
1181+ pkgarch='ia32'
1182+ format='i386-efi'
1183+ ;;
1184+ arm)
1185+ efiarch='arm'
1186+ debarch='armhf'
1187+ pkgarch='arm'
1188+ format='arm-efi'
1189+ ;;
1190+ *) debug 1 "no EFI grub for $arch";;
1191+ esac
1192+
1193+ [ -z $efiarch ] && continue
1194+
1195+ deb="grub-efi-${pkgarch}-bin_${gver}_${debarch}.deb"
1196+ if [ ! -f "${outdir}/${deb}" ]; then
1197+ dl $burl/$deb "$outdir/$deb" || fail "failed dl $burl/$deb"
1198+ fi
1199+
1200+ tar="grub-efi-${gver}-${arch}.tar.gz"
1201+ deb2tar "$outdir/$deb" "$outdir/$tar" $efiarch $format ||
1202+ fail "failed deb2efi from $deb to $tar"
1203+
1204+ error "wrote $outdir/${tar}"
1205+ ln -sf "${tar}" "$outdir/grub-efi-${arch}.tar.gz" ||
1206+ fail "failed symlink for $outdir/grub-$arch.rpm"
1207+done
1208+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1209
1210=== modified file 'bin/grab-kernels'
1211--- bin/grab-kernels 2016-06-29 17:20:04 +0000
1212+++ bin/grab-kernels 2016-07-21 10:53:24 +0000
1213@@ -1,34 +1,38 @@
1214-#!/bin/sh
1215+#!/bin/bash
1216+#
1217+# Copyright (C) 2010 Canonical Ltd.
1218+#
1219+# Authors: Scott Moser <smoser@canonical.com>
1220+# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
1221+#
1222+# This program is free software: you can redistribute it and/or modify
1223+# it under the terms of the GNU General Public License as published by
1224+# the Free Software Foundation, version 3 of the License.
1225+#
1226+# This program is distributed in the hope that it will be useful,
1227+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1228+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1229+# GNU General Public License for more details.
1230+#
1231+# You should have received a copy of the GNU General Public License
1232+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1233+
1234+source "${0%/*}/common-functions.sh"
1235
1236 burl="https://launchpad.net/ubuntu/+archive/primary/+files/linux-image"
1237 outdir="./download"
1238 def_arches="i386 x86_64 arm powerpc ppc64 ppc64le aarch64"
1239-DEBUG=0
1240-
1241-debug() {
1242- [ "${DEBUG}" -ge "${1}" ] || return 0;
1243- shift;
1244- error "$@"
1245-}
1246-error() { echo "$@" 1>&2; }
1247-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
1248-dl() {
1249- local url="$1" target="$2" tfile="" t=""
1250- [ -f "$target" ] && return
1251- t=$(dirname "$target")
1252- tfile=$(mktemp "$t/.${0##*/}.XXXXXX") || return
1253- wget "$url" -O "$tfile" &&
1254- mv "$tfile" "$target" ||
1255- { t=$?; rm -f "$tfile"; return $t; }
1256-}
1257
1258 debs2tar() {
1259 local out="$1" t="" deb=""
1260 shift
1261+
1262 t=$(dirname "$out")
1263 tdir=$(mktemp -d "$t/.${0##*/}.XXXXXX") || return
1264+
1265 debug 1 "creating $out in tempdir at $tdir from $*"
1266 mkdir "$tdir/ex"
1267+
1268 for deb in "$@"; do
1269 debug 2 "extracting $deb"
1270 dpkg -x "$deb" "$tdir/ex" || {
1271@@ -37,6 +41,7 @@
1272 return 1;
1273 }
1274 done
1275+
1276 debug 2 "creating kernel.tar.gz"
1277 tar -C "$tdir/ex" -czf "$tdir/kernel.tar.gz" . &&
1278 mv "$tdir/kernel.tar.gz" "$out" || {
1279@@ -44,6 +49,8 @@
1280 rm -Rf "$tdir"
1281 return 1;
1282 }
1283+
1284+ rm -Rf "$tdir";
1285 return 0
1286 }
1287
1288@@ -52,12 +59,11 @@
1289 shift
1290
1291 if [ $# -eq 0 ]; then
1292- set -- ${def_arches}
1293+ set -- ${def_arches}
1294 fi
1295
1296 [ -d "$outdir" ] || mkdir -p "$outdir" ||
1297- fail "failed mkdir $outdir"
1298-
1299+ fail "failed mkdir $outdir"
1300
1301 [ -n "$kver" ] || fail "must give kernel version"
1302
1303@@ -72,13 +78,15 @@
1304 kmicro=${kpart#*.*.}
1305
1306 case "$kmajor.$kminor" in
1307- 3.2|3.13|3.19|4.4) :;;
1308- *) error "WARN: possibly unknown kernel version $kmajor.$kminor.";;
1309+ 3.2|3.13|3.19|4.4) :;;
1310+ *) error "WARN: possibly unknown kernel version $kmajor.$kminor.";;
1311 esac
1312
1313 for arch in "$@"; do
1314 xarch=$arch;
1315+
1316 [ "$arch" = "x86_64" ] && xarch="amd64";
1317+
1318 if [ "$kmajor.$kminor" = "3.2" ]; then
1319 case "$arch" in
1320 x86_64|i386) flav="virtual";;
1321@@ -96,11 +104,14 @@
1322 *) fail "unknown kernel:arch for $kver:$arch"
1323 esac
1324 fi
1325+
1326 case $xarch in
1327 amd64|i386|ppc64el|s390x) extra="-extra";;
1328 *) extra="";
1329 esac
1330+
1331 debs=""
1332+
1333 for epkg in "" $extra; do
1334 url="$burl${epkg}-${kmajor}.${kminor}.${kmicro}-${abi}-${flav}_${kver}_${xarch}.deb"
1335 dl "$url" "$outdir/${url##*/}" || fail "failed dl $url"
1336@@ -108,7 +119,9 @@
1337 fail "failed symlink for $outdir/kernel-$arch${epkg}.deb"
1338 debs="${debs} ${outdir}/${url##*/}"
1339 done
1340+
1341 tar="linux-image-${kver}-${flav}-${xarch}.tar.gz"
1342+
1343 if [ -f "$outdir/${tar}" ]; then
1344 error "re-used existing $outdir/${tar}"
1345 else
1346@@ -116,7 +129,8 @@
1347 fail "failed debs2tar to $tar on $debs"
1348 error "wrote $outdir/${tar}"
1349 fi
1350+
1351 ln -sf "${tar}" "$outdir/kernel-${arch}.tar.gz" ||
1352 fail "failed symlink for $outdir/kernel-$arch${epkg}.deb"
1353 done
1354-# vi: ts=4 expandtab
1355+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1356
1357=== modified file 'bin/mirror-dump-sstream-data'
1358--- bin/mirror-dump-sstream-data 2014-09-05 20:57:52 +0000
1359+++ bin/mirror-dump-sstream-data 2016-07-21 10:53:24 +0000
1360@@ -3,6 +3,9 @@
1361 #
1362 #
1363 #
1364+
1365+source "${0%/*}/common-functions.sh"
1366+
1367 Usage() {
1368 cat <<EOF
1369 Usage: ${0##*/} mirror_dir
1370@@ -24,37 +27,37 @@
1371 }
1372
1373 datefortag() {
1374- local loginfo ts out repo="${CIRROS_BZR:-.}"
1375- local spec="$1" fmt="${2:-+%Y%m%d}"
1376- loginfo=$(bzr log "$repo" --log-format=long --revision "$spec") ||
1377- { error "couldn't bzr log tag:$i"; return 1; }
1378- ts=$(echo "$loginfo" | sed -n '/^timestamp:/s,.*: ,,p') &&
1379- [ -n "$ts" ] || {
1380- error "failed to get timestamp from log for $spec";
1381- return 1;
1382- }
1383- out=$(date --date="$ts" "$fmt") ||
1384- { error "failed convert of '$ts' to format=$fmt"; return 1; }
1385- _RET="$out"
1386+ local loginfo ts out repo="${CIRROS_BZR:-.}"
1387+ local spec="$1" fmt="${2:-+%Y%m%d}"
1388+
1389+ loginfo=$(bzr log "$repo" --log-format=long --revision "$spec") ||
1390+ { error "couldn't bzr log tag:$i"; return 1; }
1391+
1392+ ts=$(echo "$loginfo" | sed -n '/^timestamp:/s,.*: ,,p') &&
1393+ [ -n "$ts" ] || {
1394+ error "failed to get timestamp from log for $spec";
1395+ return 1;
1396+ }
1397+
1398+ out=$(date --date="$ts" "$fmt") ||
1399+ { error "failed convert of '$ts' to format=$fmt"; return 1; }
1400+ _RET="$out"
1401 }
1402
1403-error() { echo "$@" 1>&2; }
1404-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
1405-
1406 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
1407 [ "$#" -eq 1 ] || { Usage 1>&2; fail "must give mirror dir"; }
1408
1409 if [ -z "$CIRROS_BZR" ]; then
1410- CIRROS_BZR=$(t=$(readlink -f "$0") && cd "${t%/*}/.." && pwd)
1411+ CIRROS_BZR=$(t=$(readlink -f "$0") && cd "${t%/*}/.." && pwd)
1412 fi
1413
1414 OIFS="$IFS"
1415 declare -A VERSION2SERIAL
1416 VERSION2SERIAL=( [0.3.0]="20111020" [0.3.1]="20130207"
1417- [0.3.1~pre1]="20120611" [0.3.1~pre3]="20120827"
1418- [0.3.1~pre4]="20130111" [0.3.2~pre1]="20130513"
1419- [0.3.2~pre2]="20131218" [0.3.2~pre3]="20140315"
1420- [0.3.2]="20140317"
1421+ [0.3.1~pre1]="20120611" [0.3.1~pre3]="20120827"
1422+ [0.3.1~pre4]="20130111" [0.3.2~pre1]="20130513"
1423+ [0.3.2~pre2]="20131218" [0.3.2~pre3]="20140315"
1424+ [0.3.2]="20140317"
1425 )
1426
1427 #content-id product_name version_name img_name [key=value [key=value]]
1428@@ -67,59 +70,63 @@
1429 IFS=$'\n'; files=( $(find . -type f -printf "%p|%s\n") ); IFS="$OIFS"
1430
1431 for ent in "${files[@]}"; do
1432- IFS="|"; set -- $ent; IFS="$OIFS"
1433- path=${1#./}
1434- size=${2}
1435-
1436- case "$path" in
1437- *-uec.tar.gz|*-disk.img|*-rootfs.img|*-lxc.tar.gz) :;;
1438- *) continue;;
1439- esac
1440- IFS="/"; set -- $path; IFS=$OIFS
1441- version="$1"; fname="$2";
1442- serial="${VERSION2SERIAL[$version]}"
1443- if [ -z "$serial" ]; then
1444- datefortag "tag:$version" ||
1445- fail "serial not found for $version!"
1446- serial="$_RET"
1447- VERSION2SERIAL[$version]="$serial"
1448- fi
1449-
1450- # tokenize cirros-0.3.1~pre4-x86_64-lxc.tar.gz, baseproduct gets 'cirros'
1451- IFS="-"; set -- $fname; IFS="$OIFS"
1452- baseproduct="$1"; _version="$2"; arch="$3"; ftype="$4"
1453-
1454- # tokenize 0.3.1~pre1 or 0.3.0
1455- extra=${version#*~}; [ "$extra" = "$version" ] && extra=""
1456- tmp=${version%$extra}
1457- IFS="."; set -- ${version%$extra}; IFS="$IOFS"
1458- vmaj="$1"; vmin="$2"; vmic="$3"
1459-
1460- [ -z "$extra" ] && stream="released" || stream="devel"
1461-
1462- # productname is "net.cirros-cloud[.devel]:standard:0.3:arch"
1463- rdns="net.cirros-cloud"
1464- [ "$stream" = "released" ] || rdns="${rdns}.${stream}"
1465- product_name="$rdns:standard:$vmaj.$vmin:$arch"
1466- content_id="${content_id_base//%(stream)s/${stream}}"
1467-
1468- req_out=""
1469- for item in "$content_id" "$product_name" "$serial" "$ftype"; do
1470- req_out="${req_out}${tab}${item}"
1471- done
1472- req_out=${req_out#${tab}}
1473-
1474- md5=$(md5sum "${path}") && md5="${md5%% ${path}}"
1475- sha256=$(sha256sum "${path}") && sha256="${sha256%% ${path}}"
1476- pubname="${baseproduct}-${version}-${arch}"
1477-
1478- out=""
1479- for i in ftype path arch version size sha256 md5 pubname stream; do
1480- out="${out}${tab}${i}=${!i}"
1481- done
1482- out=${out#${tab}}
1483- printf "%s\n" "${req_out}${tab}${out}"
1484- #printf "
1485- #echo "$content_id
1486- #echo "version=$version fname=$fname stream=$stream product_name=$product_name"
1487-done
1488+ IFS="|"; set -- $ent; IFS="$OIFS"
1489+ path=${1#./}
1490+ size=${2}
1491+
1492+ case "$path" in
1493+ *-uec.tar.gz|*-disk.img|*-rootfs.img|*-lxc.tar.gz) :;;
1494+ *) continue;;
1495+esac
1496+
1497+IFS="/"; set -- $path; IFS=$OIFS
1498+version="$1"; fname="$2";
1499+serial="${VERSION2SERIAL[$version]}"
1500+
1501+if [ -z "$serial" ]; then
1502+ datefortag "tag:$version" ||
1503+ fail "serial not found for $version!"
1504+ serial="$_RET"
1505+ VERSION2SERIAL[$version]="$serial"
1506+fi
1507+
1508+# tokenize cirros-0.3.1~pre4-x86_64-lxc.tar.gz, baseproduct gets 'cirros'
1509+IFS="-"; set -- $fname; IFS="$OIFS"
1510+baseproduct="$1"; _version="$2"; arch="$3"; ftype="$4"
1511+
1512+# tokenize 0.3.1~pre1 or 0.3.0
1513+extra=${version#*~}; [ "$extra" = "$version" ] && extra=""
1514+tmp=${version%$extra}
1515+IFS="."; set -- ${version%$extra}; IFS="$IOFS"
1516+vmaj="$1"; vmin="$2"; vmic="$3"
1517+
1518+[ -z "$extra" ] && stream="released" || stream="devel"
1519+
1520+# productname is "net.cirros-cloud[.devel]:standard:0.3:arch"
1521+rdns="net.cirros-cloud"
1522+[ "$stream" = "released" ] || rdns="${rdns}.${stream}"
1523+product_name="$rdns:standard:$vmaj.$vmin:$arch"
1524+content_id="${content_id_base//%(stream)s/${stream}}"
1525+
1526+req_out=""
1527+for item in "$content_id" "$product_name" "$serial" "$ftype"; do
1528+ req_out="${req_out}${tab}${item}"
1529+done
1530+req_out=${req_out#${tab}}
1531+
1532+md5=$(md5sum "${path}") && md5="${md5%% ${path}}"
1533+sha256=$(sha256sum "${path}") && sha256="${sha256%% ${path}}"
1534+pubname="${baseproduct}-${version}-${arch}"
1535+
1536+out=""
1537+for i in ftype path arch version size sha256 md5 pubname stream; do
1538+ out="${out}${tab}${i}=${!i}"
1539+done
1540+
1541+out=${out#${tab}}
1542+printf "%s\n" "${req_out}${tab}${out}"
1543+#printf "
1544+#echo "$content_id
1545+#echo "version=$version fname=$fname stream=$stream product_name=$product_name"
1546+done
1547+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1548
1549=== modified file 'bin/mkcabundle'
1550--- bin/mkcabundle 2012-06-08 02:33:28 +0000
1551+++ bin/mkcabundle 2016-07-21 10:53:24 +0000
1552@@ -39,3 +39,4 @@
1553 print "# Generated from certdata.txt RCS revision $1\n#\n";
1554 }
1555 }
1556+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1557
1558=== modified file 'bin/part2disk'
1559--- bin/part2disk 2015-05-28 14:25:11 +0000
1560+++ bin/part2disk 2016-07-21 10:53:24 +0000
1561@@ -1,209 +1,183 @@
1562-#!/bin/sh
1563-# part2disk - wrap a partition image in a disk image
1564-#
1565-# Copyright (C) 2010 Canonical Ltd.
1566-#
1567-# Authors: Scott Moser <smoser@canonical.com>
1568-#
1569-# This program is free software: you can redistribute it and/or modify
1570-# it under the terms of the GNU General Public License as published by
1571-# the Free Software Foundation, version 3 of the License.
1572-#
1573-# This program is distributed in the hope that it will be useful,
1574-# but WITHOUT ANY WARRANTY; without even the implied warranty of
1575-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1576-# GNU General Public License for more details.
1577-#
1578-# You should have received a copy of the GNU General Public License
1579-# along with this program. If not, see <http://www.gnu.org/licenses/>.
1580+#!/bin/bash
1581+# part2disk - wrap a partition image in a disk image
1582+#
1583+# Copyright (C) 2010 Canonical Ltd.
1584+#
1585+# Authors: Scott Moser <smoser@canonical.com>
1586+# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
1587+#
1588+# This program is free software: you can redistribute it and/or modify
1589+# it under the terms of the GNU General Public License as published by
1590+# the Free Software Foundation, version 3 of the License.
1591+#
1592+# This program is distributed in the hope that it will be useful,
1593+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1594+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1595+# GNU General Public License for more details.
1596+#
1597+# You should have received a copy of the GNU General Public License
1598+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1599+
1600+source "${0%/*}/common-functions.sh"
1601
1602 DEF_SECTOR_SIZE=512
1603-DEBUG=0
1604 base_d=$(dirname $(readlink -f "${0}"))
1605 PATH="${PATH}:${base_d}"
1606-error() { echo "$@" 1>&2; }
1607-debug() {
1608- [ "${DEBUG}" -ge "${1:-0}" ] && shift || return 0;
1609- error "$@";
1610-}
1611-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
1612 getsize() {
1613- local fname="$1" kname="" size=""
1614- if [ -b "${fname}" ]; then
1615- kname=$(readlink -f "${fname}") &&
1616- size=$(awk '$4 == kn { print $3 * 1024 }' \
1617- "kn=${kname##*/}" /proc/partitions) &&
1618- [ -n "${size}" ] || {
1619- error "failed to read size of ${fname} from /proc/partitions";
1620- return 1;
1621- }
1622- else
1623- size=$(stat --format "%s" "${fname}") || {
1624- error "failed to get size of ${fname}"
1625- return 1;
1626- }
1627- fi
1628- _RET="$size"
1629+ local fname="$1" kname="" size=""
1630+ if [ -b "${fname}" ]; then
1631+ kname=$(readlink -f "${fname}") &&
1632+ size=$(awk '$4 == kn { print $3 * 1024 }' \
1633+ "kn=${kname##*/}" /proc/partitions) &&
1634+ [ -n "${size}" ] || {
1635+ error "failed to read size of ${fname} from /proc/partitions";
1636+ return 1;
1637+ }
1638+ else
1639+ size=$(stat --format "%s" "${fname}") || {
1640+ error "failed to get size of ${fname}"
1641+ return 1;
1642+ }
1643+ fi
1644+ _RET="$size"
1645 }
1646
1647 Usage() {
1648- cat <<EOF
1649-Usage: ${0##*/} [options] partition-image disk-image
1650+ cat <<EOF
1651+Usage: ${0##*/} [options] partition-image grub-efi-tarball architecture disk-image
1652
1653- create disk image 'disk-image' with 'partition-image' in a partition
1654- inside it.
1655+ Create disk image 'disk-image' with 'partition-image' in a partition
1656+ inside it. Add grub if requested.
1657
1658 options:
1659 -G | --grub install grub to disk image mbr
1660 | --grub1 install grub1 to disk image mbr
1661+ | --grub-efi install EFI grub to disk image
1662 -s | --size S create the disk image of size 'S'.
1663 default is large enough to fit partition-image
1664 -v | --verbose increase verbosity
1665 EOF
1666 }
1667-bad_Usage() { Usage 1>&2; fail "$@"; }
1668+
1669 human2bytes() {
1670- # converts size suitable for input to resize2fs to bytes
1671- # s:512 byte sectors, K:kilobytes, M:megabytes, G:gigabytes
1672- # none: block size of the image
1673- local input=${1} defunit=${2:-1024}
1674- local unit count;
1675- case "$input" in
1676- *s) count=${input%s}; unit=512;;
1677- *K) count=${input%K}; unit=1024;;
1678- *M) count=${input%M}; unit=$((1024*1024));;
1679- *G) count=${input%G}; unit=$((1024*1024*1024));;
1680- *) count=${input} ; unit=${2:-1024};;
1681- esac
1682- _RET=$((${count}*${unit}))
1683-}
1684-
1685-short_opts="b:c:Ghs:v"
1686-long_opts="grub1,grub,help,size:,verbose"
1687-getopt_out=$(getopt --name "${0##*/}" \
1688- --options "${short_opts}" --long "${long_opts}" -- "$@") &&
1689- eval set -- "${getopt_out}" ||
1690- bad_Usage
1691+ # converts size suitable for input to resize2fs to bytes
1692+ # s:512 byte sectors, K:kilobytes, M:megabytes, G:gigabytes
1693+ # none: block size of the image
1694+ local input=${1} defunit=${2:-1024}
1695+ local unit count;
1696+
1697+ case "$input" in
1698+ *s) count=${input%s}; unit=512;;
1699+ *K) count=${input%K}; unit=1024;;
1700+ *M) count=${input%M}; unit=$((1024*1024));;
1701+ *G) count=${input%G}; unit=$((1024*1024*1024));;
1702+ *) count=${input} ; unit=${2:-1024};;
1703+ esac
1704+
1705+ _RET=$((${count}*${unit}))
1706+}
1707+
1708+cleanup() {
1709+ umount "$TMP/efi"
1710+ umount "$TMP/rootfs"
1711+ kpartx -d "$dimg"
1712+}
1713+
1714+trap cleanup EXIT
1715
1716 ssize=${DEF_SECTOR_SIZE}
1717 size_in=""
1718 grub_ptnum=1
1719 grub=0
1720 grub1=0
1721+grub_efi=0
1722+
1723+short_opts="b:c:Ghs:v"
1724+long_opts="grub-efi,grub1,grub,help,size:,verbose,partition:,grub-efi-tar:,arch:,disk:"
1725+getopt_out=$(getopt --name "${0##*/}" \
1726+ --options "${short_opts}" --long "${long_opts}" -- "$@") &&
1727+ eval set -- "${getopt_out}" ||
1728+ bad_Usage
1729+
1730 while [ $# -ne 0 ]; do
1731- cur=${1}; next=${2};
1732- case "$cur" in
1733- -G|--grub) grub=1;;
1734- -G|--grub1) grub1=1;;
1735- -h|--help) Usage; exit 0;;
1736- -s|--size) size_in=$2; shift;;
1737- -v|--verbose) DEBUG=$((${DEBUG}+1));;
1738- --) shift; break;;
1739- esac
1740- shift;
1741+ cur=${1}; next=${2};
1742+ case "$cur" in
1743+ -G|--grub) grub=1;;
1744+ -G|--grub1) grub1=1;;
1745+ --grub-efi) grub_efi=1;;
1746+ -h|--help) Usage; exit 0;;
1747+ -s|--size) size_in=$2; shift;;
1748+ -v|--verbose) DEBUG=$((${DEBUG}+1));;
1749+ --partition) pimg=$2; shift;;
1750+ --grub-efi-tar) grub_efi_in=$2; shift;;
1751+ --arch) arch=$2; shift;;
1752+ --disk) dimg=$2; shift;;
1753+ --) shift; break;;
1754+ esac
1755+ shift;
1756 done
1757
1758-[ $# -eq 2 ] || bad_Usage "must supply partition image and output file"
1759-
1760-pimg=${1}
1761-dimg=${2}
1762-
1763 { [ ${grub} -eq 0 ] || phelper=$(command -v part2disk-grubhelper); } ||
1764- fail "no part2disk-grubhelper in PATH"
1765+ fail "no part2disk-grubhelper in PATH"
1766 [ $grub1 -eq 0 ] || command -v grub >/dev/null || fail "no 'grub' in path";
1767
1768 [ -f "${pimg}" -o -b "${pimg}" ] || fail "${pimg}: not a file or block device"
1769
1770 getsize "$pimg" ||
1771- fail "failed to get size of $pimg"
1772+ fail "failed to get size of $pimg"
1773 pimg_s="$_RET"
1774
1775-# end_pad_sectors: room for secondary gpt
1776-end_pad_sectors=33
1777-end_pad=$(($end_pad_sectors*$ssize))
1778-front_pad=$((1024*1024))
1779-front_pad_sectors=$(($front_pad/$ssize))
1780-padding=$(($front_pad+$end_pad))
1781-pt_sector_pad=$(($ssize-(${pimg_s}%$ssize)))
1782-if [ $pt_sector_pad -eq $ssize ]; then
1783- pt_sector_pad=0
1784-fi
1785-pt_size=$(($pimg_s+$pt_sector_pad))
1786-pt_sectors=$(($pt_size/$ssize))
1787-tot_size=$(($front_pad+$pt_size+$end_pad))
1788+front_pad=$((12*1024*1024))
1789+tot_size=$(($front_pad+$pimg_s))
1790 tot_size_sectors=$(($tot_size/$ssize))
1791
1792 if [ -n "${size_in}" ]; then
1793- human2bytes "${size_in}" 1 || fail "failed to convert ${size_in} to bytes"
1794- size=${_RET}
1795+ human2bytes "${size_in}" 1 || fail "failed to convert ${size_in} to bytes"
1796+ size=${_RET}
1797 else
1798- # no size specified, get enough to fit part_img, 1M header and 1M end.
1799- size=$((${pimg_s}+$padding+$pt_sector_pad))
1800+ size=$tot_size_sectors
1801 fi
1802
1803 if [ -e "$dimg" ]; then
1804- getsize "$dimg" ||
1805- fail "failed to get size of $dimg"
1806- dimg_s="$_RET"
1807+ getsize "$dimg" ||
1808+ fail "failed to get size of $dimg"
1809+ dimg_s="$_RET"
1810 else
1811- dimg_s="$size"
1812+ dimg_s="$size"
1813 fi
1814
1815 if [ "${dimg_s}" -lt "$size" ]; then
1816- fail "size of $dimg ($dimg_s) not large enough to fit $size"
1817+ fail "size of $dimg ($dimg_s) not large enough to fit $size"
1818 fi
1819
1820-debug 1 "input is ${pimg_s} bytes ($pt_sectors sectors of $ssize)."
1821-debug 1 "target is ${tot_size} bytes ($tot_size_sectors sectors)."
1822-debug 1 "padding $front_pad_sectors sectors at front," \
1823- "$end_pad_sectors sectors at end."
1824-
1825-debug 2 "zeroing first $front_pad_sectors sectors $dimg"
1826-dd if=/dev/zero of="${dimg}" bs=$ssize "count=${front_pad_sectors}" \
1827- 2>/dev/null ||
1828- fail "failed to write to ${dimg}"
1829+debug 1 "input is ${pimg_s} bytes."
1830+debug 1 "target is ${tot_size} bytes."
1831+
1832+debug 2 "create target image"
1833+dd if=/dev/zero of="${dimg}" bs=$ssize count=$tot_size_sectors \
1834+ 2>/dev/null ||
1835+ fail "failed to write to ${dimg}"
1836+
1837+debug 2 "create partitions"
1838+sgdisk -n 15:2048:+8M -t 15:ef00 -N 1 $dimg
1839+loop_nr=`kpartx -av $dimg | head -n1 | cut -d" " -f3 | cut -d"p" -f2`
1840
1841 # copy partition image. this writes $pimg bytes even if that is
1842 # not divivisble by $ssize
1843 debug 2 "copying ${pimg} to partition in ${dimg}"
1844-dd if="$pimg" of="$dimg" seek=${front_pad_sectors} bs=$ssize conv=notrunc \
1845- 2>/dev/null ||
1846- fail "failed to write ${pimg} into ${dimg}"
1847-
1848-# zero any unwritten portion of the final sector
1849-leftover=$(($ssize-(${pimg_s}%$ssize)))
1850-if [ $pt_sector_pad -ne 0 ]; then
1851- debug 2 "finishing final sector with $pt_sector_pad bytes of zeros"
1852- dd if=/dev/zero of="$dimg" bs=1 seek=$((${pimg_s}+${front_pad})) \
1853- conv=notrunc count=$pt_sector_pad 2>/dev/null ||
1854- fail "failed to finish final sector of $pimg"
1855-fi
1856-
1857-# we've now written front pad + round-sectors. now write end_pad
1858-debug 2 "writing final $end_pad_sectors sectors"
1859-dd if=/dev/zero "of=$dimg" bs=$ssize \
1860- seek=$((($size/$ssize)-${end_pad_sectors})) count=${end_pad_sectors} \
1861- conv=notrunc 2>/dev/null ||
1862- fail "failed to write final 1M to $pimg"
1863-
1864-sfdisk_in="${front_pad_sectors},$pt_sectors,L,*"
1865-debug 2 "writing partition table to ${dimg} ($sfdisk_in)"
1866-sfdisk_out=$(echo "$sfdisk_in" | sfdisk --force --unit=S "${dimg}" 2>&1)
1867-
1868-[ $? -eq 0 ] || {
1869- error "${sfdisk_out}";
1870- fail "failed to create partition table";
1871-}
1872+dd if="$pimg" of=/dev/mapper/loop${loop_nr}p1 conv=notrunc \
1873+ 2>/dev/null ||
1874+ fail "failed to write ${pimg} into ${dimg}"
1875
1876 if [ ${grub} -ne 0 ]; then
1877- debug 2 "invoking part2disk-grubhelper ${dimg}"
1878- sudo "${phelper}" "${dimg}" ||
1879- fail "part2disk-grubhelper ${dimg} failed"
1880+ debug 2 "invoking part2disk-grubhelper ${dimg}"
1881+ sudo "${phelper}" "${dimg}" ||
1882+ fail "part2disk-grubhelper ${dimg} failed"
1883 fi
1884
1885 if [ $grub1 -ne 0 ]; then
1886- debug 2 "installing grub"
1887- grub --no-floppy --batch <<EOF
1888+ debug 2 "installing grub"
1889+ grub --no-floppy --batch <<EOF
1890 device (hd0) $dimg
1891 root (hd0,0)
1892 setup (hd0)
1893@@ -211,5 +185,47 @@
1894 EOF
1895 fi
1896
1897+if [ $grub_efi -ne 0 ]; then
1898+ case $arch in
1899+ x86_64) efiarch=x64;;
1900+ aarch64) efiarch=aa64;;
1901+ i386) efiarch=ia32;;
1902+ arm) efiarch=arm;;
1903+ *) fail "arch $arch without EFI grub"
1904+ esac
1905+ TMP=$(mktemp -d)
1906+ install -d $TMP/tar $TMP/efi $TMP/rootfs
1907+
1908+ mkfs.vfat /dev/mapper/loop${loop_nr}p15
1909+ mount /dev/mapper/loop${loop_nr}p15 $TMP/efi
1910+ install -d $TMP/efi/EFI/BOOT $TMP/efi/EFI/ubuntu
1911+ tar -xf $grub_efi_in -C $TMP/efi/EFI/BOOT
1912+
1913+ mount /dev/mapper/loop${loop_nr}p1 $TMP/rootfs
1914+ kernelfile=$(cd $TMP/rootfs/boot; ls vmlinu* | head -n1)
1915+ initrdfile=$(cd $TMP/rootfs/boot; ls initrd.img-* | head -n1)
1916+
1917+
1918+ cat >$TMP/efi/EFI/ubuntu/grub.cfg <<EOF
1919+set default=0
1920+set timeout=1
1921+menuentry 'CirrOS' {
1922+ set root='hd0,gpt1'
1923+ if [ x$feature_platform_search_hint = xy ]; then
1924+ search --no-floppy --label --set=root --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci1,gpt1 cirros-rootfs
1925+ else
1926+ search --no-floppy --label --set=root cirros-rootfs
1927+ fi
1928+
1929+ linux /boot/${kernelfile} LABEL=cirros-rootfs ro
1930+ initrd /boot/${initrdfile}
1931+}
1932+EOF
1933+
1934+ umount "$TMP/efi"
1935+ umount "$TMP/rootfs"
1936+fi
1937+
1938+kpartx -d "$dimg"
1939 error "wrote to ${dimg}"
1940-# vi: ts=4 noexpandtab
1941+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
1942
1943=== modified file 'bin/prepare-grub'
1944--- bin/prepare-grub 2011-10-05 05:24:46 +0000
1945+++ bin/prepare-grub 2016-07-21 10:53:24 +0000
1946@@ -1,5 +1,6 @@
1947 #!/bin/bash
1948-# vi: ts=4 noexpandtab
1949+
1950+source "${0%/*}/common-functions.sh"
1951
1952 # these urls are for lucid release version of grub
1953 i386_url="https://launchpad.net/ubuntu/+archive/primary/+files/grub_0.97-29ubuntu60_i386.deb"
1954@@ -7,17 +8,16 @@
1955 TEMP_D=""
1956
1957 Usage() {
1958- cat <<EOF
1959+ cat <<EOF
1960 Usage: ${0##*/} out_d
1961- prepare out_d for grub
1962- creates 'bootgrub.tar' and 'grub' binary
1963+ prepare out_d for grub
1964+ creates 'bootgrub.tar' and 'grub' binary
1965 EOF
1966 }
1967+
1968 cleanup() {
1969- [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
1970+ [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
1971 }
1972-error() { echo "$@" 1>&2; }
1973-fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
1974
1975 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
1976 [ $# -eq 1 ] || { Usage 1>&2; error "must give out_d"; exit 1; }
1977@@ -28,25 +28,26 @@
1978 mkdir -p "$out_d/dl"
1979
1980 case "$(uname -m)" in
1981- x86_64) url="${x86_64_url}";;
1982- i?86) url="${i386_url}";;
1983+ x86_64) url="${x86_64_url}";;
1984+ i?86) url="${i386_url}";;
1985 esac
1986
1987 TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") ||
1988- fail "failed to make tempd"
1989+ fail "failed to make tempd"
1990 trap cleanup EXIT
1991
1992 deb="${out_d}/dl/${url##*/}"
1993 if [ ! -e "${deb}" ]; then
1994- wget "${url}" -O "${TEMP_D}/deb" &&
1995- mv "${TEMP_D}/deb" "$deb" || fail "failed download of ${url}"
1996+ wget "${url}" -O "${TEMP_D}/deb" &&
1997+ mv "${TEMP_D}/deb" "$deb" || fail "failed download of ${url}"
1998 fi
1999
2000 cd "${TEMP_D}"
2001 dpkg -x "$deb" . &&
2002- cp usr/sbin/grub "$out_d/grub" &&
2003- mkdir -p boot/grub &&
2004- cp usr/lib/grub/*/{stage1,stage2,e2fs_stage1_5} boot/grub &&
2005- tar cf "${out_d}/bootgrub.tar" boot/ ||
2006- fail "failed to create $out_d"
2007+ cp usr/sbin/grub "$out_d/grub" &&
2008+ mkdir -p boot/grub &&
2009+ cp usr/lib/grub/*/{stage1,stage2,e2fs_stage1_5} boot/grub &&
2010+ tar cf "${out_d}/bootgrub.tar" boot/ ||
2011+ fail "failed to create $out_d"
2012 exit 0
2013+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
2014
2015=== modified file 'bin/system-setup'
2016--- bin/system-setup 2016-06-29 17:37:29 +0000
2017+++ bin/system-setup 2016-07-21 10:53:24 +0000
2018@@ -1,28 +1,30 @@
2019 #!/bin/bash
2020
2021+source "${0%/*}/common-functions.sh"
2022+
2023 _APT_UPDATED=false
2024 CIRROS_BRANCH="lp:cirros"
2025 CIRROS_D=""
2026 DEPS=(
2027- bc
2028- bison
2029- build-essential
2030- bzr
2031- flex
2032- gettext
2033- libncurses5-dev
2034- parallel
2035- qemu-kvm
2036- quilt
2037- rsync
2038- texinfo
2039- unzip
2040- wget
2041+ bc
2042+ bison
2043+ build-essential
2044+ bzr
2045+ dosfstools
2046+ flex
2047+ gdisk
2048+ gettext
2049+ kpartx
2050+ libncurses5-dev
2051+ parallel
2052+ qemu-kvm
2053+ quilt
2054+ rsync
2055+ texinfo
2056+ unzip
2057+ wget
2058 )
2059
2060-error() { echo "$@" 1>&2; }
2061-fail() { [ $# -eq 0 ] || error "$@"; exit 2; }
2062-
2063 apt_get() {
2064 local ret=""
2065 if [ "$1" != "update" ] && ! $_APT_UPDATED; then
2066@@ -48,8 +50,8 @@
2067 n=n+1;
2068 }
2069 $2 == "" {
2070- pkgs[n]=$1;
2071- n=n+1;
2072+ pkgs[n]=$1;
2073+ n=n+1;
2074 };
2075 END { for(p in pkgs) {printf("%s ",pkgs[p])}; printf("\n"); }' n=0
2076 }
2077@@ -92,4 +94,4 @@
2078
2079 error "set up functional to $CIRROS_D"
2080
2081-# vi: ts=4 expandtab
2082+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
2083
2084=== modified file 'bin/xmakedevs'
2085--- bin/xmakedevs 2014-03-17 14:04:17 +0000
2086+++ bin/xmakedevs 2016-07-21 10:53:24 +0000
2087@@ -1,10 +1,12 @@
2088-#!/bin/sh -e
2089-# vi: ts=4 noexpandtab
2090+#!/bin/bash -e
2091 #
2092 # this mimics function of buildroot's makedev
2093 # read a file like:
2094 # <name> <type> <mode> <uid> <gid> <major> <minor> <start> <inc> <count>
2095 # and make files
2096+
2097+source "${0%/*}/common-functions.sh"
2098+
2099 DEBUG=${XMAKEDEV_DEBUG}
2100 Usage() {
2101 cat <<EOF
2102@@ -22,80 +24,88 @@
2103 EOF
2104 }
2105
2106-error() { echo "$@" 1>&2; exit 1; }
2107-fail() { [ $# -eq 0 ] || error "$@" ; exit 1; }
2108-
2109 [ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
2110 [ $# -eq 2 ] || { Usage 1>&2; exit 1; }
2111
2112 root="$2"
2113
2114 if [ "$1" != "-" ]; then
2115- exec < "$1" || fail "failed to redirect input from $1"
2116+ exec < "$1" || fail "failed to redirect input from $1"
2117 fi
2118
2119 chmodchown() {
2120- local mode=$1 uid=$2 gid=$3
2121- shift 3;
2122- [ "$mode" = "-" ] || chmod "$mode" "$@" || return
2123- [ "$uid" = "-" ] || chown "$uid" "$@" || return
2124- [ "$gid" = "-" ] || chgrp "$gid" "$@" || return
2125+ local mode=$1 uid=$2 gid=$3
2126+ shift 3;
2127+ [ "$mode" = "-" ] || chmod "$mode" "$@" || return
2128+ [ "$uid" = "-" ] || chown "$uid" "$@" || return
2129+ [ "$gid" = "-" ] || chgrp "$gid" "$@" || return
2130 }
2131+
2132 iswild() {
2133- local star="\\*"
2134- case "$1" in
2135- *$star*) return 0;;
2136- esac
2137- return 1
2138+ local star="\\*"
2139+ case "$1" in
2140+ *$star*) return 0;;
2141+ esac
2142+ return 1
2143 }
2144
2145 cd "$root" || fail "failed cd $root"
2146
2147 while read line; do
2148- line=${line%#*}
2149- [ -n "$line" ] || continue
2150- set -f
2151- set -- $line
2152- name=$1; type=$2; mode=$3; uid=$4; gid=$5; major=$6; minor=$7; start=$8; inc=$9; count="${10}"
2153- set +f
2154- files="./${name#/}"
2155- if iswild "$name"; then
2156- files=$(echo ./$name)
2157- iswild "$files" && fail "wildcards in wildcards: $files"
2158- fi
2159- case "$type" in
2160- f)
2161- for f in $files; do
2162- $DEBUG mkdir -p "${f%/*}" || fail "failed to make ${f%/*}";
2163- done
2164- $DEBUG touch $files &&
2165- $DEBUG chmodchown "$mode" "$uid" "$gid" $files ||
2166- fail "failed create file $files"
2167- ;;
2168- d)
2169- $DEBUG mkdir -p $files &&
2170- $DEBUG chmodchown "$mode" "$uid" "$gid" $files ||
2171- fail "failed create dir $files"
2172- ;;
2173- c|b)
2174- for f in $files; do
2175- $DEBUG mkdir -p "${f%/*}" || fail "failed to make ${f%/*}";
2176- done
2177- if [ "$count" = "-" ]; then
2178- $DEBUG mknod $files $type $major $minor ||
2179- fail "failed mknod"
2180- $DEBUG chmodchown "$mode" "$uid" "$gid" $files ||
2181- fail "failed chmodchown '$mode' '$uid' '$gid' $files"
2182- else
2183- [ "$count" = "-" ] && count=1;
2184- i=0
2185- while [ $i -lt $count ]; do
2186- fname="./$name"
2187- $DEBUG mknod "$fname" "$type" "$major" "$(($minor+($i*$inc)))"
2188- $DEBUG chmodchown "$fname" "$mode" "$uid" "$gid"
2189- i=$(($i+1))
2190- done
2191- fi
2192- ;;
2193- esac
2194+
2195+ line=${line%#*}
2196+ [ -n "$line" ] || continue
2197+
2198+ set -f
2199+ set -- $line
2200+ name=$1; type=$2; mode=$3; uid=$4; gid=$5; major=$6; minor=$7; start=$8; inc=$9; count="${10}"
2201+ set +f
2202+
2203+ files="./${name#/}"
2204+
2205+ if iswild "$name"; then
2206+ files=$(echo ./$name)
2207+ iswild "$files" && fail "wildcards in wildcards: $files"
2208+ fi
2209+
2210+ case "$type" in
2211+ f)
2212+ for f in $files; do
2213+ $DEBUG mkdir -p "${f%/*}" || fail "failed to make ${f%/*}";
2214+ done
2215+
2216+ $DEBUG touch $files &&
2217+ $DEBUG chmodchown "$mode" "$uid" "$gid" $files ||
2218+ fail "failed create file $files"
2219+ ;;
2220+ d)
2221+ $DEBUG mkdir -p $files &&
2222+ $DEBUG chmodchown "$mode" "$uid" "$gid" $files ||
2223+ fail "failed create dir $files"
2224+ ;;
2225+ c|b)
2226+ for f in $files; do
2227+ $DEBUG mkdir -p "${f%/*}" || fail "failed to make ${f%/*}";
2228+ done
2229+
2230+ if [ "$count" = "-" ]; then
2231+ $DEBUG mknod $files $type $major $minor ||
2232+ fail "failed mknod"
2233+ $DEBUG chmodchown "$mode" "$uid" "$gid" $files ||
2234+ fail "failed chmodchown '$mode' '$uid' '$gid' $files"
2235+ else
2236+ [ "$count" = "-" ] && count=1;
2237+
2238+ i=0
2239+
2240+ while [ $i -lt $count ]; do
2241+ fname="./$name"
2242+ $DEBUG mknod "$fname" "$type" "$major" "$(($minor+($i*$inc)))"
2243+ $DEBUG chmodchown "$fname" "$mode" "$uid" "$gid"
2244+ i=$(($i+1))
2245+ done
2246+ fi
2247+ ;;
2248+ esac
2249 done
2250+# vi: tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab

Subscribers

People subscribed via source and target branches