]> git.plutz.net Git - blast/blobdiff - Makefile
default packages
[blast] / Makefile
index 29a2582a04413b8ff5fb59a7e96c85b7d5a58062..3b333bd6ca95a9f58af3bc49a1fb3938656e47de 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,13 +14,15 @@ space_:= ${nul_} ${nul_}
 .PHONY: _squash_modules _squash _isosquash _iso_image
 
 ARCH := amd64
-BOOTSTRAP := http://cdn.debian.net/debian
+BOOTSTRAP := http://deb.debian.org/debian
 PACKAGES := ${PACKAGES} apt busybox-static debian-archive-keyring init systemd
 
 # Partition Table (2M) + Boot Partition (126M)+ Root Partition + Slack Space (1M) = 2048M
 BOOT_MB := 62
 ROOT_MB := 959
 
+fstype := ext4
+
 config.mk:
        cp "config.example" "$@"
 
@@ -30,17 +32,19 @@ else
   include ${config}
 endif
 
-ifdef release
-  KEYRING := keys/debian-archive-${release}-stable.gpg
-else
-  release := stretch
-  KEYRING := keys/debian-archive-stretch-stable.gpg
+ifndef release
+  release := bullseye
 endif
 
+KEYRING := keys/debian-archive-${release}-stable.gpg
+KEYRING := keys/debian-archive-${release}-automatic.gpg
+# KEYRING := keys/debian-archive-${release}-security-automatic.gpg
+
 ifndef SOURCES
-define SOURCES := 
-deb    http://cdn.debian.net/debian ${release} main
-endef
+  define SOURCES := 
+  deb  http://deb.debian.org/debian    ${release}      main
+  deb  https://deb.debian.org/debian-security/ ${release}/updates      main
+  endef
 endif
 
 ifdef disk
@@ -66,7 +70,7 @@ else ifdef image
   VOLUME := ${image}
   PBOOT := part_boot.img
   PROOT := part_root.img
-  SYSROOT := sys_root_${release}/
+  SYSROOT := sys_root_${release}_${ARCH}/
   CFGROOT := img_mount/
   
   _target: _mbr _umount _config _install
@@ -84,9 +88,23 @@ else ifdef image
   _umount: _img_mount _config _bootloader_pc
   _mbr: _partcopy _bootloader_pc
 
+else ifdef subvol
+  SYSROOT := sys_root_${release}_${ARCH}/
+  CFGROOT := cfg_root/
+
+  _target: _install _config ${subvol}
+  
+  _bootstrap:
+  _install: _bootstrap
+  _copy: _install
+  _config: _copy
+
+  ${subvol}: _config
+       btrfs sub snap "${CFGROOT}" "$@"
+
 else ifdef squash
   SQUASH := ${squash}
-  SYSROOT := sys_root_${release}/
+  SYSROOT := sys_root_${release}_${ARCH}/
   CFGROOT := cfg_root/
 
   PACKAGES += squashfs-tools nbd-client
@@ -102,7 +120,7 @@ else ifdef squash
 else ifdef iso
   ISO := ${iso}
   ISOROOT := iso_root/
-  SYSROOT := sys_root_${release}/
+  SYSROOT := sys_root_${release}_${ARCH}/
   CFGROOT := cfg_root/
   BOOT_MB := 2
   PBOOT := ${ISOROOT}/efi.img
@@ -116,21 +134,18 @@ else ifdef iso
   _copy: _install
   _config: _copy _squash_modules
   _isosquash: _config
-#  ${PBOOT}: ${ISOROOT}
-#  _format_boot: ${PBOOT}
-#  _efi_mount: ${PBOOT} _format_boot
-#  _efi_umount: _config
   _bootloader_iso: _config
   _iso_image: _bootloader_iso _isosquash # _efi_umount
 
 else ifdef raspi
+  ARCH := armhf
+
   VOLUME := ${raspi}
   PBOOT := rpi_boot.img
   PROOT := rpi_root.img
-  SYSROOT := rpi_root_${release}/
+  SYSROOT := sys_root_${release}_${ARCH}/
   CFGROOT := img_mount/
   
-  ARCH := armhf
   KEYRING := keys/raspbian-archive-keyring.gpg
   BOOTSTRAP := http://raspbian.raspberrypi.org/raspbian
 
@@ -139,7 +154,7 @@ else ifdef raspi
   deb  http://archive.raspberrypi.org/debian ${release} main
   endef
 
-  PACKAGES += firmware-brcm80211 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel
+  PACKAGES += firmware-brcm80211 libraspberrypi-bin libraspberrypi0 pi-bluetooth raspberrypi-bootloader raspberrypi-kernel initramfs-tools
 
   _target: _umount _config
   
