Add user confirmation before destructive disk operations in autoinstaller

- Add confirm_installation() function with detailed warning dialog
- Show target disk information (size, model, device path)
- Warn users that all data will be completely erased
- Support graphical confirmation (zenity), text-based (dialog), and terminal fallback
- Require explicit 'yes' confirmation before proceeding
- Add as step 4 before any disk partitioning or formatting
- Update total steps from 8 to 9 and renumber subsequent steps
- Installation can be safely cancelled without any changes to target disk
- Improves safety by preventing accidental data loss
parent ab65d8d2
......@@ -21,7 +21,7 @@ BLUE='\033[0;34m'
NC='\033[0m'
# Progress tracking
TOTAL_STEPS=8
TOTAL_STEPS=9
CURRENT_STEP=0
PROGRESS_PIPE="/tmp/installer_progress"
......@@ -229,6 +229,62 @@ configure_network() {
print_status "Offline installation will work without internet connectivity"
}
# User confirmation before destructive operations
confirm_installation() {
print_header "Installation Confirmation Required"
# Show what will happen
print_status "READY TO BEGIN INSTALLATION"
print_status ""
print_status "Installation Summary:"
print_status " Source: Live system (USB/CD: ${USB_DEVICE:-unknown})"
print_status " Target: $TARGET_DISK (will be completely erased)"
# Get disk size for display
local size_bytes=$(lsblk -rbno SIZE "$TARGET_DISK" 2>/dev/null || echo 0)
local size_gb=$((size_bytes / 1024 / 1024 / 1024))
print_status " Target size: ${size_gb} GB"
# Show disk model if available
local model=$(lsblk -rno MODEL "$TARGET_DISK" 2>/dev/null || echo "Unknown")
print_status " Target model: $model"
print_status ""
print_warning "WARNING: This will COMPLETELY ERASE all data on $TARGET_DISK!"
print_warning "All existing partitions and data will be permanently destroyed!"
print_status ""
# Use graphical confirmation if available
if command -v zenity >/dev/null 2>&1; then
zenity --question \
--title="Installation Confirmation" \
--text="Ready to install MBetter to $TARGET_DISK\n\nWARNING: This will COMPLETELY ERASE all data on $TARGET_DISK!\n\nTarget disk: $TARGET_DISK ($size_gb GB)\nModel: $model\n\nContinue with installation?" \
--width=400 \
--height=200
return $?
elif command -v dialog >/dev/null 2>&1; then
dialog --title "Installation Confirmation" \
--yesno "Ready to install MBetter to $TARGET_DISK\n\nWARNING: This will COMPLETELY ERASE all data on $TARGET_DISK!\n\nTarget disk: $TARGET_DISK ($size_gb GB)\nModel: $model\n\nContinue with installation?" \
15 70
return $?
else
# Terminal confirmation as fallback
echo ""
echo -e "${RED}WARNING: This will COMPLETELY ERASE all data on $TARGET_DISK!${NC}"
echo "Target disk: $TARGET_DISK ($size_gb GB)"
echo "Model: $model"
echo ""
echo -n "Continue with installation? (type 'yes' to confirm): "
read -r confirmation
if [ "$confirmation" = "yes" ] || [ "$confirmation" = "YES" ]; then
return 0
else
return 1
fi
fi
}
# Partition disk automatically
partition_disk() {
print_header "Disk Partitioning"
......@@ -422,25 +478,32 @@ main() {
update_progress 3 "Loading installation configuration..."
find_preseed
# Step 4: Disk Partitioning
update_progress 4 "Partitioning target disk..."
# Step 4: User Confirmation (REQUIRED before destructive operations)
update_progress 4 "Waiting for user confirmation..."
confirm_installation || {
print_error "Installation cancelled by user"
exit 0
}
# Step 5: Disk Partitioning
update_progress 5 "Partitioning target disk..."
partition_disk
mount_target
# Step 5: System Copy (longest step)
update_progress 5 "Copying live system to disk (this may take several minutes)..."
# Step 6: System Copy (longest step)
update_progress 6 "Copying live system to disk (this may take several minutes)..."
copy_live_system
# Step 6: System Configuration
update_progress 6 "Configuring target system..."
# Step 7: System Configuration
update_progress 7 "Configuring target system..."
configure_target_system
# Step 7: Bootloader Installation
update_progress 7 "Installing bootloader..."
# Step 8: Bootloader Installation
update_progress 8 "Installing bootloader..."
install_bootloader
# Step 8: Post-Installation Setup
update_progress 8 "Finalizing installation..."
# Step 9: Post-Installation Setup
update_progress 9 "Finalizing installation..."
run_post_install
# Complete
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment