various refinements
This commit is contained in:
parent
21d1606886
commit
723e4a1710
6 changed files with 414 additions and 178 deletions
|
@ -0,0 +1,147 @@
|
|||
#
|
||||
# Run-time configuration file for dialog
|
||||
#
|
||||
# Automatically generated by "dialog --create-rc <file>"
|
||||
#
|
||||
#
|
||||
# Types of values:
|
||||
#
|
||||
# Number - <number>
|
||||
# String - "string"
|
||||
# Boolean - <ON|OFF>
|
||||
# Attribute - (foreground,background,highlight?,underline?,reverse?)
|
||||
|
||||
# Set aspect-ration.
|
||||
aspect = 0
|
||||
|
||||
# Set separator (for multiple widgets output).
|
||||
separate_widget = ""
|
||||
|
||||
# Set tab-length (for textbox tab-conversion).
|
||||
tab_len = 0
|
||||
|
||||
# Make tab-traversal for checklist, etc., include the list.
|
||||
visit_items = OFF
|
||||
|
||||
# Show scrollbar in dialog boxes?
|
||||
use_scrollbar = OFF
|
||||
|
||||
# Shadow dialog boxes? This also turns on color.
|
||||
use_shadow = ON
|
||||
|
||||
# Turn color support ON or OFF
|
||||
use_colors = ON
|
||||
|
||||
# Screen color
|
||||
screen_color = (BLACK,RED,ON)
|
||||
|
||||
# Shadow color
|
||||
shadow_color = (BLACK,BLACK,ON)
|
||||
|
||||
# Dialog box color
|
||||
dialog_color = (BLACK,WHITE,OFF)
|
||||
|
||||
# Dialog box title color
|
||||
title_color = (BLUE,WHITE,ON)
|
||||
|
||||
# Dialog box border color
|
||||
border_color = (WHITE,WHITE,ON)
|
||||
|
||||
# Active button color
|
||||
button_active_color = (WHITE,BLUE,ON)
|
||||
|
||||
# Inactive button color
|
||||
button_inactive_color = dialog_color
|
||||
|
||||
# Active button key color
|
||||
button_key_active_color = button_active_color
|
||||
|
||||
# Inactive button key color
|
||||
button_key_inactive_color = (RED,WHITE,OFF)
|
||||
|
||||
# Active button label color
|
||||
button_label_active_color = (YELLOW,BLUE,ON)
|
||||
|
||||
# Inactive button label color
|
||||
button_label_inactive_color = (BLACK,WHITE,ON)
|
||||
|
||||
# Input box color
|
||||
inputbox_color = dialog_color
|
||||
|
||||
# Input box border color
|
||||
inputbox_border_color = dialog_color
|
||||
|
||||
# Search box color
|
||||
searchbox_color = dialog_color
|
||||
|
||||
# Search box title color
|
||||
searchbox_title_color = title_color
|
||||
|
||||
# Search box border color
|
||||
searchbox_border_color = border_color
|
||||
|
||||
# File position indicator color
|
||||
position_indicator_color = title_color
|
||||
|
||||
# Menu box color
|
||||
menubox_color = dialog_color
|
||||
|
||||
# Menu box border color
|
||||
menubox_border_color = border_color
|
||||
|
||||
# Item color
|
||||
item_color = dialog_color
|
||||
|
||||
# Selected item color
|
||||
item_selected_color = button_active_color
|
||||
|
||||
# Tag color
|
||||
tag_color = title_color
|
||||
|
||||
# Selected tag color
|
||||
tag_selected_color = button_label_active_color
|
||||
|
||||
# Tag key color
|
||||
tag_key_color = button_key_inactive_color
|
||||
|
||||
# Selected tag key color
|
||||
tag_key_selected_color = (RED,BLUE,ON)
|
||||
|
||||
# Check box color
|
||||
check_color = dialog_color
|
||||
|
||||
# Selected check box color
|
||||
check_selected_color = button_active_color
|
||||
|
||||
# Up arrow color
|
||||
uarrow_color = (GREEN,WHITE,ON)
|
||||
|
||||
# Down arrow color
|
||||
darrow_color = uarrow_color
|
||||
|
||||
# Item help-text color
|
||||
itemhelp_color = (WHITE,BLACK,OFF)
|
||||
|
||||
# Active form text color
|
||||
form_active_text_color = button_active_color
|
||||
|
||||
# Form text color
|
||||
form_text_color = (WHITE,CYAN,ON)
|
||||
|
||||
# Readonly form item color
|
||||
form_item_readonly_color = (CYAN,WHITE,ON)
|
||||
|
||||
# Dialog box gauge color
|
||||
gauge_color = title_color
|
||||
|
||||
# Dialog box border2 color
|
||||
border2_color = dialog_color
|
||||
|
||||
# Input box border2 color
|
||||
inputbox_border2_color = dialog_color
|
||||
|
||||
# Search box border2 color
|
||||
searchbox_border2_color = dialog_color
|
||||
|
||||
# Menu box border2 color
|
||||
menubox_border2_color = dialog_color
|
Binary file not shown.
|
@ -1,13 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
run_in_chroot(){
|
||||
chroot '/target/' /bin/bash -c "${1}"
|
||||
}
|
||||
|
||||
prepare_install(){
|
||||
echo -n "Checking network..."
|
||||
if ! ping -c 4 deb.debian.org &>/dev/null;then
|
||||
tmux popup -h 75% -w 75% -E "nmtui-connect"
|
||||
# tmux popup -h 75% -w 75% -E "nmtui-connect"
|
||||
nmtui-connect
|
||||
fi
|
||||
clear
|
||||
echo -n "Waiting on network"
|
||||
|
@ -15,26 +12,81 @@ prepare_install(){
|
|||
printf "%c" "."
|
||||
sleep 1
|
||||
done
|
||||
|
||||
root_pass=''
|
||||
root_pass_confirm=''
|
||||
|
||||
user_realname=''
|
||||
user_name=''
|
||||
user_pass=''
|
||||
user_pass_confirm=''
|
||||
|
||||
luks_pass=''
|
||||
luks_pass_confirm=''
|
||||
|
||||
stage_status[0]="done"
|
||||
stage_func=("true" "root_setup" "user_setup" "hostname_setup" "disk_setup" "install_system")
|
||||
|
||||
clear
|
||||
}
|
||||
|
||||
menu(){
|
||||
menu_select(){
|
||||
readyicon=()
|
||||
|
||||
menu_select=$(dialog --ok-label 'Menu' --nocancel --clear --stdout \
|
||||
--title 'Device Type' \
|
||||
menu_select=$(dialog --ok-label 'Select' --nocancel --clear --stdout \
|
||||
--title 'Installation Menu' \
|
||||
--menu 'Select the desired configuration page' 0 0 4 \
|
||||
root_setup 'Setup root user' \
|
||||
user_setup 'Setup default user' \
|
||||
device_type_setup 'Select installation type' \
|
||||
hostname_setup 'Set hostname' \
|
||||
partition_setup 'Partition disk' \
|
||||
1 "${stage_icon[1]} Setup root user" \
|
||||
2 "${stage_icon[2]} Setup default user" \
|
||||
3 "${stage_icon[3]} Select installation type and set hostname" \
|
||||
4 "${stage_icon[4]} Setup installation disk" \
|
||||
5 "${stage_icon[5]} Finish configuring and proceed to installation"
|
||||
3>&1 2>&3 3>&-)
|
||||
|
||||
printf "%s" "${menu_select}"
|
||||
}
|
||||
|
||||
menu_helper(){
|
||||
|
||||
while [[ ! "${stage_status[5]}" == "done" ]];do
|
||||
|
||||
for c in {1..5};do
|
||||
current_stage=${c}
|
||||
prev_stage=$(( "${current_stage}" - 1 ))
|
||||
if [[ "${stage_status[${current_stage}]}" == "done" ]];then
|
||||
echo "stage ${current_stage} done" >/dev/null
|
||||
elif [[ "${stage_status[${prev_stage}]}" == "done" ]];then
|
||||
stage_status[${current_stage}]="ready"
|
||||
else
|
||||
stage_status[${current_stage}]="lock"
|
||||
fi
|
||||
done
|
||||
|
||||
for i in {0..5};do
|
||||
case "${stage_status[${i}]}" in
|
||||
"ready" )
|
||||
stage_icon[${i}]=`printf "\xe2\x9d\x8c"`
|
||||
;;
|
||||
"done" )
|
||||
stage_icon[${i}]=`printf "\xe2\x9c\x93"`
|
||||
;;
|
||||
"lock" )
|
||||
stage_icon[${i}]=`printf "\xF0\x9f\x94\x92"`
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
menu_opt=`menu_select`
|
||||
if [[ ! "${stage_status[${menu_opt}]}" == "lock" ]];then
|
||||
"${stage_func[${menu_opt}]}" \
|
||||
&& stage_status[${menu_opt}]="done" \
|
||||
|| stage_status[${menu_opt}]="ready"
|
||||
fi
|
||||
|
||||
done
|
||||
}
|
||||
|
||||
root_setup(){
|
||||
root_pass=''
|
||||
root_pass_confirm=''
|
||||
|
||||
root_info=$(dialog --ok-label 'Submit' --nocancel --clear --stdout \
|
||||
--title "Root Setup" \
|
||||
|
@ -46,14 +98,13 @@ root_setup(){
|
|||
root_info_array=(${root_info})
|
||||
root_pass="${root_info_array[0]}"
|
||||
root_pass_confirm="${root_info_array[1]}"
|
||||
#validate, return exit code
|
||||
validate_pass "${root_pass}" "${root_pass_confirm}" || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
user_setup(){
|
||||
user_realname=''
|
||||
user_name=''
|
||||
user_pass=''
|
||||
user_pass_confirm=''
|
||||
|
||||
user_realname=$(dialog --ok-label 'Submit' --nocancel --stdout --clear \
|
||||
--title 'Default User Full Name' \
|
||||
|
@ -72,10 +123,14 @@ user_setup(){
|
|||
user_name="${user_info_array[0]}"
|
||||
user_pass="${user_info_array[1]}"
|
||||
user_pass_confirm="${user_info_array[2]}"
|
||||
#validate, return exit code
|
||||
validate_username "${user_name}" || return 1
|
||||
validate_pass "${validate_pass}" "${validate_pass_confirm}" || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
device_type_setup(){
|
||||
hostname_setup(){
|
||||
device_type=$(dialog --ok-label 'Submit' --nocancel --clear --stdout \
|
||||
--title 'Device Type' \
|
||||
--menu 'Please select the device type to use for the installation' 0 0 4 \
|
||||
|
@ -84,13 +139,7 @@ device_type_setup(){
|
|||
server 'headless environment intended for remote access' \
|
||||
kiosk 'public desktop environment' \
|
||||
3>&1 2>&3 3>&-)
|
||||
}
|
||||
|
||||
sanitize_hostname(){
|
||||
printf "%s" "${1}" | tr -dc '\-[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
hostname_setup(){
|
||||
if [ "${device_type}" = "user" ];then
|
||||
sys_role="${user_name}"
|
||||
else
|
||||
|
@ -108,88 +157,9 @@ hostname_setup(){
|
|||
--inputbox 'Customize the hostname below' 0 0 "${dest_hostname}" \
|
||||
3>&1 2>&3 3>&-)
|
||||
dest_hostname=`sanitize_hostname "${dest_hostname}"`
|
||||
return 0
|
||||
}
|
||||
|
||||
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>&-)
|
||||
|
||||
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_pass=''
|
||||
luks_pass_confirm=''
|
||||
|
||||
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
|
||||
mem_mb=`grep MemTotal /proc/meminfo | awk '{print $2 "/1024"}' | bc`
|
||||
swap_end=`printf "768+%s\n" "${mem_mb}" | bc`
|
||||
parted "${dest_dev}" mkpart swap linux-swap 768MB "${swap_end}MB" --script --fix --align optimal
|
||||
#root
|
||||
root_mb=`printf "%s*1024\n" "${root_gb}" | bc`
|
||||
root_end=`printf "%s+%s\n" "${swap_end}" "${root_mb}" | bc`
|
||||
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
|
||||
}
|
||||
|
||||
#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
|
||||
#}
|
||||
|
||||
disk_setup(){
|
||||
# partition_method=$(dialog --ok-label 'Submit' --nocancel --stdout \
|
||||
# --title 'Partition Method' \
|
||||
|
@ -201,67 +171,39 @@ disk_setup(){
|
|||
# if [ "${partition_method}" == "manual" ];then
|
||||
# manual_partitioner
|
||||
# elif [ "${partition_method}" == "automatic" ]
|
||||
automatic_partitioner
|
||||
automatic_partitioner || return 1
|
||||
format_partitions || return 1
|
||||
# fi
|
||||
# validate, return exit code
|
||||
return 0
|
||||
}
|
||||
|
||||
encrypt_partition(){
|
||||
echo -n "${3}" | cryptsetup luksFormat "${1}" -
|
||||
echo -n "${3}" | cryptsetup luksOpen "${1}" "${2}_crypt" -
|
||||
}
|
||||
|
||||
get_part_uuid(){
|
||||
lsblk -drno UUID "${1}"
|
||||
}
|
||||
|
||||
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_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}"`
|
||||
}
|
||||
|
||||
create_filesystem(){
|
||||
install_system(){
|
||||
|
||||
#create and mount root
|
||||
target_dir="/target"
|
||||
mkdir -p "${target_dir}"
|
||||
mount "/dev/mapper/root_crypt" "${target_dir}"
|
||||
mount -o compress=zstd "/dev/mapper/root_crypt" "${target_dir}"
|
||||
# btrfs property set "${target_dir}/" compression zstd
|
||||
#create and mount boot
|
||||
mkdir -p "${target_dir}/home"
|
||||
mount "/dev/mapper/home_crypt" "${target_dir}/home"
|
||||
mount -o compress=zstd "/dev/mapper/home_crypt" "${target_dir}/home"
|
||||
# btrfs property set "${target_dir}/home/" compression zstd
|
||||
#create and mount boot
|
||||
mkdir -p "${target_dir}/boot"
|
||||
mount "${boot_part}" "${target_dir}/boot"
|
||||
mount -o compress=zstd "${boot_part}" "${target_dir}/boot"
|
||||
# btrfs property set "${target_dir}/boot/" compression zstd
|
||||
#create and mount efi
|
||||
mkdir -p "${target_dir}/boot/efi"
|
||||
mount "${efi_part}" "${target_dir}/boot/efi"
|
||||
|
||||
#install base system
|
||||
debootstrap --arch "$(dpkg --print-architecture)" unstable "${target_dir}" https://deb.debian.org/debian
|
||||
|
||||
for b in {proc,sys,dev,run};do
|
||||
mount --make-rslave --rbind "/${b}" "/target/${b}"
|
||||
done
|
||||
|
||||
mkdir '/target/etc/crypttab.d'
|
||||
for k in {home,swap};do
|
||||
keyfile_path="/target/etc/crypttab.d/${k}_key"
|
||||
|
@ -288,10 +230,10 @@ EOF
|
|||
|
||||
#fstab for filesystem mounts
|
||||
cat > "${target_dir}/etc/fstab" << EOF
|
||||
/dev/mapper/root_crypt / btrfs defaults,compress 0 1
|
||||
/dev/mapper/home_crypt /home btrfs defaults,compress 0 1
|
||||
/dev/mapper/root_crypt / btrfs defaults,compress=zstd 0 1
|
||||
/dev/mapper/home_crypt /home btrfs defaults,compress=zstd 0 1
|
||||
/dev/mapper/swap_crypt none swap sw 0 0
|
||||
UUID=${boot_uuid} /boot btrfs defaults,compress 0 2
|
||||
UUID=${boot_uuid} /boot btrfs defaults,compress=zstd 0 2
|
||||
UUID=${efi_uuid} /boot/efi vfat umask=0077 0 1
|
||||
EOF
|
||||
|
||||
|
@ -305,17 +247,10 @@ EOF
|
|||
mkdir -p "${target_dir}/etc/apt/sources.list.d"
|
||||
echo "deb [signed-by=/usr/share/keyrings/pogmom.gpg] https://apt.pogmom.me/ unstable main" | tee "${target_dir}/etc/apt/sources.list.d/pogmom.list"
|
||||
|
||||
}
|
||||
|
||||
prepare_chroot(){
|
||||
for b in {proc,sys,dev,run};do
|
||||
mount --make-rslave --rbind "/${b}" "/target/${b}"
|
||||
done
|
||||
|
||||
run_in_chroot "apt-get update"
|
||||
echo "America/Los_Angeles" > /target/etc/timezone
|
||||
# run_in_chroot "DEBIAN_FRONTEND=noninteractive apt-get install -y btrfs-progs locales passwd zram-tools rsync network-manager curl linux-image-amd64 firmware-linux grub-efi grub-pc-bin cryptsetup-initramfs systemd-cryptsetup"
|
||||
run_in_chroot "DEBIAN_FRONTEND=noninteractive apt-get install -y pogmom-utils pogmom-desktop pogmom-apps linux-image-amd64 firmware-linux grub-efi grub-pc-bin cryptsetup-initramfs systemd-cryptsetup"
|
||||
run_in_chroot "DEBIAN_FRONTEND=noninteractive apt-get install -y pogmom-essentials pogmom-utils pogmom-desktop pogmom-apps linux-image-$(dpkg --print-architecture) firmware-linux"
|
||||
#TODO: split pogmom-utils into pogmom-utils and pogmom-essential
|
||||
case "$(hostnamectl chassis)" in
|
||||
laptop)
|
||||
|
@ -341,6 +276,7 @@ prepare_chroot(){
|
|||
EOF
|
||||
|
||||
run_in_chroot "timedatectl set-local-rtc 0"
|
||||
run_in_chroot "systemctl disable NetworkManager-wait-online.service"
|
||||
|
||||
run_in_chroot "dpkg-reconfigure tzdata locales keyboard-configuration"
|
||||
date > /target/root/install_date
|
||||
|
@ -350,13 +286,15 @@ EOF
|
|||
run_in_chroot "echo \"${user_name}:${user_pass}\" | chpasswd"
|
||||
run_in_chroot "usermod -aG sudo ${user_name}"
|
||||
perl -i -pe 's/(GRUB_CMDLINE_LINUX_DEFAULT)="(.*)"/$1="$2 rd.luks.uuid='"${root_luks_uuid}"'"/' /target/etc/default/grub
|
||||
root_kernel_version=`run_in_chroot "uname -r"`
|
||||
run_in_chroot "update-initramfs -c -k all"
|
||||
run_in_chroot "update-grub && grub-install --root-directory / ${dest_dev}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
finalize(){
|
||||
umount -R /target
|
||||
#change echo to dialog
|
||||
echo "Installation is complete, please remove installation medium and press ENTER to restart or CTRL+C to enter the console."
|
||||
read
|
||||
reboot
|
||||
|
|
51
scripts/lib/helpers
Executable file
51
scripts/lib/helpers
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/bin/bash
|
||||
|
||||
error_dialog(){
|
||||
DIALOGRC="${HOME}/.dialogerrrc" dialog --ok-label 'Continue' --nocancel \
|
||||
--title 'Error' \
|
||||
--msgbox "${1}" 0 0
|
||||
}
|
||||
|
||||
run_in_chroot(){
|
||||
chroot '/target/' /bin/bash -c "${1}"
|
||||
}
|
||||
|
||||
validate_pass(){
|
||||
#sanitize password too
|
||||
if [[ "${1}" == "${2}" ]];then
|
||||
return 0
|
||||
else
|
||||
error_dialog "Passwords do not match"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
validate_install_size(){
|
||||
#provide option to have no home part
|
||||
#automatically detect max rootfs partition size
|
||||
disk_size=$(echo '( '`lsblk -b --output SIZE -n -d "${dest_dev}"`' / 1048576 ) - 1024' | bc)
|
||||
if [[ "${disk_size}" -gt "${root_end}" ]];then
|
||||
return 0
|
||||
else
|
||||
error_dialog "Requested installation too large for target device"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
validate_username(){
|
||||
if [[ "${1}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]];then
|
||||
return 0
|
||||
else
|
||||
error_dialog "Bad username format"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
sanitize_hostname(){
|
||||
printf "%s" "${1}" | tr -dc '\-[:alnum:]\n\r' | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
encrypt_partition(){
|
||||
echo -n "${3}" | cryptsetup luksFormat "${1}" -
|
||||
echo -n "${3}" | cryptsetup luksOpen "${1}" "${2}_crypt" -
|
||||
}
|
114
scripts/lib/partition
Executable file
114
scripts/lib/partition
Executable file
|
@ -0,0 +1,114 @@
|
|||
#!/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}"`
|
||||
}
|
|
@ -9,25 +9,11 @@ SCRIPT_ROOT=`dirname "${0}"`
|
|||
#fi
|
||||
|
||||
source ${SCRIPT_ROOT}/lib/functions
|
||||
source ${SCRIPT_ROOT}/lib/partition
|
||||
source ${SCRIPT_ROOT}/lib/helpers
|
||||
|
||||
prepare_install
|
||||
|
||||
#collect_info #break into smaller functions, move luks out, validate inputs
|
||||
|
||||
root_setup
|
||||
|
||||
user_setup
|
||||
|
||||
device_type_setup
|
||||
|
||||
hostname_setup
|
||||
|
||||
disk_setup
|
||||
|
||||
format_partitions
|
||||
|
||||
create_filesystem
|
||||
|
||||
prepare_chroot
|
||||
|
||||
menu_helper
|
||||
finalize
|
||||
|
||||
exit
|
||||
|
|
Loading…
Add table
Reference in a new issue