From 78dd04b0ea800518ced6a6b799d80a9da2fd461c Mon Sep 17 00:00:00 2001 From: Penelope Gwen Date: Sun, 12 Jan 2025 20:50:10 -0800 Subject: [PATCH] backing up changes --- scripts/lib/functions | 101 ++++++++++++++++++++++---------------- scripts/lib/helpers | 17 +++++-- scripts/lib/install_types | 17 +++++++ scripts/lib/partition | 59 ++++++++++++---------- scripts/setup.sh | 14 ++++-- scripts/test.sh | 23 +++++++++ sudo | 1 + 7 files changed, 155 insertions(+), 77 deletions(-) create mode 100644 scripts/lib/install_types create mode 100755 scripts/test.sh create mode 100644 sudo diff --git a/scripts/lib/functions b/scripts/lib/functions index 46e4359..411be52 100644 --- a/scripts/lib/functions +++ b/scripts/lib/functions @@ -1,13 +1,13 @@ #!/bin/bash prepare_install(){ - echo -n "Checking network..." + printf "Checking network..." if ! ping -c 4 deb.debian.org &>/dev/null;then # tmux popup -h 75% -w 75% -E "nmtui-connect" nmtui-connect fi clear - echo -n "Waiting on network" + printf "Waiting on network" while ! timeout 1 ping -c 1 deb.debian.org &> /dev/null;do printf "%c" "." sleep 1 @@ -35,7 +35,7 @@ menu_select(){ menu_select=$(dialog --ok-label 'Select' --nocancel --clear --stdout \ --title 'Installation Menu' \ - --menu 'Select the desired configuration page' 0 0 4 \ + --menu 'Select the desired configuration page\n[/] Setup Complete\n[-] Setup Pending\n[X] Setup Locked' 0 0 4 \ 1 "${stage_icon[1]} Setup root user" \ 2 "${stage_icon[2]} Setup default user" \ 3 "${stage_icon[3]} Select installation type and set hostname" \ @@ -54,7 +54,7 @@ menu_helper(){ current_stage=${c} prev_stage=$(( "${current_stage}" - 1 )) if [[ "${stage_status[${current_stage}]}" == "done" ]];then - echo "stage ${current_stage} done" >/dev/null + printf "stage %s done" "${current_stage}" >/dev/null elif [[ "${stage_status[${prev_stage}]}" == "done" ]];then stage_status[${current_stage}]="ready" else @@ -65,13 +65,13 @@ menu_helper(){ for i in {0..5};do case "${stage_status[${i}]}" in "ready" ) - stage_icon[${i}]=`printf "\xe2\x9d\x8c"` + stage_icon[${i}]=`printf "[/]"` ;; "done" ) - stage_icon[${i}]=`printf "\xe2\x9c\x93"` + stage_icon[${i}]=`printf "[-]"` ;; "lock" ) - stage_icon[${i}]=`printf "\xF0\x9f\x94\x92"` + stage_icon[${i}]=`printf "[X]"` ;; esac done @@ -123,7 +123,6 @@ 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 @@ -140,17 +139,16 @@ hostname_setup(){ kiosk 'public desktop environment' \ 3>&1 2>&3 3>&-) - if [ "${device_type}" = "user" ];then + if [[ "${device_type}" == "user" ]];then sys_role="${user_name}" else sys_role="${device_type}" fi sys_manufacturer=`dmidecode -s system-manufacturer` - sys_model=`dmidecode -s system-product-name` - sys_serialno=`dmidecode -s system-serial-number` + sys_uuid=`dmidecode -s system-uuid | tr -d '\n\t\r ' | tail -c 5` - dest_hostname=`printf "%s-%s%s-%s" "${sys_role}" "${sys_manufacturer}" "${sys_model}" "${sys_serialno}"` + dest_hostname=`printf "%s-%s-%s" "${sys_role}" "${sys_manufacturer}" "${sys_uuid}"` dest_hostname=`sanitize_hostname "${dest_hostname}"` dest_hostname=$(dialog --ok-label 'Submit' --nocancel --clear --stdout \ --title 'Hostname' \ @@ -161,38 +159,46 @@ hostname_setup(){ } disk_setup(){ -# partition_method=$(dialog --ok-label 'Submit' --nocancel --stdout \ -# --title 'Partition Method' \ -# --menu 'Please select the partition method to use for the installation' 0 0 4 \ -# manual 'Manually partition installation' \ -# automatic "Use recommended partitioning scheme [DESTRUCTIVE]" \ -# 3>&1 2>&3 3>&-) + partition_method=$(dialog --ok-label 'Submit' --nocancel --stdout \ + --title 'Partition Method' \ + --menu 'Please select the partition method to use for the installation' 0 0 4 \ + manual 'Manually partition installation' \ + automatic "Use recommended partitioning scheme [DESTRUCTIVE]" \ + 3>&1 2>&3 3>&-) -# if [ "${partition_method}" == "manual" ];then -# manual_partitioner -# elif [ "${partition_method}" == "automatic" ] + if [ "${partition_method}" == "manual" ];then + manual_partitioner || return 1 + elif [ "${partition_method}" == "automatic" ];then automatic_partitioner || return 1 - format_partitions || return 1 -# fi -# validate, return exit code + fi + + 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]}" + return 0 } install_system(){ + format_partitions || return 1 #create and mount root target_dir="/target" mkdir -p "${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 -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 -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" @@ -218,7 +224,7 @@ for k in {home,swap};do keyfile_device="${home_part}" ;; esac - echo -n "${luks_pass}" | cryptsetup luksAddKey "${keyfile_device}" "${keyfile_path}" - + printf "%s" "${luks_pass}" | cryptsetup luksAddKey "${keyfile_device}" "${keyfile_path}" - done #crypttab for luks-encrypted partitions @@ -245,13 +251,21 @@ EOF curl -fsSL 'https://apt.pogmom.me/public.gpg' | gpg --dearmor -o "${target_dir}/usr/share/keyrings/pogmom.gpg" 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" + printf "deb [signed-by=/usr/share/keyrings/pogmom.gpg] https://apt.pogmom.me/ unstable main" | tee "${target_dir}/etc/apt/sources.list.d/pogmom.list" run_in_chroot "apt-get update" - echo "America/Los_Angeles" > /target/etc/timezone + printf "America/Los_Angeles" | tee /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-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 "${device_type}" in + user) + install_packages="pogmom-apps" + ;; + kiosk) + install_packages="pogmom-htpc" + ;; + esac + run_in_chroot "DEBIAN_FRONTEND=noninteractive apt-get install -y pogmom-essentials pogmom-utils pogmom-desktop ${install_packages} linux-image-$(dpkg --print-architecture) firmware-linux" + case "$(hostnamectl chassis)" in laptop) chassis_packages="tlp" @@ -265,11 +279,14 @@ EOF # do stuff with the payload #zswap -# echo -e 'ALGO=zstd\nPERCENT=60' | tee -a /target/etc/default/zramswap #zstd is unavailable in kernel 6.12 - echo -e 'ALGO=lzo\nPERCENT=60' | tee -a /target/etc/default/zramswap + if [[ $(cat /sys/block/zram0/comp_algorithm) == *zstd* ]];then + printf 'ALGO=zstd\nPERCENT=60' | tee -a /target/etc/default/zramswap #zstd is unavailable in kernel <6.12.6-1 + else + printf 'ALGO=lzo\nPERCENT=60' | tee -a /target/etc/default/zramswap + fi #hostname - echo "${dest_hostname}" > /target/etc/hostname + printf "%s" "${dest_hostname}" | tee /target/etc/hostname cat > /target/etc/hosts << EOF 127.0.0.1 localhost 127.0.1.1 ${dest_hostname} @@ -277,14 +294,15 @@ EOF run_in_chroot "timedatectl set-local-rtc 0" run_in_chroot "systemctl disable NetworkManager-wait-online.service" + run_in_chroot "setcap cap_net_raw+ep /bin/ping" + printf "RESUME=none" | tee /target/etc/initramfs-tools/conf.d/resume run_in_chroot "dpkg-reconfigure tzdata locales keyboard-configuration" date > /target/root/install_date - run_in_chroot "echo \"root:${root_pass}\" | chpasswd" - run_in_chroot "useradd -c \"${user_realname}\" -m ${user_name}" - run_in_chroot "echo \"${user_name}:${user_pass}\" | chpasswd" - run_in_chroot "usermod -aG sudo ${user_name}" + run_in_chroot "printf 'root:%s' \"${root_pass}\" | chpasswd" + run_in_chroot "useradd -c \"${user_realname}\" --shell /usr/bin/bash --groups sudo,pipewire,input,audio,video,render --create-home ${user_name}" + run_in_chroot "printf '%s:%s' \"${user_name}\" \"${user_pass}\" | chpasswd" perl -i -pe 's/(GRUB_CMDLINE_LINUX_DEFAULT)="(.*)"/$1="$2 rd.luks.uuid='"${root_luks_uuid}"'"/' /target/etc/default/grub run_in_chroot "update-initramfs -c -k all" run_in_chroot "update-grub && grub-install --root-directory / ${dest_dev}" @@ -294,9 +312,8 @@ EOF 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 + dialog --ok-label 'Continue' --nocancel --stdout \ + --msgbox 'Installation is complete, please remove installation medium and press ENTER to restart or CTRL+C to enter the console.' 0 0 reboot } diff --git a/scripts/lib/helpers b/scripts/lib/helpers index 3b3da03..e771b91 100755 --- a/scripts/lib/helpers +++ b/scripts/lib/helpers @@ -11,7 +11,6 @@ run_in_chroot(){ } validate_pass(){ - #sanitize password too if [[ "${1}" == "${2}" ]];then return 0 else @@ -20,10 +19,18 @@ validate_pass(){ fi } +validate_disk_size(){ + if [[ "${root_gb_free}" -gt "10" ]];then + return 0 + else + error_dialog "Requested installation too large for target device" + 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) + disk_size=$(printf '( %s / 1048576 ) - 1024\n' `lsblk -bno SIZE -d "${dest_dev}"` | bc) if [[ "${disk_size}" -gt "${root_end}" ]];then return 0 else @@ -46,6 +53,6 @@ sanitize_hostname(){ } encrypt_partition(){ - echo -n "${3}" | cryptsetup luksFormat "${1}" - - echo -n "${3}" | cryptsetup luksOpen "${1}" "${2}_crypt" - + printf "%s" "${3}" | cryptsetup luksFormat "${1}" - + printf "%s" "${3}" | cryptsetup luksOpen "${1}" "${2}_crypt" - } diff --git a/scripts/lib/install_types b/scripts/lib/install_types new file mode 100644 index 0000000..8a96e12 --- /dev/null +++ b/scripts/lib/install_types @@ -0,0 +1,17 @@ +#!/bin/bash + +#type_user(){ +# +#} + +#type_common(){ +# +#} + +#type_server(){ +# +#} + +#type_kiosk(){ +# +#} diff --git a/scripts/lib/partition b/scripts/lib/partition index fc77a77..f0a02c0 100755 --- a/scripts/lib/partition +++ b/scripts/lib/partition @@ -12,18 +12,25 @@ automatic_partitioner(){ "${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` + root_gb_free=`printf "( ( %s / 1048576 ) - %s ) / 1024\n" "$( lsblk -bno SIZE -d ${dest_dev} )" "${swap_end}" | bc` - validate_install_size || return 1 + validate_disk_size || return 1 + +# if dialog --yesno "Set up separate home partition?" 0 0;then + default_root_gb=`printf "( %s + 10 ) / 4\n" "${root_gb_free}" | bc` + 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 "${root_gb_free}" "${default_root_gb}" \ + 3>&1 2>&3 3>&-) + 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 +# else + +# fi if [[ ${dest_dev} = *[0-9] ]];then part_sep="p" @@ -36,17 +43,6 @@ automatic_partitioner(){ 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 @@ -60,6 +56,7 @@ automatic_partitioner(){ #home parted "${dest_dev}" mkpart home btrfs "${root_end}MB" 100% --script --fix --align optimal + efi_part_format='0' return 0 } @@ -74,17 +71,29 @@ manual_partitioner(){ 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}" + [[ ! "${target_dev}" == "done" ]] && cfdisk "${target_disk}" +# 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})") + partition_menu=() + for blk_part in $(lsblk -rno PATH,TYPE | grep -v 'disk$\|crypt$' | awk '{ print $1 } '); do + partition_menu+=("$(lsblk -rno PATH --nodeps ${blk_part})") + partition_menu+=("$(lsblk -rno FSTYPE,SIZE --nodeps ${blk_part})") done + efi_part=`dialog --menu 'Select EFI Partition' 20 0 20 "${partition_menu[@]}" 2>&1 >/dev/tty` + efi_part_format=`dialog --title 'Format EFI Partition?' --yesno 'This will likely break dual-booting as existing efi entries will be removed' 20 0 2>&1 >/dev/tty;echo $?` + boot_part=`dialog --menu 'Select Boot Partition' 20 0 20 "${partition_menu[@]}" 2>&1 >/dev/tty` + swap_part=`dialog --menu 'Select Swap Partition' 20 0 20 "${partition_menu[@]}" 2>&1 >/dev/tty` + root_part=`dialog --menu 'Select Root Partition' 20 0 20 "${partition_menu[@]}" 2>&1 >/dev/tty` + home_part=`dialog --menu 'Select Home Partition' 20 0 20 "${partition_menu[@]}" 2>&1 >/dev/tty` + + return 0 } format_partitions(){ #efi partition - mkfs.vfat "${efi_part}" + if [[ "${efi_part_format}" == "0" ]];then + mkfs.vfat "${efi_part}" + fi #boot partition mkfs.btrfs -f "${boot_part}" -L boot #swap partition diff --git a/scripts/setup.sh b/scripts/setup.sh index 3aa6630..d30c813 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,12 +1,15 @@ #!/bin/bash +trap 'echo got SIGINT' INT + SCRIPT_ROOT=`dirname "${0}"` -#if [ -f "${SCRIPT_ROOT}/install_started" ];then -# exit 1 -#else -# touch "${SCRIPT_ROOT}/install_started" -#fi +if [ -f "${SCRIPT_ROOT}/install_started" ];then + printf 'Installation has already been started. If you need to restart it, please reboot and start over.' + exit 1 +else + touch "${SCRIPT_ROOT}/install_started" +fi source ${SCRIPT_ROOT}/lib/functions source ${SCRIPT_ROOT}/lib/partition @@ -16,4 +19,5 @@ prepare_install menu_helper finalize +trap INT exit diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..bc0a849 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +SCRIPT_ROOT=`dirname "${0}"` + +#if [ -f "${SCRIPT_ROOT}/install_started" ];then +# exit 1 +#else +# touch "${SCRIPT_ROOT}/install_started" +#fi + +source ${SCRIPT_ROOT}/lib/functions +source ${SCRIPT_ROOT}/lib/partition +source ${SCRIPT_ROOT}/lib/helpers + +disk_setup + +#manual_partitioner + +#prepare_install +#menu_helper +#finalize + +exit diff --git a/sudo b/sudo new file mode 100644 index 0000000..b9df24a --- /dev/null +++ b/sudo @@ -0,0 +1 @@ +RESUME=none tee /etc/initramfs-tools/conf.d/resume