From e102469a5464c34d9a3469abc78c15234d2f4c6c Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 4 Mar 2021 15:36:22 +0100 Subject: [PATCH] feat: allow multiple drives --- install.inc | 56 +++++++++++++++++++++++++++---------------------- install.sh | 20 +++++++++++------- maas-images.inc | 24 ++++++++++++++++++--- update.sh | 16 +++++++++----- 4 files changed, 76 insertions(+), 40 deletions(-) diff --git a/install.inc b/install.inc index 3e27a58..3b9208c 100644 --- a/install.inc +++ b/install.inc @@ -6,8 +6,33 @@ function download_version() { local release_version="$1" + local drive="$2" + local downloads=~/Downloads + pushd "$downloads" + + download_and_verify "$release_version" boot-kernel + if [ $? -eq 1 ]; then + popd + exit 1 + fi + download_and_verify "$release_version" boot-initrd + if [ $? -eq 1 ]; then + popd + exit 1 + fi + download_and_verify "$release_version" squashfs + if [ $? -eq 1 ]; then + popd + exit 1 + fi + popd +} + +function install_version() +{ local drive="$2" local target + local downloads=~/Downloads find_unused "$drive" target="$unused" @@ -19,41 +44,22 @@ function download_version() exit 1 fi - downloads="$(mktemp -d)" pushd "$downloads" - - download_and_verify "$release_version" boot-kernel - if [ $? -eq 1 ]; then - popd - rm -rf "$downloads" - exit 1 - fi - download_and_verify "$release_version" boot-initrd - if [ $? -eq 1 ]; then - popd - rm -rf "$downloads" - exit 1 - fi - download_and_verify "$release_version" squashfs - if [ $? -eq 1 ]; then - popd - rm -rf "$downloads" - exit 1 - fi - mount_efi "$drive" mkdir -p "$mnt""$imagepath" - mv boot-initrd "$mnt""$imagepath"/boot-initrd."$release_version" - mv boot-kernel "$mnt""$imagepath"/boot-kernel."$release_version" + [ -f "$mnt""$imagepath"/boot-initrd."$release_version" ] || \ + cp boot-initrd "$mnt""$imagepath"/boot-initrd."$release_version" + [ -f "$mnt""$imagepath"/boot-kernel."$release_version" ] || \ + cp boot-kernel "$mnt""$imagepath"/boot-kernel."$release_version" umount_efi dev_from_partnum "$drive" "$target" dd if=squashfs of="$partition" bs=1M rename_partition "$drive" "$target" root_"$release_version" - rm -f squashfs popd - rmdir "$downloads" update_syslinux_menu "$drive" } +function cleanup_version() + # vim: set ft=sh: diff --git a/install.sh b/install.sh index 6c3f700..20bdd22 100755 --- a/install.sh +++ b/install.sh @@ -3,17 +3,23 @@ . install.inc . drive.inc -drive="$1" +declare -a drives -if [ ! -b "$drive" ]; then - echo "Usage install.sh /dev/wherever" +drives=("$@") + +if [ ${#drives[@]} -eq 0 ]; then + echo "Usage install.sh /dev/drive1 [/dev/drive2 [/dev/drive3 ]]" exit 1 fi -setup_drive "$drive" -install_syslinux "$drive" get_streams get_latest_maas_id -download_version "$release_version" "$drive" -update_syslinux_menu "$drive" + +for drive in "${drives[@]}"; do + setup_drive "$drive" + install_syslinux "$drive" + download_version "$release_version" "$drive" + install_version "$release_version" "$drive" + update_syslinux_menu "$drive" +done cleanup_temp diff --git a/maas-images.inc b/maas-images.inc index e3c6eba..d0a485c 100644 --- a/maas-images.inc +++ b/maas-images.inc @@ -50,17 +50,35 @@ function file_url() url="$baseurl/$url" } +function verify_only() +{ + local release_version="$1" + local fname="$2" + get_checksum "$release_version" "$fname" + sha256sum=$(sha256sum "$fname"|cut -d\ -f1) + if [ "$sha256sum" == "$checksum" ]; then + return 0 + fi + return 1 +} + function download_and_verify() { local release_version="$1" local fname="$2" file_url "$release_version" "$fname" - get_checksum "$release_version" "$fname" + if [ -f "$fname" ]; then + if verify_only "$release_version" "$fname"; then + echo "$fname already downloaded, skipping" + return 0 + fi + echo "Deleting $fname" + rm -f "$fname" + fi wget "$url" -O "$fname" - sha256sum=$(sha256sum "$fname"|cut -d\ -f1) - if [ "$sha256sum" == "$checksum" ]; then + if verify_only "$release_version" "$fname"; then return 0 fi echo "Checksum fail" diff --git a/update.sh b/update.sh index 92fc253..50c9586 100755 --- a/update.sh +++ b/update.sh @@ -2,15 +2,21 @@ . install.inc -drive="$1" +declare -a drives -if [ ! -b "$drive" ]; then - echo "Usage update.sh /dev/wherever" +drives=("$@") + +if [ ${#drives[@]} -eq 0 ]; then + echo "Usage install.sh /dev/drive1 [/dev/drive2 [/dev/drive3 ]]" exit 1 fi get_streams get_latest_maas_id -download_version "$release_version" "$drive" -update_syslinux_menu "$drive" + +for drive in "${drives[@]}"; do + download_version "$release_version" "$drive" + install_version "$release_version" "$drive" + update_syslinux_menu "$drive" +done cleanup_temp