#!/bin/sh
DIR=$(dirname $(realpath "$0"))
test "$1" = "-d" && {
  DUMMY=1
  shift
}
test -n "$1" || {
  echo -e "Usage:\n$0 [-d] target-variant[-skipped-part].iso [suffix]" >&2
  exit 1
}
SUFFIX="${2:+-$2}"
PREFIX=$(echo "$(basename "$1")" | sed -E 's/^([^-]+-[^-]+).*/\1/')
echo "$DIR/$PREFIX$SUFFIX-*"
test -n "$DUMMY" && exit 0

for f in vmlinuz initrd.img; do
        7zz e "$1" boot/$f | grep Files
        mv $f $DIR/$PREFIX$SUFFIX-$f
done
