cleanup
[rrq/rescue-boot.git] / minbase-strap.sh
index 852e9cbc382b61a25d5619ebf97601ddfe6fd394..6f41ac05d5f01bfb1abd9df196e498f034c9e152 100755 (executable)
@@ -30,6 +30,11 @@ if [ -d "$FS" ] ; then
     [ "$REPLY" = 1 ] && DEBSTRAP=false
 fi
 
+stupid_links() {
+    mkdir -p $1/usr
+    for d in bin sbin lib ; do mkdir $1/usr/$d ; ln -s usr/$d $1/$d ; done
+}
+
 if $DEBSTRAP ; then
     ## Optionally add the stupid-links
     read -n 1 -p "prime $FS with stupid-links? [Yn]" x
@@ -37,18 +42,13 @@ if $DEBSTRAP ; then
 
     rm -rf "$FS" # remove if existin
 
-    if $USRMERGE ; then
-       mkdir -p "$FS"/usr
-       for d in bin sbin lib ; do
-           mkdir "$FS"/usr/$d
-           ln -s usr/$d "$FS"/$d
-       done
-    fi
+    $USRMERGE && stupid_links "$FS"
 
     ## bootstrap a filesystem, with exclusions
     echo "http_proxy=$http_proxy debootstrap ..."
     debootstrap --exclude=logrotate,cron,cron-daemon-common \
-               --arch=$ARCH $DIST "$FS" http://deb.devuan.org/merged
+               --arch=$ARCH $DIST "$FS" http://deb.devuan.org/merged || \
+       chroot "$FS" apt-get -f install -y
     chroot "$FS" apt-get install -y logrotate cron
 
     ## Select and add a kernel
@@ -56,8 +56,10 @@ if $DEBSTRAP ; then
                    sed 's/\s.*//' | sort -h ) )
     echo "** Please select kernel **"
     select KERNEL in "${KERNELS[@]}" ; do [ -n "$KERNEL" ] && break ; done
+    VERSION=${KERNEL#linux-image-}
+    VERSION=${VERSION%-unsigned}
     chroot "$FS" apt-get install -y $KERNEL
-    chroot "$FS" depmod -a ${KERNEL#linux-image-}
+    chroot "$FS" depmod -a $VERSION
 
     chroot "$FS" apt-get install -y busybox-static debootstrap
     touch "$FS"/usr/bin{linuxrc,init} # block these
@@ -65,15 +67,6 @@ if $DEBSTRAP ; then
 
 fi # End of $DEBSTRAP actions
 
-## (re)install /init
-echo "** Please select /init template"
-select INIT in none $(echo init*.template) ; do [ -n "$INIT" ] && break ; done
-if [ "$INIT" != none ] ; then
-    cp $INIT "$FS"/init
-    cp message.txt "$FS"/
-    chmod a+x "$FS"/init
-fi
-
 ## Pick boot kernel, if there are many
 LINUXES=( $(cd "$FS"/boot ; ls vmlinuz* 2>/dev/null) )
 if [ ${#LINUXES[@]} -gt 1 ] ; then
@@ -86,55 +79,31 @@ else
     exit 1
 fi
 
-#============================================================
-# Prepare a temporary directory tree with a boot kernel and $FS packed
-# up into an initrd.gz
-TMP=$(mktemp -d XXXX)
-trap "rm -r $TMP" 0 2 15
-
-( cd "$FS" && find -printf '%P\n' | cpio -o -H newc ) | \
-    gzip > $TMP/initrd.gz
-cp $LINUX $TMP/vmlinuz
+. ./minbase-strap-initrd.sh
 
 #============================================================
-# Add syslinux boot equipment for bios boot under $TMP/syslinux
-# (also includes the syslinux image mastering further below)
-echo "Please select boot console options"
-
-CONOPTS=( none ttyS0,115200 )
-select CON in "${CONOPTS[@]}" ; do [ -n "$CON" ] && break ; done
-case "$CON" in none) CON= ;; *) CON="console=$CON" ;; esac
-
-mkdir -p $TMP/syslinux
-cp -t $TMP/syslinux /usr/lib/syslinux/modules/bios/*
-cat <<EOF > $TMP/syslinux/syslinux.cfg
+# Common syslinux menu
+CON="console=ttyS0,115200"
+cat <<EOF > $TMP/menu.cfg
 default menu.c32
-label linux
+label rescue (serial)
+    kernel /vmlinuz
+    append initrd=/initrd.img init=/init $CON rescue
+label rescue2 (vt1)
     kernel /vmlinuz
-    append initrd=/initrd.gz init=/init console=ttyS0,115200 
+    append initrd=/initrd.img init=/init rescue
+label linux2 (sda2)
+    kernel /vmlinuz
+    append initrd=/initrd.img root=/dev/sda2 rootfstype=squashfs $CON
+label linux (sdb1)
+    kernel /vmlinuz
+    append initrd=/initrd.img root=/dev/sdb1 $CON
 EOF
 
-#============================================================
-[ -e "$IMG" ] && read -p "** Will overwrite $IMG (or ^C here and now)" x
-rm -f "$IMG"
-
-# Estimate the required disk image size in Mib
-DUM=$(( $(du -sB1 $TMP | sed 's/\s.*//') / 1048576 + 3 ))
+. ./minbase-strap-bios.sh
+. ./minbase-strap-uefi.sh
+. ./minbase-strap-mkimg.sh
 
-# Create the image, with the partition marked as EFI parition and
-# bootable; acutal format is FAT{12,16,32}
-dd if=/dev/zero of="$IMG" bs=${DUM}M count=0 seek=1 status=none
-cat <<EOF | sfdisk -q "$IMG"
-label: dos
+for E in $ENDING ; do $E ; done
 
-- - 0xef *
-EOF
-# First sector is 2048 by default, which is byte address 1048576
-mkfs.fat --offset 2048 "$IMG" >/dev/null
-mcopy -i "$IMG@@1048576" -s $TMP/* ::/
-[ -z "$SUDO_USER" ] || chown $SUDO_USER: "$IMG"
-
-#============================================================
-# Final syslinux bios boot image mastering
-dd if=/usr/lib/SYSLINUX/mbr.bin of="$IMG" bs=440 conv=notrunc status=none
-syslinux -i -d syslinux -t 1048576 "$IMG"
+#. ./minbase-strap-mkiso.sh $IMG