From a2770630a06432987b79b453c5fede5d100ccdef Mon Sep 17 00:00:00 2001 From: Michael Shigorin Date: Thu, 3 Sep 2020 23:00:55 +0300 Subject: [PATCH] e2k: add /write.sh into ISO images There's some peculiarity in writing ISO images for e2k onto USB Flash media: we need to arrange a partition and ext2 filesystem with its label passed to propagator; the former part is what's expected, and the latter one is what this script does. Thanks to aerodisk.ru guys for catching a brown paper bag class typo making format() try to affect the image and not the drive, by the way. --- features.in/e2k/lib/50-e2k-write.sh | 46 +++++++++++++++++++++++++++++ features.in/e2k/lib/50-e2k.mk | 4 +++ 2 files changed, 50 insertions(+) create mode 100755 features.in/e2k/lib/50-e2k-write.sh create mode 100644 features.in/e2k/lib/50-e2k.mk diff --git a/features.in/e2k/lib/50-e2k-write.sh b/features.in/e2k/lib/50-e2k-write.sh new file mode 100755 index 00000000..1a7edc38 --- /dev/null +++ b/features.in/e2k/lib/50-e2k-write.sh @@ -0,0 +1,46 @@ +#!/bin/sh -efu +# ALT: write Elbrus boot media +# public domain 2020 Michael Shigorin + +error() { echo "$@" >&2; exit 1; } +usage() { error "Usage: $0 /path/to/alt-e2k.iso /dev/sdX1_or_/dev/sr0"; } + +[ $# = 2 ] || usage +[ -s "$1" ] || usage +[ -b "$2" ] || usage + +checkuid() { [ "$(id -u)" = 0 ] || error "$0: need to run as root"; } +format() { mkfs.ext2 -E packed_meta_blocks=1,num_backup_sb=1 -L altinst "$1"; } + +case "$2" in +/dev/sr[0-9]*|dvd*|cd*) + grep -qw "^$2" /proc/mounts && checkuid && umount -v "$2" + echo "Writing DVD image..." + growisofs -dvd-compat -Z "$2"="$1" + ;; +/dev/sd*) + grep -q "^$1" /proc/mounts && error "$1 mounted already" + checkuid + [ "$(blkid -o value -s LABEL "$2")" = "altinst" ] || format "$2" + src="$(mktemp -d)" + dst="$(mktemp -d)" + echo -n "mounting image... " + mount -o loop,ro "$1" "$src"; echo "done" + echo -n "mounting drive... " + mount -o noatime "$2" "$dst"; echo "done" + echo "copying contents..." + rsync -Pavc --inplace --delete --numeric-ids "$src/" "$dst/" || + cp -avt "$dst" -- "$src"/{.disk,*} + grep -q "^default=.*_flash$" "$dst/boot.conf" || { + echo -n "updating default boot target... " + sed -i 's,default=install$,&_flash,' "$dst/boot.conf" + echo "done" + } + echo -n "unmounting media... " + umount "$src" "$dst" + echo "done." + ;; +*) + usage + ;; +esac diff --git a/features.in/e2k/lib/50-e2k.mk b/features.in/e2k/lib/50-e2k.mk new file mode 100644 index 00000000..dd9847e8 --- /dev/null +++ b/features.in/e2k/lib/50-e2k.mk @@ -0,0 +1,4 @@ +WHATEVER += files/write.sh + +files/write.sh: + @install -pDm755 lib/50-e2k-write.sh files/write.sh