@@ -154,7 +169,7 @@ else ifdef raspi
   _copy: _install _img_mount
   _config: _copy _img_mount
   _bootloader_raspi: _img_mount
-  _umount: _img_mount _config _bootloader_raspi
+  _umount: _copy _config _bootloader_raspi
 
 else
   _target:
@@ -167,7 +182,8 @@ ifdef modules
   include $(addsuffix .mk, $(addprefix modules/, $(subst ${comma_},${space_},${modules})))
 endif
 
-ifeq "${ARCH}" "amd64"
+ifeq "$(findstring linux-image, ${PACKAGES})" "linux-image"
+else ifeq "${ARCH}" "amd64"
   PACKAGES += linux-image-amd64
 else ifeq "${ARCH}" "i386"
   PACKAGES += linux-image-686
@@ -175,15 +191,11 @@ endif
 
 export SOURCES SYSROOT CFGROOT VOLUME PBOOT PROOT SQUASH ARCH KEYRING BOOTSTRAP ISOROOT ISO
 
-sys_root_${release}/:
+sys_root_${release}_${ARCH}/:
        btrfs subvol create "$@" || mkdir "$@"
        chmod 755 "$@"
 
-rpi_root_${release}/:
-       btrfs subvol create "$@" || mkdir "$@"
-       chmod 755 "$@"
-
-cfg_root/: sys_root_${release}/ _install
+cfg_root/: sys_root_${release}_${ARCH}/ _install
        -btrfs sub del "$@" || rm -r "$@"
        btrfs sub snap "$<" "$@" || mkdir "$@"
        chmod 755 "$@"
@@ -221,12 +233,13 @@ _norecommends: ${SYSROOT}/etc/apt/apt.conf.d/10norecommends
 
 ${SYSROOT}/etc/apt/apt.conf.d/10norecommends: ${SYSROOT}
        mkdir -p -m 755 "$(dir $@)"
