216 lines
5.3 KiB
Bash
216 lines
5.3 KiB
Bash
#!/bin/bash
|
|
|
|
main="/tmp/vinstall"
|
|
target="${main}/target"
|
|
pass="oem"
|
|
|
|
if [ $DEBUG ]; then
|
|
umount ${target}/boot/efi ${target}/boot ${target}
|
|
vgchange -an
|
|
cryptsetup close /dev/mapper/luks*
|
|
fi
|
|
|
|
mkdir -p $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="/dev/${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: 2 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"
|
|
}
|
|
|
|
hibernation() {
|
|
ramsize="$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))"
|
|
ramsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}/1024); }")"
|
|
HIBERNATE=1
|
|
if [[ "${ramsize}" -lt "2" ]]; then
|
|
SWAPSIZE="$(( ramsize * 2 ))"
|
|
SWAPSIZE="$(( ramsize * 3 ))"
|
|
elif [[ "${ramsize}" -ge "2" ]] && [[ "${ramsize}" -lt "8" ]]; then
|
|
SWAPSIZE="${ramsize}"
|
|
SWAPSIZE="$(( ramsize * 2 ))"
|
|
elif [[ "${ramsize}" -ge "8" ]] && [[ "${ramsize}" -lt "16" ]]; then
|
|
SWAPSIZE="${ramsize}"
|
|
SWAPSIZE="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}*1.5); }")"
|
|
elif [[ "${ramsize}" -ge "16" ]]; then
|
|
SWAPSIZE="4"
|
|
echo "hibernate not recommended, turning off"
|
|
HIBERNATE="0"
|
|
SWAPSIZE="4"
|
|
fi
|
|
}
|
|
|
|
do_partition() {
|
|
header "do partition"
|
|
start=1
|
|
if [ "$EFI" == "1" ]; then
|
|
parted -a optimal $TARGET_PHY_WWN -s -- mklabel gpt
|
|
size=500
|
|
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart EFI fat32 $start $(( start + size ))
|
|
sleep 2
|
|
start=$(( start + size ))
|
|
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart root $start -1s
|
|
mkfs.vfat -F32 ${TARGET_PHY_WWN}-part1
|
|
TARGET_PART="2"
|
|
else
|
|
parted -a optimal $TARGET_PHY_WWN -s -- mklabel msdos
|
|
TARGET_PART="1"
|
|
if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then
|
|
size=2048
|
|
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart primary ext4 $start $(( start + size ))
|
|
sleep 2
|
|
start=$(( start + size ))
|
|
mkfs.btrfs -f "${TARGET_PHY_WWN}-part1"
|
|
TARGET_PART="2"
|
|
fi
|
|
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart primary ext4 $start -1s
|
|
fi
|
|
sleep 2
|
|
TARGETNAME=$(basename ${TARGET_PHY_WWN}-part${TARGET_PART})
|
|
TARGETNAME_UNDERSCORE=${TARGETNAME//-/_}
|
|
echo -n $pass | cryptsetup luksFormat ${TARGET_PHY_WWN}-part${TARGET_PART} -d -
|
|
#echo -n $pass | sudo cryptsetup luksOpen /dev/sdc1 sdc1 -d -
|
|
echo -n $pass | cryptsetup luksOpen ${TARGET_PHY_WWN}-part${TARGET_PART} "luks_${TARGETNAME_UNDERSCORE}" -d -
|
|
vgcreate vg_${TARGETNAME_UNDERSCORE} /dev/mapper/luks_${TARGETNAME_UNDERSCORE}
|
|
lvcreate --name swap -L ${SWAPSIZE}G vg_${TARGETNAME_UNDERSCORE}
|
|
lvcreate --name root -l 100%FREE vg_${TARGETNAME_UNDERSCORE}
|
|
mkswap -f /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-swap
|
|
mkfs.btrfs -f /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root
|
|
mount /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root $target
|
|
btrfs subvol create ${target}/root
|
|
btrfs subvol create ${target}/home
|
|
umount $target
|
|
mount /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root $target -o subvol=root
|
|
if [ "$EFI" == "1" ]; then
|
|
mkdir -p ${target}/boot/efi
|
|
mount ${TARGET_PHY_WWN}-part1 ${target}/boot/efi
|
|
else
|
|
if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then
|
|
mkdir -p ${target}/boot
|
|
mount ${TARGET_PHY_WWN}-part1 ${target}/boot
|
|
fi
|
|
fi
|
|
}
|
|
|
|
user() {
|
|
read -p "Username? " USERNAME
|
|
}
|
|
|
|
gfx() {
|
|
input "Which GFX System?" "amd nvidia intel" "unknown error"
|
|
GFX=$output
|
|
. etc/gfx/$GFX
|
|
packages
|
|
}
|
|
|
|
soundsystem() {
|
|
input "Which Soundsystem" "pulseaudio pipewire" "unknown error"
|
|
SOUNDSYSTEM=$output
|
|
. etc/gfx/$SOUNDSYSTEM
|
|
packages
|
|
}
|
|
|
|
base() {
|
|
. etc/base
|
|
packages
|
|
}
|
|
|
|
de() {
|
|
input "Which Desktop Environment?" "plasma gnome minimal" "unknown error"
|
|
DE=$output
|
|
if ! [ "$DE" == "minimal" ]; then
|
|
gfx
|
|
soundsystem
|
|
. etc/gfx/$DE
|
|
packages
|
|
fi
|
|
}
|
|
|
|
printing() {
|
|
input "Do you want printing?" "yes no" "unknown error"
|
|
if [ "$output" == "yes" ]; then
|
|
addpkg cups
|
|
fi
|
|
}
|
|
|
|
lang() {
|
|
input "Which language?" "de en" "unknown error"
|
|
if [ "$output" == "de" ]; then
|
|
L1=de_DE
|
|
elif [ "$output" == "de" ]; then
|
|
L1=en_US
|
|
fi
|
|
}
|
|
|
|
bootloader() {
|
|
if [ "$EFI" == "1" ]; then
|
|
addpkg grub-x86_64-efi dracut-uefi
|
|
else
|
|
addpkg grub
|
|
fi
|
|
}
|
|
|
|
do_install() {
|
|
echo xbps-install -Sy -R https://alpha.de.repo.voidlinux.org/current -r $target "${pkgs[@]}"
|
|
}
|
|
|
|
target_phy_disk
|
|
target_phy_id
|
|
use_efi
|
|
encryption_style
|
|
hibernation
|
|
user
|
|
base
|
|
bootloader
|
|
de
|
|
do_partition
|
|
do_install |