This commit is contained in:
Your Name 2024-07-24 20:37:00 -06:00
parent 3b8e49ff4e
commit 320e280ac6

287
debian.sh
View File

@ -6,11 +6,12 @@
# 1. BTRFS with Grub Snapshots
# 2. Full-disk-encryption
# 3. Hibernation
# 4. GNOME, CINNAMON, XFCE, or KDE Desktop
# 4. GNOME or KDE Desktop
# 5. The ability to build a custom and deployable image onto any machine
# 6. Easily create a bootable USB drive
# 7. Automatic Partitioning
# 8. Bypass entering encrypted disk password at boot time if desired
# 9. Copy Live OS to another Disk to boot.
#
# INSTRUCTIONS
#
@ -28,6 +29,7 @@
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export DEBIAN_FRONTEND=noninteractive
TARGET='/install'
SCRIPT=$(pwd)
mkdir $TARGET
######################################
echo
@ -46,15 +48,14 @@ FLATPAKS+=(io.exodus.Exodus us.zoom.Zoom)
DESKTOP="GNOME"
BROWSER="librewolf"
#Packages
BASE_PACKAGES=" syncthing tor firmware-realtek screenfetch linux-image-amd64 grub-efi efibootmgr plymouth plymouth-themes duperemove btrfs-compsize btrfs-progs cryptsetup-initramfs linux-headers-amd64 firmware-iwlwifi firmware-linux firmware-linux-nonfree packagekit cockpit-packagekit cockpit-storaged shfmt aardvark-dns power-profiles-daemon iptables-persistent resolvconf wireguard wireguard-tools nmap libsecret-tools libglu1-mesa preload powertop acpi btop inotify-tools debootstrap cups apt-transport-https samba samba-common nfs-common nfs-kernel-server linux-cpupower locales zram-tools acpid ghostscript cifs-utils ntp vim-airline rsync screen base udev git network-manager cryptsetup network-manager-openvpn ntp screen docbook-xsl alsa-utils sysstat fuse3 build-essential unzip bash-completion parted dosfstools wget curl "
BASE_PACKAGES=" syncthing tor firmware-realtek screenfetch linux-image-amd64 grub-efi efibootmgr plymouth plymouth-themes duperemove btrfs-compsize btrfs-progs cryptsetup-initramfs linux-headers-amd64 firmware-iwlwifi firmware-linux firmware-linux-nonfree packagekit cockpit-packagekit cockpit-storaged shfmt aardvark-dns power-profiles-daemon resolvconf wireguard wireguard-tools nmap libsecret-tools libglu1-mesa preload powertop acpi btop inotify-tools debootstrap cups apt-transport-https samba samba-common nfs-common nfs-kernel-server linux-cpupower locales zram-tools acpid ghostscript cifs-utils ntp vim-airline rsync screen base udev git network-manager cryptsetup network-manager-openvpn ntp screen docbook-xsl alsa-utils sysstat fuse3 build-essential unzip bash-completion parted dosfstools wget curl "
KDE_DESKTOP_ENV=" krita libdbus-glib-1-2 korganizer print-manager kwin-addons kde-standard konsole dolphin kde-spectacle "
XFCE_DESKTOP_ENV=" xfce4 xfce4-goodies xfce4-whiskermenu-plugin xfce4-pulseaudio-plugin slim "
CINNAMON_DESKTOP_ENV=" cinnamon slim gnome-screenshot "
GNOME_DESKTOP_ENV=" gnome-calendar xournalpp gnome-core gdm3 gnome-shell-extension-tiling-assistant gnome-tweaks synaptic "
SHARED_DESKTOP_APPS=" krita obs-studio keepassxc telegram-desktop handbrake vlc yt-dlp "
VIRTUALIZATION=" virt-manager qemu-system libvirt-daemon-system ovmf cockpit-machines"
PACKAGES=""
TAR_EXCLUDES=" --exclude=/media --exclude=/.snapshots --exclude=/snapshots --exclude=/var/backups --exclude=/volumes/* --exclude=/mnt/* --exclude=/var/tmp/* --exclude=/tmp/* --exclude=/raid/* --exclude=/root/* --exclude=/var/cache/apt/archives/* --exclude=/proc/* --exclude=/.snapshots/* --exclude=/var/lib/libvirt/* --exclude=/dev/* --exclude=/sys/* --exclude=/home/* --exclude=/var/lib/postgresql --exclude=/var/lib/containers "
SWAP_CHOICE=""
partitionDetection() {
#This is used for the installer to do script-based actions
@ -105,6 +106,7 @@ create-os-snapshots() {
echo
NEW_TAR_EXCLUDES="$TAR_EXCLUDES --exclude=/minio --exclude=$TARGET/* --exclude=/var/lib/docker "
echo
rm -f $2/$3.tgz
time tar cpzvf $2/$3.tgz $NEW_TAR_EXCLUDES /
chown $USER:$USER $2/$3.tgz
}
@ -118,7 +120,6 @@ homeBackup() {
os-backup() {
umount $TARGET
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
if [[ -e "/dev/mapper/$ROOT_MAPPER_NAME" ]]; then
@ -154,6 +155,37 @@ os-backup() {
cryptsetup close $ROOT_MAPPER_NAME
}
live-os-restore() {
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')"
partitions
clear
echo "[Transferring Currenting Running OS from $LIVE_OS_DM to $HARD_DISK ]"
echo
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')"
mount $LIVE_OS_DM /tmp/live
cd /tmp/live/$LIVE_OS_SUBVOL
rsync -a --delete . $TARGET/
fstab
cp -f $SCRIPT/debian.sh $TARGET/usr/bin/
systemMounts
echo "[Copying Boot Files ]"
echo
rsync -a --delete /boot/ $TARGET/boot/
chmod +x $TARGET/usr/bin/debian.sh
chroot $TARGET /usr/bin/debian.sh bootloader $1 $5 $2
chroot $TARGET /usr/bin/debian.sh btrfs-tweaks
chroot $TARGET /usr/bin/debian.sh accounts
chown -R $USER:$USER $TARGET/home/$USER
auto_login
cd
unmount
}
os-restore() {
partitions
rm -rf $TARGET/usr $TARGET/sbin $TARGET/lib32 $TARGET/libx32 $TARGET/lib $TARGET/vmlinuz* $TARGET/initrd* $TARGET/bin $TARGET/var $TARGET/root $TARGET/opt $TARGET/etc $TARGET/run
@ -324,28 +356,12 @@ desktop() {
done
fi
if [ -f "/usr/bin/slim" ]; then
echo
echo "Performing Cinnamon Bloat Removal"
echo
chmod -x /usr/lib/evolution/evolution-calendar-factory
chmod -x /usr/lib/evolution/evolution-source-registry
chmod -x /usr/lib/evolution/evolution-addressbook-factory
chmod -x /usr/libexec/evolution-data-server/evolution-alarm-notify
mv /usr/lib/evolution-data-server /usr/lib/evolution-data-server-disabled
mv /usr/lib/evolution /usr/lib/evolution-disabled
BLOAT_APPS+=(evolution)
for i in "${BLOAT_APPS[@]}"; do
echo "Removing: $i"
apt remove --purge -y $i
apt autoremove -y
done
fi
installBrowser
installLibreWolf
installCodium
installSteam
hibernate-setup
if [[ $SWAP_CHOICE = *y* ]]; then
hibernate-setup
fi
apt autoremove -y
}
@ -398,11 +414,15 @@ bootloader() {
fi
/sbin/update-initramfs -c -k all
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash mitigations=off\"" >/etc/default/grub
echo "GRUB_CMDLINE_LINUX=resume=UUID=$(/sbin/blkid | grep $SWAP | cut -d '"' -f2) cryptdevice=UUID=$(/sbin/blkid | grep $BTRFS | cut -d '"' -f2):$ROOT_MAPPER_NAME root=UUID=$(/sbin/blkid | grep $ROOT_MAPPER_NAME | cut -d '"' -f4) rootflags=subvol@${ROOT_NAME} " >>/etc/default/grub
if [[ $SWAP_CHOICE = *y* ]]; then
echo "GRUB_CMDLINE_LINUX=resume=UUID=$(/sbin/blkid | grep $SWAP | cut -d '"' -f2) cryptdevice=UUID=$(/sbin/blkid | grep $BTRFS | cut -d '"' -f2):$ROOT_MAPPER_NAME root=UUID=$(/sbin/blkid | grep $ROOT_MAPPER_NAME | cut -d '"' -f4) rootflags=subvol@${ROOT_NAME} " >>/etc/default/grub
else
echo "GRUB_CMDLINE_LINUX=cryptdevice=UUID=$(/sbin/blkid | grep $BTRFS | cut -d '"' -f2):$ROOT_MAPPER_NAME root=UUID=$(/sbin/blkid | grep $ROOT_MAPPER_NAME | cut -d '"' -f4) rootflags=subvol@${ROOT_NAME} " >>/etc/default/grub
fi
echo "GRUB_ENABLE_CRYPTODISK=n" >>/etc/default/grub
echo "GRUB_DISABLE_OS_PROBER=true" >>/etc/default/grub
echo "GRUB_TIMEOUT=1" >>/etc/default/grub
/sbin/grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
/sbin/grub-install --removable --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
/sbin/update-grub
fi
@ -446,14 +466,6 @@ installCodium() {
apt install codium -y
}
installFirefoxNightly() {
wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc >/dev/null
gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); print "\n"$0"\n"}'
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list >/dev/null
apt update
apt install firefox-nightly -y
}
installLibreWolf() {
distro=$(if echo " una bookworm vanessa focal jammy bullseye vera uma " | grep -q " $(lsb_release -sc) "; then lsb_release -sc; else echo focal; fi)
wget -O- https://deb.librewolf.net/keyring.gpg | gpg --dearmor -o /usr/share/keyrings/librewolf.gpg
@ -469,18 +481,6 @@ EOF
apt install -y librewolf
}
installFirefoxESR() {
apt install -y firefox-esr
}
installFirefox() {
wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | tee /etc/apt/keyrings/packages.mozilla.org.asc >/dev/null
gpg -n -q --import --import-options import-show /etc/apt/keyrings/packages.mozilla.org.asc | awk '/pub/{getline; gsub(/^ +| +$/,""); print "\n"$0"\n"}'
echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | tee -a /etc/apt/sources.list.d/mozilla.list >/dev/null
apt update
apt install firefox -y
}
installSteam() {
dpkg --add-architecture i386
apt update
@ -491,54 +491,6 @@ installSteam() {
apt install lutris -y
}
installBrave() {
curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main" | tee /etc/apt/sources.list.d/brave-browser-release.list
apt update
apt install brave-browser -y
apt remove -y firefox-esr
apt autoremove -y
}
installChrome() {
curl -fSsL https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor | tee /usr/share/keyrings/google-chrome.gpg >>/dev/null
echo deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main | tee /etc/apt/sources.list.d/google-chrome.list
apt update
apt install -y google-chrome-stable
}
installVivaldi() {
curl -fsSL https://repo.vivaldi.com/archive/linux_signing_key.pub | gpg --dearmor | tee /usr/share/keyrings/vivaldi.gpg >/dev/null
echo deb [arch=amd64,armhf signed-by=/usr/share/keyrings/vivaldi.gpg] https://repo.vivaldi.com/archive/deb/ stable main | tee /etc/apt/sources.list.d/vivaldi.list
apt update
apt install -y vivaldi-stable
}
installEdge() {
curl -fSsL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /usr/share/keyrings/microsoft-edge.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/microsoft-edge.gpg] https://packages.microsoft.com/repos/edge stable main' | tee /etc/apt/sources.list.d/microsoft-edge.list
apt update -y
apt install microsoft-edge-stable -y
}
installBrowser() {
if [ "$BROWSER" = "brave" ]; then
installBrave
elif [ "$BROWSER" = "librewolf" ]; then
installLibreWolf
elif [ "$BROWSER" = "edge" ]; then
installEdge
elif [ "$BROWSER" = "firefox" ]; then
installFirefox
elif [ "$BROWSER" = "firefox-nightly" ]; then
installFirefoxNightly
elif [ "$BROWSER" = "vivaldi" ]; then
installVivaldi
else
installFirefoxESR
fi
}
mounts() {
echo
echo "Mounting......."
@ -586,7 +538,9 @@ partitions() {
echo y | mkfs.vfat $EFI
echo "Formatting $BOOT"
echo y | mkfs.ext4 $BOOT
mkswap -f $SWAP
if [[ $SWAP_CHOICE = *y* ]]; then
mkswap -f $SWAP
fi
mounts
fstab
else
@ -613,7 +567,9 @@ fstab() {
echo "/dev/mapper/$ROOT_MAPPER_NAME /home btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@home 0 1" >>$TARGET/etc/fstab
echo "/dev/mapper/$ROOT_MAPPER_NAME /root btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@root 0 1" >>$TARGET/etc/fstab
echo "/dev/mapper/$ROOT_MAPPER_NAME /var/lib/containers btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@containers 0 1" >>$TARGET/etc/fstab
echo "$SWAP none swap 0 0" >>$TARGET/etc/fstab
if [[ $SWAP_CHOICE = *y* ]]; then
echo "$SWAP none swap 0 0" >>$TARGET/etc/fstab
fi
}
accounts() {
@ -657,13 +613,60 @@ custom_service_files() {
}
gnome-unmounter() {
umount /media/*/* -R
/sbin/cryptsetup close /dev/mapper/luks-*
}
legacy-efi-resize() {
clear
echo
echo "[Debian Installer - Resize EFI]"
echo
cp -rf /boot /tmp
umount /boot/efi
umount /boot
parted -a optimal /dev/$HARD_DISK rm 1
parted -a optimal /dev/$HARD_DISK rm 2
parted -a optimal /dev/$HARD_DISK mkpart primary fat32 1MiB 10MiB
parted -a optimal /dev/$HARD_DISK mkpart primary ext3 10MiB 700MiB
parted -a optimal /dev/$HARD_DISK set 1 esp on
echo "Formatting $EFI"
echo
echo y | mkfs.vfat $EFI
echo "Formatting $BOOT"
echo y | mkfs.ext4 $BOOT
mount -t ext4 $BOOT /boot
mount $EFI /boot/efi
rsync -av /tmp/boot/ /boot/
partitionDetection
TARGET=/
fstab
echo
echo "Complete. Restart Debian Installer and choose the Menu option to reinstall the bootloader"
echo
}
initialize-disk() {
clear
echo
echo "[Debian Installer - Initialize Device]"
echo
parted /dev/$HARD_DISK mklabel gpt
parted -a optimal /dev/$HARD_DISK mkpart primary fat32 1MiB 200MiB
parted -a optimal /dev/$HARD_DISK mkpart primary ext3 200MiB 700MiB
parted -a optimal /dev/$HARD_DISK mkpart primary ext3 200MiB 1GiB
parted -a optimal /dev/$HARD_DISK set 1 esp on
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 700MiB 98%
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 98% 100%
if [[ $SWAP_CHOICE = *y* ]]; then
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 1GiB 98%
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 98% 100%
else
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 1GiB 100%
fi
partitionDetection
printf "$DISK_PASSWORD\n$DISK_PASSWORD" | cryptsetup luksFormat ${BTRFS}
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
@ -703,6 +706,8 @@ tweaks() {
echo "[2] Create a deployable System Image"
echo "[3] Reinstall Bootloader"
echo "[4] Chroot into existing OS"
echo "[5] *Danger* Resize /boot and /boot/efi [Run on booted OS only!]"
echo "[6] Restore Current Running OS to Another Drive"
echo
read -p 'Your Choice: ' choice
if [[ $choice = 1 ]]; then
@ -727,13 +732,9 @@ tweaks() {
read -p 'Location to Store Image: ' -e -i "/home/$USER" image_directory
read -p 'Image File Name: ' -e -i "debian" ROOT_NAME
read -p 'Debian Version: ' -e -i "stable" DEBIAN_RELEASE
read -p 'KDE, CINNAMON, XFCE, or GNOME: ' -e -i "GNOME" DESKTOP
read -p 'KDE or GNOME: ' -e -i "GNOME" DESKTOP
if [[ $DESKTOP = *KDE* ]]; then
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$KDE_DESKTOP_ENV$VIRTUALIZATION
elif [[ $DESKTOP = *XFCE* ]]; then
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$XFCE_DESKTOP_ENV
elif [[ $DESKTOP = *CINNAMON* ]]; then
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$CINNAMON_DESKTOP_ENV
else
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$GNOME_DESKTOP_ENV$VIRTUALIZATION
fi
@ -746,11 +747,21 @@ tweaks() {
set-devices
partitions
systemMounts
if [[ -e "$TARGET/usr/bin/bash" ]]; then
/usr/sbin/chroot $TARGET /usr/bin/bash
else
echo
echo "error: Bash not found!"
echo
fi
unmount
elif [[ $choice = 5 ]]; then
rm -f /tmp/disk
set-devices
legacy-efi-resize
elif [[ $choice = 6 ]]; then
set-devices
live-os-restore "$HARD_DISK" $ROOT_MAPPER_NAME "none" "none" "$ROOT_NAME"
fi
}
@ -772,13 +783,9 @@ menu() {
echo
echo
read -p 'Debian Version: ' -e -i "stable" DEBIAN_RELEASE
read -p 'KDE, CINNAMON, XFCE, or GNOME: ' -e -i "GNOME" DESKTOP
read -p 'KDE or GNOME: ' -e -i "GNOME" DESKTOP
if [[ $DESKTOP = *KDE* ]]; then
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$KDE_DESKTOP_ENV
elif [[ $DESKTOP = *XFCE* ]]; then
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$XFCE_DESKTOP_ENV
elif [[ $DESKTOP = *CINNAMON* ]]; then
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$CINNAMON_DESKTOP_ENV
else
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$GNOME_DESKTOP_ENV
fi
@ -790,7 +797,7 @@ menu() {
echo
set-devices
read -p 'Backup Home Directory? : ' -e -i 'n' home_backup
read -p 'OS Backup Directory Location : ' -e -i "/mnt" backup_directory
read -p 'OS Backup Directory Location : ' -e -i "/install/@$ROOT_NAME" backup_directory
if [[ $home_backup = *n* ]]; then
os-backup "none" "$backup_directory" "$ROOT_NAME"
else
@ -818,6 +825,7 @@ menu() {
echo "[Initialize Disk]"
echo
echo
rm -f /tmp/disk
set-devices
initialize-disk
else
@ -827,31 +835,44 @@ menu() {
}
set-devices() {
i=0
while [ $i != "n" ]; do
clear
echo
echo "Disks and Partitions:"
echo
cat /proc/partitions
echo
echo "Erase the line and press enter to skip to the next detected disk"
echo
i=$(expr $i + 1)
read -p 'Disk Device to Use: ' -e -i $(lsblk | grep -i disk | grep -Evi 'swap' | cut -d ' ' -f1 | head -$i | tail -1) device
if [[ ! -z $device ]]; then
i="n"
fi
done
if [ -f "/tmp/disk" ]; then
HARD_DISK=$(cat /tmp/disk | head -1)
ROOT_NAME=$(cat /tmp/disk | tail -3 | head -1)
ROOT_MAPPER_NAME=$(cat /tmp/disk | tail -2 | head -1)
SWAP_CHOICE=$(cat /tmp/disk | tail -1 | head -1)
else
i=0
while [ $i != "n" ]; do
clear
echo
echo "Disks and Partitions:"
echo
cat /proc/partitions
echo
echo "Erase the line and press enter to skip to the next detected disk"
echo
i=$(expr $i + 1)
read -p 'Disk Device to Use: ' -e -i $(lsblk | grep -i disk | grep -Evi 'swap' | cut -d ' ' -f1 | head -$i | tail -1) device
if [[ ! -z $device ]]; then
i="n"
fi
done
read -p 'BTRFS Root Volume name: ' -e -i "debian" root_name
read -p 'LUKS Device Mapper Name: ' -e -i "root" device_mapper_name
HARD_DISK=$device
read -p 'BTRFS Root Volume name: ' -e -i "debian" root_name
read -p 'LUKS Device Mapper Name: ' -e -i "root" device_mapper_name
read -p 'Swap Partition for hibernation? (y/n): ' -e -i "y" SWAP_CHOICE
HARD_DISK=$device
echo $HARD_DISK >/tmp/disk
echo $root_name >>/tmp/disk
echo $device_mapper_name >>/tmp/disk
echo $SWAP_CHOICE >>/tmp/disk
set-devices
fi
partitionDetection
ROOT_NAME=$root_name
ROOT_MAPPER_NAME=$device_mapper_name
}
gnome-unmounter
if [ "$1" = "desktop" ]; then
desktop
elif [ "$1" = "tar" ]; then