Add script to do vmdk files
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
|
||||
if [[ "${1:-}" == -h || "${1:-}" == --help ]]; then
|
||||
printf 'Usage: %s [INPUT.iso] [OUTPUT.vmdk]\n' "$0"
|
||||
printf 'Defaults: %s/ep-eraser-amd64.hybrid.iso and %s/ep-eraser-amd64.vmdk\n' "$root" "$root"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if (( $# > 2 )); then
|
||||
printf 'Usage: %s [INPUT.iso] [OUTPUT.vmdk]\n' "$0" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
input=${1:-"$root/ep-eraser-amd64.hybrid.iso"}
|
||||
output=${2:-"$root/ep-eraser-amd64.vmdk"}
|
||||
|
||||
command -v qemu-img >/dev/null 2>&1 || {
|
||||
printf 'ERROR: qemu-img is required (install qemu-utils).\n' >&2
|
||||
exit 1
|
||||
}
|
||||
command -v sha256sum >/dev/null 2>&1 || {
|
||||
printf 'ERROR: sha256sum is required.\n' >&2
|
||||
exit 1
|
||||
}
|
||||
[[ -f "$input" ]] || {
|
||||
printf 'ERROR: ISO not found: %s\n' "$input" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
input=$(realpath -- "$input")
|
||||
output=$(realpath -m -- "$output")
|
||||
checksum="$output.sha256"
|
||||
|
||||
for path in "$output" "$checksum"; do
|
||||
if [[ -e "$path" || -L "$path" ]]; then
|
||||
printf 'ERROR: refusing to overwrite existing file: %s\n' "$path" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
mkdir -p -- "$(dirname -- "$output")"
|
||||
temporary_output="$output.tmp.$$"
|
||||
temporary_checksum="$checksum.tmp.$$"
|
||||
trap 'rm -f -- "$temporary_output" "$temporary_checksum"' EXIT
|
||||
|
||||
qemu-img convert -p -f raw -O vmdk -o subformat=monolithicSparse "$input" "$temporary_output"
|
||||
hash=$(sha256sum < "$temporary_output")
|
||||
printf '%s %s\n' "${hash%% *}" "$(basename -- "$output")" > "$temporary_checksum"
|
||||
mv -- "$temporary_output" "$output"
|
||||
mv -- "$temporary_checksum" "$checksum"
|
||||
trap - EXIT
|
||||
|
||||
qemu-img info "$output"
|
||||
printf 'SHA-256: %s\n' "$checksum"
|
||||
Reference in New Issue
Block a user