114 lines
3.6 KiB
Bash
Executable file
114 lines
3.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
automatic_partitioner(){
|
|
device_menu=()
|
|
for blk_device in $(lsblk -no PATH --nodeps); do
|
|
device_menu+=("$(lsblk -no PATH --nodeps ${blk_device})")
|
|
device_menu+=("$(lsblk -no MODEL,SIZE --nodeps ${blk_device})")
|
|
done
|
|
dest_dev=$(dialog --ok-label "Submit" --nocancel --stdout \
|
|
--menu 'Select Install Destination' \
|
|
20 0 20 \
|
|
"${device_menu[@]}" \
|
|
3>&1 2>&3 3>&-)
|
|
|
|
root_gb=$(dialog --ok-label 'Submit' --nocancel --clear --stdout \
|
|
--title "Root Partition Size" \
|
|
--rangebox "Please set the root partition size in GB" \
|
|
0 0 10 2000 100 \
|
|
3>&1 2>&3 3>&-)
|
|
|
|
mem_mb=`grep MemTotal /proc/meminfo | awk '{print $2 "/1024"}' | bc`
|
|
swap_end=`printf "768+%s\n" "${mem_mb}" | bc`
|
|
root_mb=`printf "%s*1024\n" "${root_gb}" | bc`
|
|
root_end=`printf "%s+%s\n" "${swap_end}" "${root_mb}" | bc`
|
|
|
|
validate_install_size || return 1
|
|
|
|
if [[ ${dest_dev} = *[0-9] ]];then
|
|
part_sep="p"
|
|
else
|
|
part_sep=""
|
|
fi
|
|
efi_part="${dest_dev}${part_sep}1"
|
|
boot_part="${dest_dev}${part_sep}2"
|
|
swap_part="${dest_dev}${part_sep}3"
|
|
root_part="${dest_dev}${part_sep}4"
|
|
home_part="${dest_dev}${part_sep}5"
|
|
|
|
luks_info=$(dialog --ok-label 'Submit' --nocancel --stdout \
|
|
--title "luks Setup" \
|
|
--form "Please enter the following information for luks encryption" \
|
|
0 0 0 \
|
|
"Password:" 1 1 "$luks_pass" 1 25 40 0 \
|
|
"Password (confirm):" 2 1 "$luks_pass_confirm" 2 25 40 0 \
|
|
3>&1 2>&3 3>&-)
|
|
luks_info_array=(${luks_info})
|
|
luks_pass="${luks_info_array[0]}"
|
|
luks_pass_confirm="${luks_info_array[1]}"
|
|
|
|
#new gpt label
|
|
parted "${dest_dev}" mklabel gpt --script --fix
|
|
#efi
|
|
parted "${dest_dev}" mkpart efi fat32 0MB 256MB --script --fix --align optimal
|
|
#boot
|
|
parted "${dest_dev}" mkpart boot btrfs 256MB 768MB --script --fix --align optimal
|
|
#swap
|
|
parted "${dest_dev}" mkpart swap linux-swap 768MB "${swap_end}MB" --script --fix --align optimal
|
|
#root
|
|
parted "${dest_dev}" mkpart root btrfs "${swap_end}MB" "${root_end}MB" --script --fix --align optimal
|
|
#home
|
|
parted "${dest_dev}" mkpart home btrfs "${root_end}MB" 100% --script --fix --align optimal
|
|
|
|
return 0
|
|
}
|
|
|
|
manual_partitioner(){
|
|
target_dev=''
|
|
until [ "${target_dev}" == 'done' ];do
|
|
device_menu=()
|
|
for blk_device in $(lsblk -no PATH --nodeps); do
|
|
device_menu+=("$(lsblk -no PATH --nodeps ${blk_device})")
|
|
device_menu+=("$(lsblk -no MODEL,SIZE --nodeps ${blk_device})")
|
|
done
|
|
device_menu+=("done")
|
|
device_menu+=("Proceed to selecting disks")
|
|
target_dev=`dialog --menu 'Select Install Destination' 20 0 20 "${device_menu[@]}" 2>&1 >/dev/tty`
|
|
tmux popup -h 75% -w 75% -E "cfdisk ${target_dev}"
|
|
done
|
|
for blk_parts in $(lsblk -rno PATH,TYPE | grep -v 'disk$\|crypt$' | awk '{ print $1 } '); do
|
|
device_menu+=("$(lsblk -rno PATH --nodeps ${blk_device})")
|
|
device_menu+=("$(lsblk -rno MODEL,SIZE --nodeps ${blk_device})")
|
|
done
|
|
}
|
|
|
|
format_partitions(){
|
|
#efi partition
|
|
mkfs.vfat "${efi_part}"
|
|
#boot partition
|
|
mkfs.btrfs -f "${boot_part}" -L boot
|
|
#swap partition
|
|
encrypt_partition "${swap_part}" swap "${luks_pass}"
|
|
mkswap /dev/mapper/swap_crypt
|
|
#root partition
|
|
encrypt_partition "${root_part}" root "${luks_pass}"
|
|
mkfs.btrfs /dev/mapper/root_crypt -L root
|
|
#home partition
|
|
encrypt_partition "${home_part}" home "${luks_pass}"
|
|
mkfs.btrfs /dev/mapper/home_crypt -L home
|
|
|
|
get_uuids
|
|
}
|
|
|
|
get_part_uuid(){
|
|
lsblk -drno UUID "${1}"
|
|
}
|
|
|
|
get_uuids(){
|
|
#get uuids
|
|
efi_uuid=`get_part_uuid "${efi_part}"`
|
|
boot_uuid=`get_part_uuid "${boot_part}"`
|
|
swap_luks_uuid=`get_part_uuid "${swap_part}"`
|
|
root_luks_uuid=`get_part_uuid "${root_part}"`
|
|
home_luks_uuid=`get_part_uuid "${home_part}"`
|
|
}
|