TT#11444 Add RAID configuration menu

Add menu if Software RAID should be configured and which disks
should be part of it. Only 2 disks allowed.

Move all disk selection code to separate script.

Script will write variables to /tmp/disk_selection file to pass
it to main.sh. It is necessary because 'dialog' is used for
interactivity so we can not capture output of script.

Change-Id: I3dd772c9a6ac6db6809688ff38f242271d9551a8
changes/09/23709/3
Mykola Malkov 7 years ago
parent 686ac0f9f7
commit d2c0a9d1ec

@ -0,0 +1,103 @@
#!/bin/bash
set -e
set -u
prompt_for_raid() {
# display disk ID next to the disk name
declare -a DISK_LIST
DISK_LIST=( $(for i in "${AVAILABLE_DISKS[@]}" ; do
disk_info=$(get_disk_info "${i}")
echo "${i}" "${disk_info}" off
done) )
local TMP
TMP=$(mktemp)
if ! dialog --title "Disk selection for Software RAID" --separate-output \
--checklist "Please select the disks you would like to use for your RAID1:" 0 0 0 \
"${DISK_LIST[@]}" 2>"${TMP}" ; then
rm -f "${TMP}"
echo "Cancelling as requested by user during disk selection." >&2
exit 1
fi
TARGET_DISK=( $(cat "${TMP}") ); rm -f "${TMP}"
if [[ "${#TARGET_DISK[@]}" -ne 2 ]]; then
dialog --title "Disk selection for Software RAID" \
--msgbox "Exactly 2 disks need to be selected, cannot continue." 0 0
rerun=true
fi
}
prompt_for_target() {
# display disk ID next to the disk name
declare -a DISK_LIST
DISK_LIST=( $(for i in "${AVAILABLE_DISKS[@]}" ; do
disk_info=$(get_disk_info "${i}")
echo "${i}" "${disk_info}"
done) )
local TMP
TMP=$(mktemp)
if ! dialog --title "Disk selection" --single-quoted \
--ok-label OK --cancel-label Exit \
--menu "Please select the target disk for installing Debian/ngcp:" 0 0 0 \
"${DISK_LIST[@]}" 2>"${TMP}" ; then
rm -f "${TMP}"
echo "Cancelling as requested by user during disk selection." >&2
exit 1
fi
TARGET_DISK=( $(cat "${TMP}") ); rm -f "${TMP}"
}
get_disk_info() {
local disk="${1}"
local disk_info
for file in /dev/disk/by-id/* ; do
case "$(realpath "${file}")" in
"/dev/${disk}")
disk_info="${file#/dev/disk/by-id/}"
break
;;
*)
disk_info="${file}"
;;
esac
done
echo "${disk_info}"
return 0
}
rm -f /tmp/disk_options
declare -a AVAILABLE_DISKS
AVAILABLE_DISKS=( $(awk '/[a-z]$/ {print $4}' /proc/partitions | grep -v '^name$' | sort -u) )
if [[ -z "${AVAILABLE_DISKS[*]}" ]] ; then
dialog --title "Disk selection" \
--msgbox "Sorry, no disks found. Please make sure to have a hard disk attached to your system/VM." 0 0
exit 1
fi
SW_RAID='false'
message="Do you want to configure Software RAID?
Please notice that only RAID level 1 is currently supported. Configuration will take place using mdadm."
if dialog --stdout --title "Software RAID" --defaultno --yesno "${message}" 0 0 ; then
SW_RAID='true'
fi
declare -a TARGET_DISK
if "${SW_RAID}" ; then
rerun=true
while "${rerun}"; do
rerun=false
prompt_for_raid
done
echo "SWRAID_DISK1=${TARGET_DISK[0]} SWRAID_DISK2=${TARGET_DISK[1]}" > /tmp/disk_options
else
prompt_for_target
echo "TARGET_DISK=${TARGET_DISK[0]}" > /tmp/disk_options
fi
exit 0

@ -82,41 +82,6 @@ check_for_existing_pvs()
fi
}
prompt_for_target()
{
AVAILABLE_DISKS=$(awk '/[a-z]$/ {print $4}' /proc/partitions | grep -v '^name$' | sort -u)
if [ -z "$AVAILABLE_DISKS" ] ; then
dialog --title "Disk selection" \
--msgbox "Sorry, no disks found. Please make sure to have a hard disk attached to your system/VM." 0 0
return 1
fi
# display disk ID next to the disk name
DISK_LIST=( $(for i in $AVAILABLE_DISKS ; do
for file in /dev/disk/by-id/* ; do
case "$(realpath "$file")" in
(/dev/"$i") disk_info="${file#/dev/disk/by-id/}" ; break ;;
(*) disk_info="$file" ;;
esac
done
echo "${i}" "${disk_info}"
done) )
TMP=$(mktemp)
if ! dialog --title "Disk selection" --single-quoted \
--ok-label OK --cancel-label Exit \
--menu "Please select the target disk for installing Debian/ngcp:" 0 0 0 \
"${DISK_LIST[@]}" 2>"${TMP}" ; then
rm -f "${TMP}"
ewarn "Cancelling as requested by user during disk selection." ; eend 0
return 1
fi
TARGET_DISK="$(cat "${TMP}")"; rm -f "${TMP}"
}
# }}}
deploy() {
# choose appropriate deployment.sh script:
local version=$(grep -Eo '\<ngcpvers=[^ ]+' /proc/cmdline || true)
@ -128,7 +93,7 @@ deploy() {
einfo "Running ${YELLOW}${version}${NORMAL} of deployment.sh..."; eend 0
RC=0
TARGET_DISK="$TARGET_DISK" "${scripts_dir}/deployment.sh" || RC=$?
"${scripts_dir}/deployment.sh" || RC=$?
if [ $RC -eq 0 ] ; then
if dialog --yes-label Reboot --no-label Exit --yesno "Successfully finished deployment, enjoy your sip:provider system. Reboot system now?" 0 0 ; then
reboot
@ -147,7 +112,15 @@ install_sipwise_keyring
"${scripts_dir}/check_installing_version.sh"
"${scripts_dir}/install_required_packages.sh"
"${scripts_dir}/verify_iso_image.sh"
prompt_for_target
"${scripts_dir}/disk_selection.sh"
if [[ ! -r '/tmp/disk_options' ]]; then
eerror "There is no /tmp/disk_options which should be availible after disk selection" ; eend 0
fi
DISK_OPTIONS="$(cat '/tmp/disk_options')"
if [[ -z "${DISK_OPTIONS}" ]]; then
ewarn "There are no disk options configured, continuing anyway." ; eend 0
fi
export ${DISK_OPTIONS}
check_for_existing_pvs
report_ssh_password
deploy

Loading…
Cancel
Save