From 248c1f033b249dc20899723165cd93ff4a576e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Karpi=C5=84ski?= Date: Tue, 4 Feb 2020 19:21:59 +0100 Subject: [PATCH] sending works --- .gitignore | 1 + Makefile | 4 +++- linux/Makefile | 13 ++++++++++--- linux/src/scripts/menu.sh | 11 +++++------ linux/src/scripts/send_dd.sh | 6 ++++++ linux/src/scripts/send_pc.sh | 6 ++++++ linux/src/scripts/send_sfd.sh | 6 ++++++ pxelinux.cfg | 2 +- receive.sh | 4 ++++ 9 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 linux/src/scripts/send_dd.sh create mode 100644 linux/src/scripts/send_pc.sh create mode 100644 linux/src/scripts/send_sfd.sh create mode 100755 receive.sh diff --git a/.gitignore b/.gitignore index 482ade3..206a25d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ linux/build/ syslinux/ +files/ diff --git a/Makefile b/Makefile index df0a63f..552f39f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: .FORCE + files: files/pxelinux.0 files/initrd.img files/vmlinuz files/pxelinux.cfg/default files/ldlinux.c32 files/root.squashfs files/pxelinux.0: syslinux @@ -16,7 +18,7 @@ files/pxelinux.cfg/default: pxelinux.cfg files/ldlinux.c32: syslinux cp syslinux/bios/com32/elflink/ldlinux/ldlinux.c32 files/ldlinux.c32 -files/root.squashfs: linux/build/rootfs +files/root.squashfs: .FORCE rm files/root.squashfs || true mksquashfs linux/build/rootfs files/root.squashfs diff --git a/linux/Makefile b/linux/Makefile index 314c887..69c0026 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -3,22 +3,29 @@ CHROOT_CMD := chroot build/rootfs /bin/bash -c FILES = $(shell find src/ -type f -print | sed -e 's|^src/|build/rootfs/|') FILES_SRC = $(shell find src/ -type f -print) -all: build/rootfs $(FILES) menu build/rootfs/initrd.img +.PHONY: .FORCE + +all: build/rootfs $(FILES) menu images build/rootfs/initrd.img clean: rm -rf build/rootfs -menu: $(FILES) +menu: $(CHROOT_CMD) "apt install dialog" $(CHROOT_CMD) "chmod +x /scripts/menu.sh" $(CHROOT_CMD) "usermod -s /scripts/menu.sh root" +images: + $(CHROOT_CMD) "apt install -y udpcast" + $(CHROOT_CMD) "apt install -y partclone" + $(CHROOT_CMD) "apt install -y lzop" + build/rootfs/initrd.img: $(FILES) chmod +x build/rootfs/etc/initramfs-tools/scripts/local-top/download.sh $(CHROOT_CMD) "apt update && apt install -y linux-image-4.19.0-6-amd64" $(CHROOT_CMD) "update-initramfs -c -kall" -$(FILES): $(FILES_SRC) +$(FILES): .FORCE mkdir -p $(@D) cp $(shell echo $@ | sed -e 's|^build/rootfs/|src/|') $@ diff --git a/linux/src/scripts/menu.sh b/linux/src/scripts/menu.sh index d780986..d100c20 100644 --- a/linux/src/scripts/menu.sh +++ b/linux/src/scripts/menu.sh @@ -2,13 +2,12 @@ sleep 1 -dialog --menu " " 10 80 5 \ - recv_fsa "Receive and write fsarchiver's archive (to /dev/sda1)" \ - recv_sfd "Receive and write sfdisk's partition table" \ - shell "Run root shell" 2>/tmp/menu \ +dialog --menu " " 20 80 10 \ + send_pc "Send /dev/sda1 image (partclone)" \ + send_sfd "Send /dev/sda partition table (sfdisk)" \ + send_dd "Send /dev/sda MBR (dd)" \ + shell "Run root shell" 2>/tmp/menu if [ "$?" != "0" ]; then CHOICE="shell"; else CHOICE=$(cat /tmp/menu); fi -if ! [ -f "$CHOICE" ]; then CHOICE="shell"; fi - bash $(dirname "$0")/$CHOICE.sh diff --git a/linux/src/scripts/send_dd.sh b/linux/src/scripts/send_dd.sh new file mode 100644 index 0000000..b72ae67 --- /dev/null +++ b/linux/src/scripts/send_dd.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +DISK=/dev/sda +INTERFACE=eth0 + +dd if=$DISK bs=512 count=1 | udp-sender --interface $INTERFACE diff --git a/linux/src/scripts/send_pc.sh b/linux/src/scripts/send_pc.sh new file mode 100644 index 0000000..633da33 --- /dev/null +++ b/linux/src/scripts/send_pc.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +DISK=/dev/sda1 +INTERFACE=eth0 + +partclone.extfs -s /dev/sda1 -c --logfile /tmp/partclone.log 2>/dev/null| lzop | udp-sender --interface $INTERFACE diff --git a/linux/src/scripts/send_sfd.sh b/linux/src/scripts/send_sfd.sh new file mode 100644 index 0000000..5c0e4cc --- /dev/null +++ b/linux/src/scripts/send_sfd.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +DISK=/dev/sda +INTERFACE=eth0 + +sfdisk -d $DISK | udp-sender --interface $INTERFACE diff --git a/pxelinux.cfg b/pxelinux.cfg index a5f229a..04007f3 100644 --- a/pxelinux.cfg +++ b/pxelinux.cfg @@ -2,6 +2,6 @@ DEFAULT linux LABEL linux kernel vmlinuz - append initrd=initrd.img root=/dev/loop0 + append initrd=initrd.img root=/dev/loop0 net.ifnames=0 biosdevname=0 PROMPT 0 TIIMEOUT 0 diff --git a/receive.sh b/receive.sh new file mode 100755 index 0000000..74ea101 --- /dev/null +++ b/receive.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +INTERFACE=$1 +udp-receiver --interface $INTERFACE