melawy-dracut-module-luks-u.../usr/bin/luks-unlock-shell

48 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
trap '' INT TERM TSTP PIPE
clear
echo -e "\033[1;36m=== Melawy OS Remote Decryption Infrastructure ===\033[0m"
echo -e "Хост: Защищенный рантайм Initramfs (Dracut Layer)"
echo -e "Статус: Ожидание разблокировки LUKS-контейнеров...\n"
unlock_volumes() {
local attempts=0
local max_attempts=5
while [ $attempts -lt $max_attempts ]; do
read -s -p "Введите мастер-пароль Melawy OS: " passphrase
echo ""
if [ -z "$passphrase" ]; then
echo -e "\033[1;31m[Ошибка] Пароль не может быть пустым.\033[0m\n"
((attempts++))
continue
fi
echo "Проверка сигнатур и расшифровка контейнеров..."
local success=true
for dev in /dev/disk/by-id/* /dev/sd* /dev/nvme* 2>/dev/null; do
if [ -b "$dev" ] && cryptsetup isLuks "$dev" 2>/dev/null; then
local uuid=$(cryptsetup luksUUID "$dev" 2>/dev/null)
if [ ! -b "/dev/mapper/luks-$uuid" ]; then
echo "-> Открываем контейнер UUID: $uuid ($dev)..."
echo -n "$passphrase" | cryptsetup open "$dev" "luks-$uuid" 2>/dev/null
if [ $? -ne 0 ]; then success=false; fi
fi
fi
done
if [ "$success" = true ]; then
echo -e "\n\033[1;32m[Успех] Все LUKS-контейнеры успешно расшифрованы!\033[0m"
if [ -f /tmp/cryptroot-asked ]; then echo "1" > /tmp/cryptroot-asked; fi
systemctl restart systemd-cryptsetup@* 2>/dev/null || true
udevadm trigger --action=change 2>/dev/null || true
sleep 2
exit 0
else
echo -e "\033[1;31m[Сбой] Неверный мастер-пароль.\033[0m"
local remaining=$((max_attempts - attempts - 1))
echo -e "Осталось попыток: $remaining\n"
((attempts++))
fi
done
exit 1
}
unlock_volumes