From 7fbc5c0c42e1839e38d3adc6f198a279cd8e042c Mon Sep 17 00:00:00 2001 From: Saverio Miroddi Date: Tue, 5 May 2020 23:06:22 +0200 Subject: [PATCH] Add sample scripts for image-based custom O/S installation --- os_install_scripts/from_target_image-guest.sh | 12 ++++++ os_install_scripts/from_target_image-host.sh | 42 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 os_install_scripts/from_target_image-guest.sh create mode 100755 os_install_scripts/from_target_image-host.sh diff --git a/os_install_scripts/from_target_image-guest.sh b/os_install_scripts/from_target_image-guest.sh new file mode 100755 index 0000000..865fe82 --- /dev/null +++ b/os_install_scripts/from_target_image-guest.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +c_fifo_filename="/tmp/target_image.fifo" +c_root_pool_mount=/mnt + +echo "Restoring the target image..." + +# shellcheck disable=SC2002 # xz doesn't accept as input a fifo, and reverting the commands orde +# is ugly. +cat "$c_fifo_filename" | xz -d | tar xv -C "$c_root_pool_mount" + +echo diff --git a/os_install_scripts/from_target_image-host.sh b/os_install_scripts/from_target_image-host.sh new file mode 100755 index 0000000..2372bc9 --- /dev/null +++ b/os_install_scripts/from_target_image-host.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +# Don't use spaces in the filenames; avoids ugly quoting. +# +c_fifo_filename="/tmp/target_image.fifo" +c_os_install_script="$(dirname "$0")/from_target_image-guest.sh" +c_zfs_installer_script="$(dirname "${0%/*}")/install-zfs.sh" + +if [[ $# -ne 3 ]] || [[ ! -x "$(command -v sshpass)" ]]; then + echo "Usage: $(basename "$0") + +Perform a ZFS installation via custom script \`$(basename "$c_os_install_script")\`, using the provided O/S image. + +The image must be an XZ-tarball of the target mountpoint (typically, \`/target\`), as it is immediately after the installer (S)Ubiquity has finished. +The files must be relative to the target mountpoint. + +Requirements: + +- the \`sshpass\` tool on the host (for convenience); +- the SSH server on the guest, with allowed password authentication; +- the SSH client configured on the host. +" + echo + exit 1 +fi + +v_image=$1 +v_host=$2 +export SSHPASS=$3 + +# Initiate the image copy in the background, but block until it's picked up. +# +sshpass -e ssh "$v_host" "rm -f $c_fifo_filename && mkfifo $c_fifo_filename" +sshpass -e scp -q "$v_image" "$v_host":"$c_fifo_filename" & + +sshpass -e scp "$c_os_install_script" "$c_zfs_installer_script" "$v_host": + +sshpass -e ssh -t "$v_host" "sudo ZFS_OS_INSTALLATION_SCRIPT=./$(basename "$c_os_install_script") ./$(basename "$c_zfs_installer_script")"