#!/bin/bash

DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions


if (whiptail --title "!HDD FORMAT WARNING!" --yesno "After this question, your HDD may be altered independently of questions in automatic mode, do you want to continue?" 8 80) then
    echo "Confirmed $? - ERASE!"
else
    echo "Exit $? - CANCEL!"
    halt -p
fi

ask_and_load_lang_set

imagedir="/run/live/medium/home/partimag"
get_target_dir_name_when_restoring_disk

get_target_hd_name_from_local_machine "$msg_choose_the_disks_to_restore \n$msg_linux_disk_naming $msg_press_space_to_mark_selection" "radiolist"
target_hd="$(select_VG "$target_hd")"


sed -i "s/FILL_IMAGE_NAME/$target_dir/" /etc/ocs/ocs-live.conf
sed -i "s/FILL_DEVICE/$target_hd/" /etc/ocs/ocs-live.conf
cat > "/tmp/scripts.env" << EOF
IMAGE="$target_dir"
DISK="$target_hd"
EOF

"$imagedir/$target_dir/pre.sh"

ocs-live-restore

"$imagedir/$target_dir/post.sh"