-       printf 'APT::Install-Recommends "false";\n' >"$@"
+       printf 'APT::%s "false";\n' "Install-Recommends" "Keep-Recommends" "Install-Suggests" "Keep-Suggests" >"$@"
        chmod 644 "$@"
 
 ${SYSROOT}/etc/apt/trusted.gpg.d/: ${SYSROOT} _bootstrap
        mkdir -p -m 755 "$@"
        cp keys/*.gpg "$@"
+       chmod 644 "$@"/*.gpg
 
 _install: ${SYSROOT} _aptkeys _norecommends
        printf '%s\n' "$${SOURCES}" |sort -u >"$${SYSROOT}/etc/apt/sources.list"
@@ -235,20 +248,26 @@ _install: ${SYSROOT} _aptkeys _norecommends
        -chroot "$${SYSROOT}" apt-get update
        chroot "$${SYSROOT}" ln -sf /bin/true /usr/local/sbin/invoke-rc.d
        chroot "$${SYSROOT}" ln -sf /bin/true /usr/sbin/udevadm
-       chroot "$${SYSROOT}" apt-get --yes install ${PACKAGES}
+       mountpoint "$${SYSROOT}/proc" || mount -o bind /proc "$${SYSROOT}/proc"
+       chroot "$${SYSROOT}" apt-get --yes -t "${release}" install ${PACKAGES}
+       mkdir -p -m 755 "$${SYSROOT}/var/lib/deborphan/"
+       chroot "$${SYSROOT}" sh -c 'printf "%s\\n" ${PACKAGES} >/var/lib/deborphan/keep'
+       -chroot "$${SYSROOT}" sh -c 'apt-get --yes purge $$(deborphan -an |sed "s;^.* ;;g")'
        chroot "$${SYSROOT}" apt-get --yes --auto-remove purge
        -chroot "$${SYSROOT}" apt-get --yes --auto-remove upgrade
+       -umount "$${SYSROOT}/proc"
        chroot "$${SYSROOT}" apt-get clean
        chroot "$${SYSROOT}" rm /usr/local/sbin/invoke-rc.d
        chroot "$${SYSROOT}" rm /usr/sbin/udevadm
 
 _copy: ${SYSROOT} ${CFGROOT}
+       sync
        cp -au "$${SYSROOT}/." "$${CFGROOT}/"
 
 _config: ${CFGROOT}
        ln -sf /dev/null "$${CFGROOT}/etc/systemd/network/99-default.link"
        printf '\nsession       optional        pam_mkhomedir.so umask=0027\n' >>"$${CFGROOT}/etc/pam.d/common-session"
-       printf 'LABEL=FSROOT / ext4 auto,nofail,rw 0 0\nLABEL=BOOT /boot vfat auto,nofail,ro 0 0\n' \
+       printf 'LABEL=FSROOT / ${fstype} auto,nofail,rw 0 0\nLABEL=BOOT /boot vfat auto,nofail,ro 0 0\n' \
                >"$${CFGROOT}/etc/fstab"
        chroot "$${CFGROOT}" update-initramfs -u
 
@@ -264,7 +283,8 @@ _squash: ${SQUASH} _squash_modules
 _isosquash: ${ISOROOT}/live/live.squashfs
 ${ISOROOT}/live/live.squashfs: ${CFGROOT} ${ISOROOT} .FORCE
        -rm "$@"
-       printf '%s\n' boot |mksquashfs "$${CFGROOT}" "$@" -comp xz -ef /dev/stdin
+       { cd "$${CFGROOT}"; printf '%s\n' boot/*; } \
+       | mksquashfs "$${CFGROOT}" "$@" -comp xz -ef /dev/stdin
 
 ${VOLUME}: .FORCE
        ! printf '%s\n' "$${VOLUME}" |grep -q '^/dev/'  # abort if volume should be real device
@@ -292,9 +312,15 @@ _partition_gpt: ${VOLUME}
 
 _sparse: ${PBOOT} ${PROOT}
 
+ifeq "${fstype}" "ext4"
+  fsflag:=-F
+else
+  fsflag:=-f
+endif
+
 _format_root: ${PROOT}
        -umount "$${CFGROOT}/boot" "$${CFGROOT}" "${PROOT}"
-       mkfs.ext4 -F -L FSROOT "$${PROOT}"
+       mkfs.${fstype} ${fsflag} -L FSROOT "$${PROOT}"
 
 _format_boot: ${PBOOT}
        -umount "$${CFGROOT}/boot" "${PBOOT}"
@@ -302,11 +328,8 @@ _format_boot: ${PBOOT}
 
 _format: _format_root _format_boot
 
-_iso_image: ${ISOROOT} # _efi_iso _efi_umount
-       xorriso -as mkisofs -o "$${ISO}" -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-               -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
-               "$${ISOROOT}"
-               # -eltorito-alt-boot -e efi.img -no-emul-boot -isohybrid-gpt-basdat \
+_iso_image: ${ISOROOT}
+       grub-mkrescue -o "$${ISO}" "$${ISOROOT}"
 
 .PHONY: _syslinux_efi32 _syslinux_efi64 _syslinux_bios
 .PHONY: _grub_efi32 _grub_efi64
@@ -341,7 +364,7 @@ _grub_efi64: ${CFGROOT}
        grub-mkimage -p / -O x86_64-efi fat part_gpt normal linux all_video >"$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI"
 
 ${CFGROOT}/boot/cmdline.txt: ${CFGROOT}
-       printf 'root=/dev/mmcblk0p2 rootfstype=ext4 fsck.repair=yes rootwait' >"$@"
+       printf 'root=/dev/mmcblk0p2 rootfstype=${fstype} fsck.repair=yes rootwait net.ifnames=0' >"$@"
 
 _bootloader_raspi: ${CFGROOT} ${CFGROOT}/boot/cmdline.txt
 
@@ -360,17 +383,18 @@ _bootloader_pc: ${CFGROOT} _grub_efi32 _grub_efi64 _syslinux_bios #_syslinux_efi
                "$$k" "$$i" >>"$${CFGROOT}/boot/grub.cfg"
 
 _bootloader_iso: ${CFGROOT} ${ISOROOT}
-       # grub-mkimage -p / -O i386-pc-eltorito biosdisk iso9660 normal linux all_video >"$${ISOROOT}/grub.bin"
+       mkdir -p "$${ISOROOT}/boot/grub/"
        cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${ISOROOT}"
-       cp /usr/lib/ISOLINUX/isolinux.bin $(addprefix /usr/lib/syslinux/modules/bios/, ldlinux.c32 menu.c32 libutil.c32) "$${ISOROOT}"
-       # printf '%s\n' "set timeout=10" "default=buster" \
-       #       "menuentry 'Debian Buster' --id 'buster' {" \
-       #       "linux '/vmlinuz' boot=live" "initrd '/initrd.img'" "}" \
-       #       >"$${ISOROOT}/grub.cfg"
-       printf '%s\n' "UI menu.c32" "DEFAULT buster" "TIMEOUT 100" \
-               "LABEL buster" "  MENU LABEL Debian Buster 64bit" \
-               "  KERNEL /vmlinuz" "  APPEND initrd=/initrd.img boot=live" \
-               >"$${ISOROOT}/syslinux.cfg"
+       printf '%s\n' "insmod all_video" "set gfxmode=auto" "load_video" "insmod gfxterm" \
+               >"$${ISOROOT}/boot/grub/grub.cfg"
+       printf '%s\n' "set timeout=10" "default=${release}" \
+               "menuentry 'Debian ${release}' --id '${release}' {" \
+               "linux '/vmlinuz' boot=live" "initrd '/initrd.img'" "}" \
+               >>"$${ISOROOT}/boot/grub/grub.cfg"
+       -[ -f "$${ISOROOT}/install/initrd.gz" -a -f "$${ISOROOT}/install/linux" ] && \
+       printf '%s\n' "menuentry 'Install Debian' --id 'install' {" \
+               "linux '/install/linux'" "initrd '/install/initrd.gz'" "}" \
+               >>"$${ISOROOT}/boot/grub/grub.cfg"
 
 _efi_mount: ${PBOOT}
        -umount "efi/"
@@ -378,11 +402,9 @@ _efi_mount: ${PBOOT}
        mount -t vfat -o loop "$${PBOOT}" "efi/"
 
 _efi_umount: _efi_mount
+       sync
        umount efi/ && rmdir efi/
 
-_efi_iso: _efi_mount _grub_efi32 _grub_efi64
-       cp -r "$${CFGROOT}/boot/EFI/." "efi/EFI/"
-
 .PHONY: _syslinux_mbr _grub_mbr
 
 _syslinux_mbr: ${VOLUME}
@@ -399,12 +421,14 @@ _partcopy: ${VOLUME} ${PROOT} ${PBOOT}
        dd conv=notrunc,sparse bs=1M seek=$$((2 + ${BOOT_MB})) if="$${PROOT}" of="$${VOLUME}"
 
 _mount_root: ${PROOT} ${CFGROOT}
-       mount -t ext4 "$${PROOT}" "$${CFGROOT}"
+       mountpoint "$${CFGROOT}" \
+       || mount -t ${fstype} "$${PROOT}" "$${CFGROOT}"
        chmod 755 "$${CFGROOT}"
 
 _mount_boot: ${PBOOT}
        mkdir -p -m 755 "$${CFGROOT}/boot"
-       mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot"
+       mountpoint "$${CFGROOT}/boot" \
+       || mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot"
 
 ifdef disk
   _mount_boot: _mount_root
@@ -412,18 +436,22 @@ endif
 
 _mount: _mount_root _mount_boot
 
-_img_mount:
-       mount -o loop,offset="$$((${BOOT_MB} + 2))"M,sizelimit=${ROOT_MB}M \
-         -t ext4 "$${VOLUME}" "$${CFGROOT}"
+_img_mount: ${CFGROOT}
+       mountpoint "$${CFGROOT}" \
+       || mount -o loop,offset="$$((${BOOT_MB} + 2))"M,sizelimit=${ROOT_MB}M \
+                -t ${fstype} "$${VOLUME}" "$${CFGROOT}"
        chmod 755 "$${CFGROOT}"
        mkdir -p -m 755 "$${CFGROOT}/boot"
-       mount -o loop,offset=2M,sizelimit=${BOOT_MB}M \
-         -t vfat "$${VOLUME}" "$${CFGROOT}/boot"
+       mountpoint "$${CFGROOT}/boot" \
+       || mount -o loop,offset=2M,sizelimit=${BOOT_MB}M \
+                -t vfat "$${VOLUME}" "$${CFGROOT}/boot"
 
-_umount_boot: ${CFGROOT}
+_umount_boot: ${CFGROOT} _config
+       sync
        -umount "$${CFGROOT}/boot"
 
-_umount_root: _umount_boot
+_umount_root: _umount_boot _config
+       sync
        umount "$${CFGROOT}" && rmdir "$${CFGROOT}"
 
 _umount: _umount_boot _umount_root
@@ -438,8 +466,7 @@ clean:
        -rmdir hdd_mount
        if [ -d "cfg_root/" ]; then btrfs sub del "cfg_root/" || rm -r "cfg_root/"; fi
        if [ -d "iso_root/" ]; then btrfs sub del "iso_root/" || rm -r "iso_root/"; fi
-       if [ -d "sys_root_${release}/" ]; then btrfs sub del "sys_root_${release}/" || rm -r "sys_root_${release}/"; fi
-       if [ -d "rpi_root_${release}/" ]; then btrfs sub del "rpi_root_${release}/" || rm -r "rpi_root_${release}/"; fi
+       if [ -d "sys_root_${release}_${ARCH}/" ]; then btrfs sub del "sys_root_${release}_${ARCH}/" || rm -r "sys_root_${release}_${ARCH}/"; fi
        -rm part_boot.img
        -rm part_root.img
        -rm rpi_boot.img