From 2af902f2ee3fa682c1cf3a095fd2f90bb5896aa5 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 1 Jul 2018 13:29:48 +0200 Subject: Improve re-runability --- make-boot-image.sh | 92 +++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/make-boot-image.sh b/make-boot-image.sh index 0ba8ce8..720192e 100755 --- a/make-boot-image.sh +++ b/make-boot-image.sh @@ -38,7 +38,7 @@ function mkchroot return 1 fi # Skip files that already exist at target. - [ -f "$dest/$p" ] && continue + [ -s "$dest/$p" ] && continue # Create destination path d=$(echo "$p" | grep -o '.*/') && mkdir -p "$dest/$d" && @@ -64,13 +64,15 @@ EOT exit 1 fi -[ -d "$WORKDIR" ] || mkdir "$WORKDIR" -[ -d "$DLDIR" ] || mkdir "$DLDIR" -[ -d "$OUTDIR" ] || mkdir "$OUTDIR" +mkdir -p "$WORKDIR" "$DLDIR" "$OUTDIR" -if [ ! -e "$WORKDIR/apt-done" ] +if [ ! -e "$DLDIR/apt-update-done" ] then $ROOTCMD apt-get update - # Dependencies of this script (assuming default debian install or live) + > "$DLDIR/apt-update-done" +fi + +if [ ! -e "$WORKDIR/apt-install-done" ] +then # Dependencies of this script (assuming default debian install or live) $ROOTCMD apt-get install wget libncurses5-dev coreutils syslinux # Dependencies for kernel building $ROOTCMD apt-get build-dep linux-source @@ -88,17 +90,18 @@ fi # Kernel build setup # ###################### kernel_tarball=$DLDIR/$(basename $KERNEL_TARBALL_URL) -[ -f "$kernel_tarball" ] || $WGET -O "$kernel_tarball" "$KERNEL_TARBALL_URL" -if [ ! -d "$WORKDIR/kernel" ] -then mkdir "$WORKDIR/kernel" +[ -s "$kernel_tarball" ] || $WGET -O "$kernel_tarball" "$KERNEL_TARBALL_URL" +if [ ! -s "$WORKDIR/kernel/Makefile" ] +then mkdir -p "$WORKDIR/kernel" tar xf "$kernel_tarball" --strip-components=1 -C "$WORKDIR/kernel" fi -if [ ! -d "$WORKDIR/kernel/scripts/Kconfiglib" ] +if [ ! -s "$WORKDIR/kernel/scripts/Kconfiglib/kconfiglib.py" ] then - [ -f "$DLDIR/kconfiglib.py" ] || $WGET -O "$DLDIR/kconfiglib.py" "$KCONFIGLIB_MAIN_URL" - [ -f "$DLDIR/makefile.patch" ] || $WGET -O "$DLDIR/makefile.patch" "$KCONFIGLIB_PATCH_URL" - mkdir "$WORKDIR/kernel/scripts/Kconfiglib" + [ -s "$DLDIR/kconfiglib.py" ] || $WGET -O "$DLDIR/kconfiglib.py" "$KCONFIGLIB_MAIN_URL" + [ -s "$DLDIR/makefile.patch" ] || $WGET -O "$DLDIR/makefile.patch" "$KCONFIGLIB_PATCH_URL" + mkdir -p "$WORKDIR/kernel/scripts/Kconfiglib" + patch -t -p1 -d "$WORKDIR/kernel" < "$DLDIR/makefile.patch" && \ cp "$DLDIR/kconfiglib.py" "$WORKDIR/kernel/scripts/Kconfiglib/kconfiglib.py" patch -t -p1 -d "$WORKDIR/kernel" < "$DLDIR/makefile.patch" fi @@ -190,7 +193,7 @@ chmod +x "$WORKDIR/kernel/scripts/Kconfiglib/customize.py" ############################### ( cd "$WORKDIR/kernel" - if [ ! -f .config ] + if [ ! -s .config ] then make defconfig if [ "x$DEVEL_MODE" == "xy" ] then extra="SCRIPT_ARG=--debug" @@ -200,24 +203,24 @@ chmod +x "$WORKDIR/kernel/scripts/Kconfiglib/customize.py" fi ) -p="$WORKDIR/kernel/tools/perf/perf" -if [ "x$DEVEL_MODE" == "xy" -a ! -f "$p" ] +if [ "x$DEVEL_MODE" == "xy" -a ! -s "$WORKDIR/kernel/tools/perf/perf" ] then ( cd "$WORKDIR/kernel" - make tools/perf + # Workaround : linux-3.16.57 (and others?) have make tools/perf broken, ignore it + make tools/perf || true ) fi # Build additionnal tools from source # ####################################### uftp_tarball=$DLDIR/$(basename "$UFTP_TARBALL_URL") -[ -f "$uftp_tarball" ] || $WGET -O "$uftp_tarball" "$UFTP_TARBALL_URL" -if [ ! -d "$WORKDIR/uftp" ] -then mkdir "$WORKDIR/uftp" +[ -s "$uftp_tarball" ] || $WGET -O "$uftp_tarball" "$UFTP_TARBALL_URL" +if [ ! -s "$WORKDIR/uftp/uftpd.1" ] +then mkdir -p "$WORKDIR/uftp" tar xf "$uftp_tarball" --strip-components=1 -C "$WORKDIR/uftp" fi -if [ ! -f "$WORKDIR/uftp/uftpd" ] +if [ ! -s "$WORKDIR/uftp/uftpd" ] then ( cd "$WORKDIR/uftp/" make NO_ENCRYPTION=1 @@ -226,7 +229,7 @@ fi # Initial Ram Disk building (embed in kernel) # ############################################### -if [ ! -d "$WORKDIR/initrd" ] +if [ ! -L "$WORKDIR/initrd/var/lock" ] then mkdir -p "$WORKDIR/initrd/"{bin,dev,etc/init.d,mnt,root,proc,root,sbin,sys,run/lock,run/uftpd,tmp,var/log} $ROOTCMD cp -a /dev/{null,console,tty1} "$WORKDIR/initrd/dev/" $ROOTCMD chmod 1777 "$WORKDIR/initrd/run/lock" @@ -235,21 +238,25 @@ then mkdir -p "$WORKDIR/initrd/"{bin,dev,etc/init.d,mnt,root,proc,root,sbin,sys, ln -s "../run/lock" "$WORKDIR/initrd/var/lock" fi -if [ ! -f "$WORKDIR/initrd/bin/busybox" ] -then [ -f "$DLDIR/busybox" ] || $WGET -O "$DLDIR/busybox" "$BUSYBOX_BIN_URL" +if [ ! -s "$WORKDIR/initrd/bin/busybox" ] +then [ -s "$DLDIR/busybox" ] || $WGET -O "$DLDIR/busybox" "$BUSYBOX_BIN_URL" cp "$DLDIR/busybox" "$WORKDIR/initrd/bin/busybox" chmod +x "$WORKDIR/initrd/bin/busybox" ln -s /bin/busybox "$WORKDIR/initrd/init" fi -if [ ! -f "$WORKDIR/initrd/etc/keys.bmap" ] +if [ ! -L "$WORKDIR/initrd/init" ] +then ln -s /bin/busybox "$WORKDIR/initrd/init" +fi + +if [ ! -s "$WORKDIR/initrd/etc/keys.bmap" ] then # When using sudo with password auth, ask and cache pass first $ROOTCMD true # The following compound command will suck at asking pass $ROOTCMD dumpkeys | $ROOTCMD loadkeys -b > "$WORKDIR/initrd/etc/keys.bmap" fi -if [ ! -f "$WORKDIR/initrd/usr/sbin/partclone.restore" ] +if [ ! -s "$WORKDIR/initrd/usr/sbin/partclone.restore" ] then ( set +x PATH="$WORKDIR/kernel/tools/perf:/usr/sbin:/usr/bin:/sbin:/bin" @@ -265,7 +272,8 @@ then ( ) fi -if [ "x$DEVEL_MODE" == "xy" ] +# Workaround : kernel 3.2.102 "make tools/perf" do nothing. Other are broken. Prevent failing if perf missing +if [ "x$DEVEL_MODE" == "xy" -a -s "$WORKDIR/kernel/tools/perf/perf"] then ( p="$WORKDIR/kernel/tools/perf/perf" cp -a "$p" "$WORKDIR/initrd/sbin/" @@ -274,20 +282,20 @@ then ( ) fi -if [ ! -d "$WORKDIR/initrd/usr/man" ] -then mkdir -p "$WORKDIR"/initrd/usr/man/man{1,8} "$WORKDIR"/initrd/usr/share/groff/1.22.2/font "$WORKDIR/initrd/etc/groff/" +if [ ! -f "$WORKDIR/initrd/usr/share/groff/current/man.local" ] +then mkdir -p "$WORKDIR"/initrd/usr/man/man{1,8} "$WORKDIR"/initrd/usr/share/groff/current/font "$WORKDIR/initrd/etc/groff/" cp /usr/share/man/man1/{iostat,mpstat,strace,udp-receiver}* "$WORKDIR/initrd/usr/man/man1/" cp /usr/share/man/man8/{dmidecode,partclone,efibootmgr,gdisk,iftop,tcpdump}* "$WORKDIR/initrd/usr/man/man8/" - cp -r /usr/share/groff/1.22.2/font/devascii "$WORKDIR/initrd/usr/share/groff/1.22.2/font/" - cp -r /usr/share/groff/1.22.2/tmac "$WORKDIR/initrd/usr/share/groff/1.22.2/" - cp /etc/groff/man.local "$WORKDIR/initrd/usr/share/groff/1.22.2/" + cp -r /usr/share/groff/current/font/devascii "$WORKDIR/initrd/usr/share/groff/current/font/" + cp -r /usr/share/groff/current/tmac "$WORKDIR/initrd/usr/share/groff/current/" + cp /etc/groff/man.local "$WORKDIR/initrd/usr/share/groff/current/" fi -p="$WORKDIR/initrd/bin/uftp" -if [ ! -f "$p" ] +p="$WORKDIR/initrd/usr/bin/uftpd" +if [ ! -s "$p" ] then ( cd "$WORKDIR/uftp/" - make DESTDIR="../initrd" install + make NO_ENCRYPTION=1 DESTDIR="../initrd" install ) ( set +x @@ -296,7 +304,7 @@ then ( fi p="$WORKDIR/kernel/tools/perf/perf" -if [ "x$KERNEL_TOOLS" == "xy" -a ! -f "$p" ] +if [ "x$KERNEL_TOOLS" == "xy" -a ! -s "$p" ] then ( cp -a "$p" "$WORKDIR/initrd/sbin/" set +x @@ -304,16 +312,16 @@ then ( ) fi -if [ ! -d "$WORKDIR/initrd/var/lib" ] -then [ -f "$DLDIR/pci.ids" ] || $WGET -O "$DLDIR/pci.ids" "$PCI_IDS_URL" - [ -f "$DLDIR/usb.ids" ] || $WGET -O "$DLDIR/usb.ids" "$USB_IDS_URL" +if [ ! -s "$WORKDIR/initrd/usr/share/misc/pci.ids" ] +then [ -s "$DLDIR/pci.ids" ] || $WGET -O "$DLDIR/pci.ids" "$PCI_IDS_URL" + [ -s "$DLDIR/usb.ids" ] || $WGET -O "$DLDIR/usb.ids" "$USB_IDS_URL" mkdir -p "$WORKDIR/initrd/var/lib/usbutils" "$WORKDIR/initrd/usr/share/misc" cp "$DLDIR/usb.ids" "$WORKDIR/initrd/var/lib/usbutils/" cp "$DLDIR/pci.ids" "$WORKDIR/initrd/usr/share/misc/" fi if [ ! -d "$WORKDIR/initrd/lib/firmware" ] -then [ -f "$DLDIR/nic-firmware.deb" ] || $WGET -O "$DLDIR/nic-firmware.deb" "$NIC_FIRMWARE_URL" +then [ -s "$DLDIR/nic-firmware.deb" ] || $WGET -O "$DLDIR/nic-firmware.deb" "$NIC_FIRMWARE_URL" dpkg -x "$DLDIR/nic-firmware.deb" "$WORKDIR/initrd/" find "$WORKDIR/initrd/lib/firmware/" \( -name 'ipw*' -o -name 'brcmfmac*' -o -name '*wifi*' \) -print0 | xargs -r0 rm -v fi @@ -541,10 +549,10 @@ chmod +x "$WORKDIR/initrd/bin/sinkdo" cp "$WORKDIR/kernel/arch/x86/boot/bzImage" "$OUTDIR/BOOTX64.EFI" if [ -n "$OUTUSB" -a -b "$OUTUSB" ] -then [ -d "$WORKDIR/mountpoint" ] || mkdir "$WORKDIR/mountpoint" +then mkdir -p "$WORKDIR/mountpoint" mount | grep -E "^$OUTUSB" -q && $ROOTCMD umount "$OUTUSB" $ROOTCMD mount "$OUTUSB" "$WORKDIR/mountpoint" - [ -d "$WORKDIR/mountpoint/BOOT/EFI" ] || $ROOTCMD mkdir -p "$WORKDIR/mountpoint/EFI/BOOT" + $ROOTCMD mkdir -p "$WORKDIR/mountpoint/EFI/BOOT" $ROOTCMD cp "$OUTDIR/BOOTX64.EFI" "$WORKDIR/mountpoint/EFI/BOOT" $ROOTCMD umount "$WORKDIR/mountpoint" fi -- cgit v1.2.3