#!/bin/sh
#DdShurick GPL 230114 for PRA

DEVS=$(awk '/[hs]d/ {print $4}' /proc/partitions | grep -v [0-9])
#if [ "$(echo $DEVS | wc -w)" -gt 1 ]; then
for DEV in $DEVS
do
MEDIA="HD"
[ "$(cat /sys/block/$DEV/events)" = "media_change" ] && MEDIA="USB"
INFO=$(cat /sys/block/$DEV/device/{vendor,model} | tr -d ' ' | tr '\n' ' ')
MENU="${MENU}
$DEV $MEDIA $INFO"
done
yad --title "Выберите устройство" --width 300 --height 200 --center --list --print-column=1 --hide-column=1 --column "" --column "Тип" --column "Инфо" --column "" $MENU
#fi
echo "...Вы уверены?..." | yad --back=red --fontname="24" --wrap --justify=center --margins=10 --tail --width 300 --height 120 --center --undecorated --text-info --button=Да:0 --button=Нет:1
[ $? -gt 0 ] && exit
#Прописываем загрузчик
MYLOG=/tmp/$(basename "$0").log
sudo cp -f /usr/lib/grub4dos/grldr.mbr /tmp/wee.mbr >>$MYLOG 2>&1
sudo dd if=/dev/$DEV bs=1 skip=440 count=72 2>/dev/null | dd of=/tmp/wee.mbr bs=1 seek=440 conv=notrunc >>$MYLOG 2>&1
sudo dd if=/dev/$DEV of=${DEV}.backup.mbr bs=512 count=1 >>$MYLOG 2>&1 #backup
sudo dd if=/tmp/wee.mbr of=/dev/$DEV >>$MYLOG 2>&1
echo "...Готово..." | yad --back=green --fontname="24" --wrap --justify=center --margins=10 --tail --width 300 --height 120 --center --undecorated --text-info --button=Да:0
