commit 9e3c35b53da4a5458c55af777be22b7a60f99655 Author: teldra Date: Sun Feb 6 22:12:28 2022 +0100 init diff --git a/functions b/functions new file mode 100644 index 0000000..5027bac --- /dev/null +++ b/functions @@ -0,0 +1,27 @@ +err() { + echo $1 + echo "exiting.." + exit 1 +} + +input() { + local input + local found="0" + echo "$1 $2" + read input + for i in $2; do + if [ "$i" == "$input" ]; then + found=1 + fi + done + if [ "$found" == "0" ]; then + err "$input: $3" + return 1 + fi + output="$input" +} + +header() { + echo "" + echo "#### $1" +} \ No newline at end of file diff --git a/main.sh b/main.sh new file mode 100644 index 0000000..da5a4df --- /dev/null +++ b/main.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +main="/tmp/vinstall" +target="${main}/target" + +. functions + +target_phy_disk() { + header "Choose target disk" + local DISKS_DETAILS + local output + DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL,WWN|grep disk) + echo "$DISKS_DETAILS" + input "which one?" "$(echo "$DISKS_DETAILS"|awk '{print $1}'|tr '\n' ' ')" "not found." + TARGET_PHY_DISK="$output" +} + +target_phy_id() { + local i + local f1 + local f2 + for i in $(find /dev/disk/by-id|grep -v part); do + if realpath "$i" | grep -q -i "$TARGET_PHY_DISK"; then + if echo "$i" | grep -q "wwn"; then + TARGET_PHY_WWN="$i" + f1=1 + fi + if echo "$i" | grep -q -v "wwn"; then + TARGET_PHY_ID="$i" + f2=1 + fi + fi + done + if [ "$f1" == "1" ] && [ "$f2" == "1" ]; then + return 0 + else + err "no id found" + fi +} + +use_efi() { + if test -e /sys/firmware/efi; then + EFI=1 + else + EFI=0 + fi +} + +encryption_style() { + header "Choose encryption style" + echo "implemented:" + echo "a)keyfile in initramfs" #bios: 1 uefi: 2 + echo "b)no encryption" #bios: 1 uefi: 2 + echo "not implemented:" + echo "c)no keyfile (double pw enter)" #bios: 1 uefi: 2 + echo "d)keyfile on usb" #bios: 1 uefi: ? + echo "e)unencrypted boot" #bios: 2 uefi: 2 + input "how to encrypt?" "a b c d e" "wrong input" + ENCRYPTION_STYLE="$output" +} + +partition() { + if [ "$EFI" == "1" ]; then + echo parted --script $TARGET_PHY_WWN 'mklabel gpt' + else + echo parted --script $TARGET_PHY_WWN 'mklabel msdos' + fi +} + +target_phy_disk +target_phy_id +use_efi +encryption_style