diff --git a/gentoo.sh b/gentoo.sh index c60d96b..c4da6c4 100644 --- a/gentoo.sh +++ b/gentoo.sh @@ -36,11 +36,14 @@ USER="verita84" USER_PASSWORD="123456" ROOT_PASSWORD="123456" WIRELESS_PASSWORD='123456' -SSID='123456' -DISK_PASSWORD='123456' -AUTO_DECRYPT='False' +SSID='WIfi' WIRELESS_INTERFACE='wlan0' COMPRESSION='compress=zstd:10' +#Full Disk Encryption Settings +FULL_DISK_ENCRYPTION="True" +AUTO_DECRYPT='False' +DISK_PASSWORD='123456' +############################## FLATPAKS+=() SERVICES+=(cronie libvirtd smartd cronie cups NetworkManager dev-zram0.swap) MAKEOPTS="-j$(cat /proc/cpuinfo | grep -i processor | grep -vi 'model' | wc -l)" @@ -70,8 +73,11 @@ partitionDetection() { EFI=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -1 | tail -1) BTRFS=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -2 | tail -1) SWAP=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -3 | tail -1) - ROOT_MAPPER_NAME="luks-$(/sbin/blkid -s UUID -o value $BTRFS)" - echo $ROOT_MAPPER_NAME + if [[ $FULL_DISK_ENCRYPTION = *True* ]]; then + ROOT_MAPPER_NAME="/dev/mapper/luks-$(/sbin/blkid -s UUID -o value ${BTRFS})" + else + ROOT_MAPPER_NAME="$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -2 | tail -1)" + fi } partitionDetection @@ -84,7 +90,6 @@ torConfig() { echo "AvoidDiskWrites 1" >>/etc/tor/torrc echo "HardwareAccel 1" >>/etc/tor/torrc echo "NumCPUs 4" >>/etc/tor/torrc - chown -R debian-tor:debian-tor /etc/tor } decryptBoot() { @@ -143,13 +148,16 @@ homeBackup() { osBackup() { umount $TARGET - printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME - if [[ -e "/dev/mapper/$ROOT_MAPPER_NAME" ]]; then + if [[ $FULL_DISK_ENCRYPTION = *True* ]]; then + printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME + fi + + if [[ -e "$ROOT_MAPPER_NAME" ]]; then echo echo "[Mounting.....]" echo - mount -o $COMPRESSION /dev/mapper/$ROOT_MAPPER_NAME $TARGET + mount -o $COMPRESSION $ROOT_MAPPER_NAME $TARGET if [[ -e "$TARGET/@$ROOT_NAME/usr/bin/bash" ]]; then if [ "$1" = "home" ]; then @@ -167,7 +175,7 @@ osBackup() { else echo - echo "Aborting Install, /dev/mapper/$ROOT_MAPPER_NAME not found!" + echo "Aborting Install, $ROOT_MAPPER_NAME not found!" echo echo exit 1 @@ -217,14 +225,14 @@ systemMounts() { echo echo "Mounting Boot,EFI,HOME" echo - mount /dev/mapper/$ROOT_MAPPER_NAME $TARGET + mount $ROOT_MAPPER_NAME $TARGET mount $BTRFS $TARGET btrfs_filesytem mkdir -p $TARGET/boot/EFI mount $EFI $TARGET/boot #CONFIGURE DATA DIRS (HOME) mkdir $TARGET/home - mount -o subvol=@home /dev/mapper/$ROOT_MAPPER_NAME $TARGET/home + mount -o subvol=@home $ROOT_MAPPER_NAME $TARGET/home mkdir $TARGET/home/$USER mkdir $TARGET/run @@ -421,8 +429,15 @@ btrfsTweaks() { liveOSrestore() { clear mkdir /tmp/live - LIVE_OS_DM="/dev/mapper/$(mount | grep -i ' / ' | cut -d '/' -f4 | cut -d ' ' -f1)" - LIVE_OS_SUBVOL="@$(mount | grep -i ' / ' | cut -d '@' -f2 | sed 's/)//g')" + INSTALL_TYPE=$(mount | grep ' / ') + if [[ $INSTALL_TYPE = *mapper* ]]; then + LIVE_OS_DM="/dev/mapper/$(mount | grep -i ' / ' | cut -d '/' -f4 | cut -d ' ' -f1)" + LIVE_OS_SUBVOL="@$(mount | grep -i ' / ' | cut -d '@' -f2 | sed 's/)//g')" + else + LIVE_OS_DM="$(mount | grep ' / ' | cut -d ' ' -f1)" + LIVE_OS_SUBVOL="@$(mount | grep -i ' / ' | cut -d '@' -f2 | sed 's/)//g')" + fi + partitions systemMounts clear @@ -430,6 +445,7 @@ liveOSrestore() { echo "[Transferring Currenting Running OS from $LIVE_OS_DM to $HARD_DISK ]" echo mount $LIVE_OS_DM /tmp/live + cd /tmp/live/$LIVE_OS_SUBVOL rsync -a --delete . --exclude=home/* --exclude=.snapshots/* --exclude=sys/* --exclude=dev/* --exclude=proc/* --exclude=run/* $TARGET/ fstab @@ -489,7 +505,8 @@ btrfs_filesytem() { echo "Binding BTRFS Root" echo umount $TARGET - mount -o $COMPRESSION,subvol=@$ROOT_NAME /dev/mapper/$ROOT_MAPPER_NAME $TARGET + echo mount -o $COMPRESSION,subvol=@$ROOT_NAME $ROOT_MAPPER_NAME $TARGET + mount -o $COMPRESSION,subvol=@$ROOT_NAME $ROOT_MAPPER_NAME $TARGET } userTweaks() { @@ -567,19 +584,18 @@ locale() { fstab() { mkdir $TARGET/etc - echo "Debug $ROOT_MAPPER_NAME" echo "UUID=$(/sbin/blkid -s UUID -o value $EFI) /boot vfat defaults,fmask=0077,dmask=0077 0 1" >$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) / btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@$ROOT_NAME 0 1" >>$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) /.snapshots btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@.snapshots 0 1" >>$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) /var/lib/libvirt btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@libvirt 0 1" >>$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) /var/lib/flatpak btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@flatpak 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) / btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@$ROOT_NAME 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) /.snapshots btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@.snapshots 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) /var/lib/libvirt btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@libvirt 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) /var/lib/flatpak btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@flatpak 0 1" >>$TARGET/etc/fstab echo "tmpfs /var/log tmpfs defaults,dev,exec 0 0" >>$TARGET/etc/fstab echo "tmpfs /tmp tmpfs defaults 0 0" >>$TARGET/etc/fstab echo "tmpfs /home/${USER}/.cache tmpfs rw,user,exec 0 0" >>$TARGET/etc/fstab echo "tmpfs /home/${USER}/Downloads tmpfs rw,user,exec 0 0" >>$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) /home btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@home 0 1" >>$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) /root btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@root 0 1" >>$TARGET/etc/fstab - echo "UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/$ROOT_MAPPER_NAME) /var/lib/containers btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@containers 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) /home btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@home 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) /root btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@root 0 1" >>$TARGET/etc/fstab + echo "UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) /var/lib/containers btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@containers 0 1" >>$TARGET/etc/fstab if [[ $SWAP_CHOICE = *y* ]]; then echo "$SWAP none swap 0 0" >>$TARGET/etc/fstab fi @@ -630,11 +646,15 @@ initializeDisk() { parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 2024MiB 100% fi partitionDetection - printf "$DISK_PASSWORD\n$DISK_PASSWORD" | cryptsetup luksFormat ${BTRFS} - printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME + if [[ $FULL_DISK_ENCRYPTION = *True* ]]; then + printf "$DISK_PASSWORD\n$DISK_PASSWORD" | cryptsetup luksFormat ${BTRFS} + printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $(echo $ROOT_MAPPER_NAME | sed 's/\/dev\/mapper\///') + fi + echo echo "Formatting....." - echo y | mkfs.btrfs /dev/mapper/$ROOT_MAPPER_NAME -f + echo "mkfs.btrfs $ROOT_MAPPER_NAME -f" + echo y | mkfs.btrfs $ROOT_MAPPER_NAME -f echo echo "Formatting $EFI" echo @@ -646,6 +666,7 @@ initializeDisk() { echo "Initialize Complete. Please reboot your machine to avoid any issues" echo cryptsetup close $ROOT_MAPPER_NAME + rm -f /tmp/disk } wifi() { @@ -822,6 +843,7 @@ menu() { echo echo setDevices + partitionDetection initializeDisk read -p "Press enter key to Continue" menu @@ -833,13 +855,15 @@ menu() { partitions() { echo echo "Setting Up Partitions....." - echo printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME - printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME - if [[ -e "/dev/mapper/$ROOT_MAPPER_NAME" ]]; then + if [[ $FULL_DISK_ENCRYPTION = *True* ]]; then + printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $(echo $ROOT_MAPPER_NAME | sed 's/\/dev\/mapper\///') + fi + + if [[ -e "$ROOT_MAPPER_NAME" ]]; then fstab else echo - echo "Aborting Install, /dev/mapper/$ROOT_MAPPER_NAME not found!" + echo "Aborting Install, $ROOT_MAPPER_NAME not found!" echo echo exit 1 @@ -851,6 +875,16 @@ setDevices() { HARD_DISK=$(cat /tmp/disk | head -1) ROOT_NAME=$(cat /tmp/disk | tail -3 | head -1) SWAP_CHOICE=$(cat /tmp/disk | tail -1 | head -1) + partitionDetection + echo + echo "Configuration Settings:" + echo + echo "Disk: $HARD_DISK" + echo "Root Name: $ROOT_NAME" + echo "Root Mapper Name: $ROOT_MAPPER_NAME" + echo "Swap Choice: $SWAP_CHOICE" + echo + echo else i=0 while [ $i != "n" ]; do @@ -909,19 +943,25 @@ bootloader() { LOADER_FILE="/boot/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf" PREVIOUS_LOADER_FILE="/boot/loader/entries/previous.conf" clear + KERNEL_COMMAND_LINE="mitigations=off root=UUID=$(/sbin/blkid -s UUID -o value $ROOT_MAPPER_NAME) rootflags=subvol=@$ROOT_NAME rw " + rm -f /etc/crypttab + echo >/etc/dracut.conf - echo 'add_dracutmodules+=" crypt dm rootfs-block "' >/etc/dracut.conf if [[ $SWAP_CHOICE = *y* ]]; then - echo "kernel_cmdline+=\" resume=UUID=$(/sbin/blkid -s UUID -o value ${SWAP}) mitigations=off rd.luks.key=/boot/keyfile.key:UUID=$(/sbin/blkid -s UUID -o value ${EFI}) rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS}) root=UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/${ROOT_MAPPER_NAME}) rootflags=subvol=@$ROOT_NAME rw \"" >>/etc/dracut.conf - else - echo "kernel_cmdline+=\" mitigations=off rd.luks.key=/boot/keyfile.key:UUID=$(/sbin/blkid -s UUID -o value ${EFI}) rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS}) root=UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/${ROOT_MAPPER_NAME}) rootflags=subvol=@$ROOT_NAME rw \"" >>/etc/dracut.conf + KERNEL_COMMAND_LINE="$KERNEL_COMMAND_LINE: resume=UUID=$(/sbin/blkid -s UUID -o value $SWAP) " fi - if [ "$AUTO_DECRYPT" == "True" ]; then - echo "$ROOT_MAPPER_NAME UUID=$(/sbin/blkid -s UUID -o value ${BTRFS}) none" >/etc/crypttab - decryptBoot "${BTRFS}" - else - echo "$ROOT_MAPPER_NAME UUID=$(/sbin/blkid -s UUID -o value ${BTRFS}) none luks" >/etc/crypttab + if [[ $FULL_DISK_ENCRYPTION = *True* ]]; then + KERNEL_COMMAND_LINE="$KERNEL_COMMAND_LINE: rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS})" + echo "add_dracutmodules+=\" crypt dm rootfs-block \"" >/etc/dracut.conf + echo "kernel_cmdline+=\" $KERNEL_COMMAND_LINE \" " >>/etc/dracut.conf + + if [ "$AUTO_DECRYPT" == "True" ]; then + echo "$(echo $ROOT_MAPPER_NAME | sed 's/\/dev\/mapper\///') UUID=$(/sbin/blkid -s UUID -o value ${BTRFS}) none" >/etc/crypttab + decryptBoot "${BTRFS}" + else + echo "$(echo $ROOT_MAPPER_NAME | sed 's/\/dev\/mapper\///') UUID=$(/sbin/blkid -s UUID -o value ${BTRFS}) none luks" >/etc/crypttab + fi fi mkdir -p /boot/$MACHINE_ID/$KERNEL_VERSION @@ -937,31 +977,19 @@ bootloader() { echo "default $MACHINE_ID" >/boot/loader/loader.conf echo "timeout 1" >>/boot/loader/loader.conf - #Generate Previous Boot Entry - echo "title Previous" >$PREVIOUS_LOADER_FILE - echo "version $KERNEL_VERSION" >>$PREVIOUS_LOADER_FILE - - if [[ $SWAP_CHOICE = *y* ]]; then - echo "options resume=UUID=$(/sbin/blkid -s UUID -o value ${SWAP}) mitigations=off rd.luks.key=/boot/keyfile.key:UUID=$(/sbin/blkid -s UUID -o value ${EFI}) rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS}) root=UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/${ROOT_MAPPER_NAME}) rootflags=subvol=@.snapshots/previous rw " >>$PREVIOUS_LOADER_FILE - else - echo "options mitigations=off rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS}) root=UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/${ROOT_MAPPER_NAME}) rootflags=subvol=@previous rw " >>$PREVIOUS_LOADER_FILE - fi - echo "machine-id $MACHINE_ID" >>$PREVIOUS_LOADER_FILE - echo "linux /$KERNEL" >>$PREVIOUS_LOADER_FILE - echo "initrd /$MACHINE_ID/$KERNEL_VERSION/initrd" >>$PREVIOUS_LOADER_FILE - #Generate Main Boot Entry echo "title Current" >$LOADER_FILE echo "version $KERNEL_VERSION" >>$LOADER_FILE - if [[ $SWAP_CHOICE = *y* ]]; then - echo "options resume=UUID=$(/sbin/blkid -s UUID -o value ${SWAP}) mitigations=off rd.luks.key=/boot/keyfile.key:UUID=$(/sbin/blkid -s UUID -o value ${EFI}) rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS}) root=UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/${ROOT_MAPPER_NAME}) rootflags=subvol=@${ROOT_NAME} rw " >>$LOADER_FILE - else - echo "options mitigations=off rd.luks.uuid=$(/sbin/blkid -s UUID -o value ${BTRFS}) rd.luks.key=/boot/keyfile.key:UUID=$(/sbin/blkid -s UUID -o value ${EFI}) root=UUID=$(/sbin/blkid -s UUID -o value /dev/mapper/${ROOT_MAPPER_NAME}) rootflags=subvol=@${ROOT_NAME} rw " >>$LOADER_FILE - fi + echo "options $KERNEL_COMMAND_LINE " >>$LOADER_FILE echo "machine-id $MACHINE_ID" >>$LOADER_FILE echo "linux /$KERNEL" >>$LOADER_FILE echo "initrd /$MACHINE_ID/$KERNEL_VERSION/initrd" >>$LOADER_FILE + + #Generate Previous Boot Entry + cp -f $LOADER_FILE $PREVIOUS_LOADER_FILE + sed -i "s/@${ROOT_NAME}/@previous/" $PREVIOUS_LOADER_FILE bootctl set-default $MACHINE_ID-$KERNEL_VERSION.conf + #bootctl list }