2024-01-22 16:50:16 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
2024-02-27 21:38:35 +01:00
|
|
|
export LANG=en_US.UTF-8
|
2024-02-18 20:36:24 +01:00
|
|
|
|
2024-01-22 16:50:16 +01:00
|
|
|
if [[ "$1" = "get_block_devices" ]]
|
|
|
|
then
|
2024-01-24 20:59:09 +01:00
|
|
|
lsblk -dn -o NAME | grep -v -i -E 'loop|zram|sr|cdrom|portal'
|
2024-01-22 16:50:16 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "get_block_size" ]]
|
|
|
|
then
|
|
|
|
#disk_sector_num=$(cat /sys/block/"$2"/size)
|
|
|
|
#echo ""$(expr $disk_sector_num / 2097152)" GB"
|
|
|
|
lsblk -b --output SIZE -n -d /dev/"$2"
|
|
|
|
fi
|
|
|
|
|
2024-10-11 18:11:15 +02:00
|
|
|
if [[ "$1" = "get_block_model" ]]
|
|
|
|
then
|
|
|
|
cat /sys/class/block/"$2"/device/model
|
|
|
|
fi
|
|
|
|
|
2024-02-16 22:21:09 +01:00
|
|
|
if [[ "$1" = "has_encryption" ]]
|
2024-01-22 16:50:16 +01:00
|
|
|
then
|
2024-02-16 22:21:09 +01:00
|
|
|
if blkid -o value -s TYPE $(lsblk -sJp | jq -r --arg dsk /dev/"$2" '.blockdevices | .[] | select(.name == $dsk) | .children | .[0] | .name') | grep -i luks > /dev/null 2>&1
|
2024-01-22 16:50:16 +01:00
|
|
|
then
|
2024-02-16 22:21:09 +01:00
|
|
|
echo "$2 has encryption"
|
2024-01-22 16:50:16 +01:00
|
|
|
exit 0
|
|
|
|
else
|
2024-02-16 22:21:09 +01:00
|
|
|
echo "$2 is unencrypted"
|
2024-01-22 16:50:16 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "home_not_root" ]]
|
|
|
|
then
|
|
|
|
if [[ $(blkid "$(df -P -h -T "$2" | awk 'END{print $1}')" -s UUID -o value) == $(blkid "$(df -P -h -T "$2/home" | awk 'END{print $1}')" -s UUID -o value) ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-08-19 22:42:36 +02:00
|
|
|
if [[ "$1" = "get_part_uuid" ]]
|
|
|
|
then
|
|
|
|
echo "$(blkid /dev/$2 -s UUID -o value)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "get_luks_uuid" ]]
|
|
|
|
then
|
|
|
|
echo "$(blkid "$(lsblk -sJp | jq -r --arg dsk /dev/"$2" '.blockdevices | .[] | select(.name == $dsk) | .children | .[0] | .name')" -s UUID -o value)"
|
|
|
|
fi
|
|
|
|
|
2024-02-16 08:51:28 +01:00
|
|
|
if [[ "$1" = "get_partitions" ]]
|
|
|
|
then
|
|
|
|
lsblk -ln -o NAME,TYPE | grep -E "part|crypt|lvm" | awk '{print $1}' | while read i ; do
|
2024-11-14 21:48:11 +01:00
|
|
|
if lsblk -ln -o NAME,TYPE | grep -w "$i" | grep "crypt" > /dev/null 2>&1
|
2024-02-16 08:51:28 +01:00
|
|
|
then
|
2024-11-14 21:48:11 +01:00
|
|
|
echo "mapper/$(lsblk -ln -o NAME,TYPE | grep -w "$i" | awk '{print $1}')"
|
2024-02-16 08:51:28 +01:00
|
|
|
fi
|
|
|
|
|
2024-11-14 21:48:11 +01:00
|
|
|
if lsblk -ln -o NAME,TYPE | grep -w "$i" | grep "lvm" > /dev/null 2>&1
|
2024-02-16 08:51:28 +01:00
|
|
|
then
|
2024-11-14 21:48:11 +01:00
|
|
|
echo "mapper/$(lsblk -ln -o NAME,TYPE | grep -w "$i" | awk '{print $1}')"
|
2024-02-16 08:51:28 +01:00
|
|
|
fi
|
|
|
|
|
2024-11-14 21:48:11 +01:00
|
|
|
if lsblk -ln -o NAME,TYPE | grep -w "$i" | grep "part" > /dev/null 2>&1
|
2024-02-16 08:51:28 +01:00
|
|
|
then
|
2024-11-14 21:48:11 +01:00
|
|
|
lsblk -ln -o NAME,TYPE | grep -w "$i" | awk '{print $1}'
|
2024-02-16 08:51:28 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "get_part_fs" ]]
|
|
|
|
then
|
2024-11-14 21:48:11 +01:00
|
|
|
lsblk -ln -o NAME,FSTYPE | grep -w "$2" | awk '{print $2}'
|
2024-02-16 08:51:28 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "get_part_size" ]]
|
|
|
|
then
|
|
|
|
lsblk -b --output SIZE -n -d /dev/"$2"
|
|
|
|
fi
|
|
|
|
|
2024-01-22 16:50:16 +01:00
|
|
|
if [[ "$1" = "home_not_boot" ]]
|
|
|
|
then
|
|
|
|
if [[ $(blkid "$(df -P -h -T "$2/boot" | awk 'END{print $1}')" -s UUID -o value) == $(blkid "$(df -P -h -T "$2/home" | awk 'END{print $1}')" -s UUID -o value) ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "home_not_efi" ]]
|
|
|
|
then
|
|
|
|
if [[ $(blkid "$(df -P -h -T "$2/boot/efi" | awk 'END{print $1}')" -s UUID -o value) == $(blkid "$(df -P -h -T "$2/home" | awk 'END{print $1}')" -s UUID -o value) ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "root_not_boot" ]]
|
|
|
|
then
|
|
|
|
if [[ $(blkid "$(df -P -h -T "$2/boot" | awk 'END{print $1}')" -s UUID -o value) == $(blkid "$(df -P -h -T "$2" | awk 'END{print $1}')" -s UUID -o value) ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$1" = "root_not_efi" ]]
|
|
|
|
then
|
|
|
|
if [[ $(blkid "$(df -P -h -T "$2/boot/efi" | awk 'END{print $1}')" -s UUID -o value) == $(blkid "$(df -P -h -T "$2" | awk 'END{print $1}')" -s UUID -o value) ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "boot_not_efi" ]]
|
|
|
|
then
|
|
|
|
if [[ $(blkid "$(df -P -h -T "$2/boot" | awk 'END{print $1}')" -s UUID -o value) == $(blkid "$(df -P -h -T "$2/boot/efi" | awk 'END{print $1}')" -s UUID -o value) ]]
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-02-16 22:21:09 +01:00
|
|
|
if [[ "$1" = "test_luks_passwd" ]]
|
2024-01-22 16:50:16 +01:00
|
|
|
then
|
2024-02-16 22:21:09 +01:00
|
|
|
if printf "$3" | cryptsetup luksOpen --test-passphrase UUID="$(blkid "$(lsblk -sJp | jq -r --arg dsk /dev/"$2" '.blockdevices | .[] | select(.name == $dsk) | .children | .[0] | .name')" -s UUID -o value)"
|
2024-01-22 16:50:16 +01:00
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|