arch/debian.sh

671 lines
22 KiB
Bash
Raw Normal View History

2022-12-07 14:24:20 -07:00
#!/bin/bash
########################
2022-12-10 19:45:07 -07:00
# What this script is:
#
2023-02-06 10:34:45 -07:00
# An automatic installer for Debian Stable with BTRFS, Snapshots, and Full-disk-encryption
2022-12-10 19:45:07 -07:00
#
2023-02-14 16:29:59 -07:00
# INSTRUCTIONS
2022-12-10 19:45:07 -07:00
#
2022-12-08 08:26:11 -07:00
# For new disk installs, initialize the disk to setup Encryption and partitions:
2022-12-09 09:49:37 -07:00
# ./debian.sh initialize nvme0n1 (DO NOT SPECIFY /dev/ !)
2022-12-08 08:26:11 -07:00
#
2023-02-14 16:29:59 -07:00
# Before running the install, ensure that you have Internet access. If you modify the
2022-12-09 09:49:37 -07:00
# WIRELESS_PASSWORD and SSID in this file, you can connect to the Internet with:
2023-02-14 16:29:59 -07:00
# ./debian.sh wifi
2022-12-09 09:49:37 -07:00
#
2023-02-14 16:29:59 -07:00
# Plesae be sure to change USER,USER_PASSWORD,DISK_PASSWORD, and ROOT_PASSWORD strings in this file
2022-12-08 08:26:11 -07:00
#
# To install/reinstall the OS:
# ./debian.sh install nvme0n1
2023-02-14 16:29:59 -07:00
#
2022-12-08 08:26:11 -07:00
# reboot
########################
2022-12-07 14:24:20 -07:00
#Configure this section
########################
2022-12-07 20:05:53 -07:00
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2022-12-07 22:12:26 -07:00
export DEBIAN_FRONTEND=noninteractive
2022-12-10 15:46:40 -07:00
TARGET='/install'
2022-12-07 16:15:01 -07:00
mkdir $TARGET
2022-12-07 14:24:20 -07:00
######################################
echo
2022-12-07 16:15:01 -07:00
HARD_DISK=$2
2023-03-22 16:14:58 -06:00
EFI="/dev/$(lsblk | grep $HARD_DISK | head -2 | tail -1 | sed 's/├─//' | cut -d ' ' -f1)"
2023-03-25 12:47:08 -06:00
BTRFS="/dev/$(lsblk | grep $HARD_DISK | head -4 | tail -1 | sed 's/└─//' | cut -d ' ' -f1)"
2023-03-22 16:14:58 -06:00
BOOT="/dev/$(lsblk | grep $HARD_DISK | head -3 | tail -1 | sed 's/├─//' | cut -d ' ' -f1)"
2023-02-14 16:29:59 -07:00
ROOT_NAME='debian'
ROOT_MAPPER_NAME='root'
2023-02-21 09:30:17 -07:00
BACKUP_DISK='/dev/disk/by-uuid/da0af184-781f-49f8-bd3f-f3b869a08fcf'
2023-02-14 23:26:33 -07:00
BACKUP_DISK_MAPPER='usb'
2023-02-21 09:30:17 -07:00
BACKUP_DISK_ROOT_NAME='usb'
2023-02-20 17:54:46 -07:00
BACKUP_DISK_IMAGES="$TARGET/@$BACKUP_DISK_ROOT_NAME/var/backups"
2022-12-07 14:24:20 -07:00
######################################
2022-12-09 14:05:22 -07:00
USER="verita84"
2022-12-07 14:24:20 -07:00
USER_PASSWORD="123456"
ROOT_PASSWORD="123456"
2023-02-10 14:54:48 -07:00
WIRELESS_PASSWORD='123456'
2022-12-07 16:15:01 -07:00
SSID='123456'
2022-12-07 14:24:20 -07:00
WIRELESS_INTERFACE='wlan0'
DISK_PASSWORD='123456'
2022-12-10 13:48:49 -07:00
COMPRESSION='compress=zlib:5'
2023-02-03 21:08:53 -07:00
DEBIAN_RELEASE='stable'
2023-02-10 14:54:48 -07:00
CURRENT_STABLE_NAME='bullseye'
2023-02-09 10:40:38 -07:00
AUTO_DECRYPT='True'
2023-04-04 21:24:39 -06:00
FLATPAKS+=(net.sourceforge.chromium-bsu io.jor.mightymike com.eduke32.EDuke32 com.zandronum.Zandronum net.openra.OpenRA)
2022-12-07 14:24:20 -07:00
#Packages
2023-04-04 21:24:39 -06:00
PACKAGES=" nmap minidlna libsecret-tools libglu1-mesa preload flatpak powertop acpi cockpit cockpit-podman packagekit cockpit-packagekit cockpit-pcp cockpit-storaged "
BASE_PACKAGES=" btop shfmt cups apt-transport-https samba samba-common nfs-common nfs-kernel-server linux-cpupower locales zram-tools acpid podman ghostscript cifs-utils ntp vim-airline rsync screen base udev git network-manager efibootmgr linux-headers-amd64 cryptsetup network-manager-openvpn ntp screen docbook-xsl alsa-utils sysstat fuse3 build-essential unzip bash-completion parted dosfstools wget curl "
2023-03-29 19:57:52 -06:00
SHARED_DESKTOP_APPS=" kwin-addons power-profiles-daemon kde-standard konsole dolphin kde-spectacle print-manager digikam yt-dlp keepassxc telegram-desktop krita nextcloud-desktop handbrake calligra "
2023-02-07 13:03:55 -07:00
#Removed for Debian Bullseye. Works on Bookworm
2023-02-20 13:44:43 -07:00
#REMOVED=" aardvark-dns podman-compose podman-toolbox "
2023-02-11 08:05:40 -07:00
VIRTUALIZATION=" virt-manager qemu-system libvirt-daemon-system ovmf cockpit-machines"
2023-02-14 12:10:41 -07:00
PACKAGES=$BASE_PACKAGES$PACKAGES$SHARED_DESKTOP_APPS
#PACKAGES=$BASE_PACKAGES
2023-02-14 16:29:59 -07:00
SERVICES+=(powertop preload)
2023-04-04 21:24:39 -06:00
TAR_EXCLUDES="--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/flatpak --exclude=/var/lib/postgresql --exclude=/var/lib/containers"
2022-12-07 14:24:20 -07:00
2023-02-14 16:29:59 -07:00
auto_login() {
2023-03-27 23:41:15 -06:00
mkdir -p $TARGET/etc/sddm.conf.d
echo "[Autologin]" >$TARGET/etc/sddm.conf.d/autologin
echo "User=$USER" >>$TARGET/etc/sddm.conf.d/autologin
echo "Session=plasma.desktop" >>$TARGET/etc/sddm.conf.d/autologin
echo "Relogin=false" >>$TARGET/etc/sddm.conf.d/autologin
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
create-os-snapshots() {
2023-03-27 23:41:15 -06:00
echo
if [ -z "${2}" ]; then
mkdir $BACKUP_DISK_IMAGES
echo "[Creating new OS snapshot to $BACKUP_DISK_IMAGES/$1.tgz]"
echo
echo
2023-03-28 18:04:33 -06:00
time tar cpzf $BACKUP_DISK_IMAGES/$1.tgz $TAR_EXCLUDES /
2023-03-27 23:41:15 -06:00
chown $USER:$USER $BACKUP_DISK_IMAGES/$1.tgz
else
echo "[Creating new OS snapshot to $2/$1.tgz]"
echo
echo
2023-03-28 18:04:33 -06:00
time tar cpzf $2/$1.tgz --exclude=/snapshots $TAR_EXCLUDES /
2023-03-27 23:41:15 -06:00
chown $USER:$USER $2/$1.tgz
fi
2022-12-07 14:24:20 -07:00
}
homeBackup() {
2023-03-27 23:41:15 -06:00
echo
echo "[Copying USER data from /home to $TARGET/@home]"
echo
rsync -a --delete /home/ --exclude=.cache --exclude=.local/share/flatpak --exclude=.local/share/containers $TARGET/\@home/
2022-12-07 14:24:20 -07:00
}
2023-02-14 12:10:41 -07:00
os-backup() {
2023-03-27 23:41:15 -06:00
umount $TARGET
printf "$DISK_PASSWORD" | cryptsetup open $BACKUP_DISK $BACKUP_DISK_MAPPER
if [[ -e "/dev/mapper/$BACKUP_DISK_MAPPER" ]]; then
echo
echo "[Mounting.....]"
echo
mount /dev/mapper/$BACKUP_DISK_MAPPER $TARGET
if [[ -e "$TARGET/@$BACKUP_DISK_ROOT_NAME/usr/bin/bash" ]]; then
if [ "$2" = "home" ]; then
homeBackup
fi
create-os-snapshots "$1"
else
echo
echo "Aborting Install, $TARGET/@$BACKUP_DISK_ROOT_NAME/usr/bin/bash not found!"
echo
echo
exit 1
fi
else
echo
echo "Aborting Install, /dev/mapper/$BACKUP_DISK_MAPPER not found!"
echo
echo
exit 1
fi
ls $TARGET/
umount $TARGET
cryptsetup close $BACKUP_DISK_MAPPER
2022-12-07 14:24:20 -07:00
}
2023-02-14 12:10:41 -07:00
os-restore() {
2023-02-20 17:54:46 -07:00
2023-03-27 23:41:15 -06:00
ROOT_CHECK=$(mount | grep ' / ')
if [[ "$ROOT_CHECK" == *"$BACKUP_DISK_ROOT_NAME"* ]]; then
BACKUP_DISK_IMAGES="/var/backups"
fi
if [ "${4}" ]; then
BACKUP_DISK_IMAGES="${4}"
fi
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
echo "[Restoring OS tarfile from $BACKUP_DISK_IMAGES/$2.tgz]"
echo
tar xfp $BACKUP_DISK_IMAGES/$2.tgz -C $TARGET/
if [ "$3" = "home" ]; then
rsync -a --delete /home/ $TARGET/home/
fi
fstab
cp -f debian.sh $TARGET/
systemMounts
chmod +x $TARGET/debian.sh
chroot $TARGET /debian.sh bootloader $1
chroot $TARGET /debian.sh btrfs-tweaks
chroot $TARGET /debian.sh accounts
chown -R $USER:$USER $TARGET/home/$USER
auto_login
rm -f $TARGET/debian.sh
unmount
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
systemMounts() {
2023-03-27 23:41:15 -06:00
mount -o rbind /dev $TARGET/dev
mount -o rbind /dev/pts $TARGET/dev/pts
mount -o rbind /proc $TARGET/proc
mount -o rbind /sys $TARGET/sys
mount -t efivarfs none $TARGET/sys/firmware/efi/efivars
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
decryptBoot() {
2023-03-27 23:41:15 -06:00
KEYFILE='keyfile.key'
echo
echo "Setting LUKS to use Keyfile for password entry"
echo
echo
echo "Clearing Old Keys"
echo
for i in 1 2 3 4 5 6; do
printf "$DISK_PASSWORD" | cryptsetup luksKillSlot ${BTRFS} $i
done
dd if=/dev/urandom of=/etc/$KEYFILE bs=1024 count=4
chown root:root /etc/$KEYFILE
chmod 0400 /etc/$KEYFILE
echo
echo "Adding new key......"
echo
printf "$DISK_PASSWORD" | cryptsetup luksAddKey ${BTRFS} /etc/$KEYFILE
sed -i "s/none/\/etc\/$KEYFILE/" /etc/crypttab
echo "KEYFILE_PATTERN=\"/etc/*.key\"" >/etc/cryptsetup-initramfs/conf-hook
2023-02-08 20:06:57 -07:00
}
2023-02-14 16:29:59 -07:00
install-vscode() {
2023-03-27 23:41:15 -06:00
wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg | gpg --dearmor | dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg
echo 'deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] https://download.vscodium.com/debs vscodium main' | tee /etc/apt/sources.list.d/vscodium.list
apt update
apt install -y codium
2022-12-27 19:33:31 -07:00
}
2023-03-04 11:55:33 -07:00
install-vivaldi() {
2023-03-27 23:41:15 -06:00
wget -qO- https://repo.vivaldi.com/archive/linux_signing_key.pub | gpg --dearmor | dd of=/usr/share/keyrings/vivaldi-browser.gpg
echo "deb [signed-by=/usr/share/keyrings/vivaldi-browser.gpg arch=$(dpkg --print-architecture)] https://repo.vivaldi.com/archive/deb/ stable main" | dd of=/etc/apt/sources.list.d/vivaldi-archive.list
apt update && apt install -y vivaldi-stable
2023-03-04 11:55:33 -07:00
}
install-brave() {
2023-03-27 23:41:15 -06:00
apt install curl -y
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
2023-02-21 16:27:21 -07:00
}
2023-02-14 16:29:59 -07:00
install-element() {
2023-03-27 23:41:15 -06:00
wget -O /usr/share/keyrings/element-io-archive-keyring.gpg https://packages.element.io/debian/element-io-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/element-io-archive-keyring.gpg] https://packages.element.io/debian/ default main" | tee /etc/apt/sources.list.d/element-io.list
apt update
apt install -y element-desktop
2022-12-27 19:33:31 -07:00
}
2023-03-25 12:47:08 -06:00
install-tor() {
2023-03-27 23:41:15 -06:00
apt update
apt install -y apt-transport-https privoxy
echo "deb [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $DEBIAN_RELEASE main" >/etc/apt/sources.list.d/tor.list
echo "deb-src [signed-by=/usr/share/keyrings/tor-archive-keyring.gpg] https://deb.torproject.org/torproject.org $DEBIAN_RELEASE main" >>/etc/apt/sources.list.d/tor.list
wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/tor-archive-keyring.gpg >/dev/null
apt update
apt install -y tor deb.torproject.org-keyring
echo "ExitNodes {us}" >>/etc/tor/torrc
echo "forward-socks4a / 0.0.0.0:9050 ." >>/etc/privoxy/config
2023-03-25 12:47:08 -06:00
}
2023-02-14 16:29:59 -07:00
additional-software() {
2023-03-27 23:41:15 -06:00
install-tor
install-vivaldi
#install-brave
install-element
#install-vscode
2022-12-14 19:54:02 -07:00
}
2023-02-14 16:29:59 -07:00
configure-repository() {
2023-03-27 23:41:15 -06:00
echo 'force-unsafe-io' >$TARGET/etc/dpkg/dpkg.cfg.d/docker-apt-speedup
if [ "$DEBIAN_RELEASE" == "testing" ]; then
echo "deb https://deb.debian.org/debian $DEBIAN_RELEASE main contrib non-free non-free-firmware" >$TARGET/etc/apt/sources.list
chroot $TARGET /usr/bin/apt update
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt install -y $PACKAGES"
else
echo "deb https://deb.debian.org/debian $DEBIAN_RELEASE main contrib non-free" >$TARGET/etc/apt/sources.list
echo "deb https://deb.debian.org/debian-security $DEBIAN_RELEASE-security main" >>$TARGET/etc/apt/sources.list
echo "deb https://deb.debian.org/debian $DEBIAN_RELEASE-updates main " >>$TARGET/etc/apt/sources.list
echo "deb https://deb.debian.org/debian $CURRENT_STABLE_NAME-backports main" >>$TARGET/etc/apt/sources.list
chroot $TARGET /usr/bin/apt update
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt install -y $PACKAGES"
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt dist-upgrade -y -t $CURRENT_STABLE_NAME-backports"
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt auto-remove -y"
fi
echo 'DPkg::Post-Invoke {"/usr/bin/debian.sh snapshot";};' >$TARGET/etc/apt/apt.conf
2023-02-10 14:54:48 -07:00
}
2023-04-04 21:24:39 -06:00
make-image() {
umount $TARGET
mount -t tmpfs tmpfs -o size=11G,dev,exec $TARGET
debootstrap --arch amd64 $DEBIAN_RELEASE $TARGET https://deb.debian.org/debian
configure-repository
locale
custom_service_files
services
cp -f debian.sh $TARGET/usr/bin/
cp -f debian.tar $TARGET/etc/default/
echo 'bash /usr/bin/debian.sh kernel-packages' >>$TARGET/setup.sh
echo "bash /usr/bin/debian.sh bootloader $1" >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh grub-snapshots' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh desktop' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh additional-software' >>$TARGET/setup.sh
echo '/usr/bin/apt clean all' >>$TARGET/setup.sh
chmod +x $TARGET/usr/bin/debian.sh
chmod +x $TARGET/setup.sh
chroot $TARGET /setup.sh
rm -f $TARGET/setup.sh
echo -e "ALGO=zstd\nPERCENT=60" | tee -a $TARGET/etc/default/zramswap
cd $TARGET
echo "[Creating new OS image to $1/$ROOT_NAME.tgz]"
time tar cpzf $1/$ROOT_NAME.tgz $TAR_EXCLUDES .
cd $1
umount $TARGET
}
2022-12-07 14:24:20 -07:00
install() {
2023-03-27 23:41:15 -06:00
partitions
sed -i '/^SigLevel/s/^\(.*\)$/#\1\n/' /etc/pacman.conf
sed -i '/#SigLevel/a SigLevel = Never' /etc/pacman.conf
pacman -Sy archlinux-keyring debootstrap --noconfirm
apt update
apt install debootstrap -y
rm -rf /debootstrap
debootstrap --arch amd64 $DEBIAN_RELEASE $TARGET https://deb.debian.org/debian
systemMounts
cp -f /etc/resolv.conf $TARGET/etc/
echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >$TARGET/setup.sh
configure-repository
cp -f debian.tar $TARGET/etc/default/
locale
auto_login
custom_service_files
services
setup_script "$1"
echo -e "ALGO=zstd\nPERCENT=60" | tee -a $TARGET/etc/default/zramswap
unmount
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
desktop() {
2023-04-04 21:24:39 -06:00
SERVICES+=(pmcd pmie pmlogger pmproxy exim4 cockpit.socket apparmor nfs-server smbd rpbind rpcbind.socket avahi-daemon bluetooth minidlna openvpn)
2023-03-27 23:41:15 -06:00
for i in "${SERVICES[@]}"; do
systemctl disable --now $i
done
2023-02-07 21:36:19 -07:00
2023-03-27 23:41:15 -06:00
apt -y purge apparmor
apt remove unattended-upgrades chromium chromium-common chromium-sandbox epiphany-browser epiphany-browser-data -y
apt autoremove -y
2022-12-07 14:24:20 -07:00
}
snapshots() {
2023-03-27 23:41:15 -06:00
echo
echo "Creating Snapshots....."
echo
DATE=$(echo $(date +%Y-%m-%d-%H-%M-%S))
btrfs sub snapshot / /.snapshots/root-${DATE}
update-grub
2022-12-07 14:24:20 -07:00
}
remove-snapshots() {
2023-03-27 23:41:15 -06:00
btrfs sub delete /.snapshots/*
rm -f /boot/loader/entries/root-*
2022-12-07 14:24:20 -07:00
}
enter_chroot() {
2023-03-27 23:41:15 -06:00
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
mounts
systemMounts
chroot $TARGET /bin/bash
2022-12-07 14:24:20 -07:00
}
flatpaks() {
2023-03-27 23:41:15 -06:00
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
for i in "${FLATPAKS[@]}"; do
echo $i
flatpak install $i -y
done
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
grub-snapshots() {
2023-03-27 23:41:15 -06:00
cd /opt
git clone https://github.com/Antynea/grub-btrfs.git
cd /opt/grub-btrfs
make
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
kernel-packages() {
2023-03-27 23:41:15 -06:00
/usr/bin/apt install --reinstall -y linux-image-$(ls /lib/modules/) grub-efi efibootmgr plymouth plymouth-themes btrfs-progs cryptsetup-initramfs linux-image-amd64 linux-headers-amd64 firmware-iwlwifi firmware-linux firmware-linux-nonfree
2022-12-07 14:24:20 -07:00
}
2023-03-26 23:01:14 -06:00
secure-boot() {
2023-03-27 23:41:15 -06:00
if [ -z "$1" ]; then
clear
echo
echo "Error: No Disk specified!"
echo
else
clear
echo
echo "Disabling Automatic Password Decryption for Hard Disk....."
echo
AUTO_DECRYPT='False'
bootloader "$1"
fi
2023-03-26 23:01:14 -06:00
}
2022-12-07 14:24:20 -07:00
bootloader() {
2023-03-27 23:41:15 -06:00
if [ -z "$1" ]; then
echo
echo "Error: No Disk specified!"
echo
else
rm -rf /boot/grub/themes
mkdir /boot/grub/themes
tar xf /etc/default/debian.tar -C /boot/grub/themes/
plymouth-set-default-theme -R spacefun
echo "$ROOT_MAPPER_NAME UUID=$(/sbin/blkid | grep $BTRFS | cut -d '"' -f2) none luks" >/etc/crypttab
if [ "$AUTO_DECRYPT" == "True" ]; then
decryptBoot
fi
/sbin/update-initramfs -c -k all
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash\"" >/etc/default/grub
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} mitigations=-off" >>/etc/default/grub
echo "GRUB_ENABLE_CRYPTODISK=y" >>/etc/default/grub
echo "GRUB_DISABLE_OS_PROBER=false" >>/etc/default/grub
echo "GRUB_THEME=/boot/grub/themes/theme.txt" >>/etc/default/grub
/sbin/grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
/sbin/update-grub
fi
2023-03-26 23:01:14 -06:00
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
function setup_script() {
2023-03-27 23:41:15 -06:00
cp -f debian.sh $TARGET/usr/bin/
echo 'bash /usr/bin/debian.sh kernel-packages' >>$TARGET/setup.sh
#sed -i 's/most/dep/i' $TARGET/etc/initramfs-tools/initramfs.conf
echo "bash /usr/bin/debian.sh bootloader $1" >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh grub-snapshots' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh accounts' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh desktop' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh additional-software' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh btrfs-tweaks' >>$TARGET/setup.sh
chmod +x $TARGET/usr/bin/debian.sh
chmod +x $TARGET/setup.sh
chroot $TARGET /setup.sh
rm -f $TARGET/setup.sh
2022-12-07 14:24:20 -07:00
}
btrfs_filesytem() {
2023-03-27 23:41:15 -06:00
btrfs sub create $TARGET/@$ROOT_NAME
btrfs sub create $TARGET/@.snapshots
btrfs sub create $TARGET/@libvirt
btrfs sub create $TARGET/@home
btrfs sub create $TARGET/@root
btrfs sub create $TARGET/@containers
echo
echo "Binding BTRFS Root"
echo
umount $TARGET
mount -o $COMPRESSION,subvol=@$ROOT_NAME /dev/mapper/$ROOT_MAPPER_NAME $TARGET
2022-12-07 14:24:20 -07:00
}
mounts() {
2023-03-27 23:41:15 -06:00
echo
echo "Mounting......."
mount /dev/mapper/$ROOT_MAPPER_NAME $TARGET
btrfs_filesytem
mkdir -p $TARGET/boot
mount -t ext4 $BOOT $TARGET/boot
mkdir -p $TARGET/boot/efi
mount $EFI $TARGET/boot/efi
#CONFIGURE DATA DIRS (HOME)
mkdir $TARGET/home
mount -o subvol=@home /dev/mapper/$ROOT_MAPPER_NAME $TARGET/home
2022-12-07 14:24:20 -07:00
}
unmount() {
2023-03-27 23:41:15 -06:00
echo
echo "Unmounting....."
umount $TARGET/proc
umount $TARGET/dev
umount $TARGET/sys
umount $TARGET/boot
umount $TARGET/home
umount -R $TARGET/*
umount -R $TARGET
umount -R $TARGET
cryptsetup close $ROOT_MAPPER_NAME
2022-12-07 14:24:20 -07:00
}
locale() {
2023-03-27 23:41:15 -06:00
echo "ln -sf /usr/share/zoneinfo/US/Mountain /etc/localtime" >>$TARGET/setup.sh
echo "hwclock --systohc" >>$TARGET/setup.sh
echo "en_US.UTF-8 UTF-8" >$TARGET/etc/locale.gen
echo "locale-gen" >>$TARGET/setup.sh
2022-12-07 14:24:20 -07:00
}
partitions() {
2023-03-27 23:41:15 -06:00
echo
echo "Setting Up Partitions....."
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
if [[ -e "/dev/mapper/$ROOT_MAPPER_NAME" ]]; then
echo
echo "Formatting $EFI"
echo
echo y | mkfs.vfat $EFI
echo "Formatting $BOOT"
echo y | mkfs.ext4 $BOOT
mounts
fstab
else
echo
echo "Aborting Install, /dev/mapper/$ROOT_MAPPER_NAME not found!"
echo
echo
exit 1
fi
2022-12-07 14:24:20 -07:00
}
fstab() {
2023-03-27 23:41:15 -06:00
mkdir $TARGET/etc
echo "UUID=$(/sbin/blkid | grep ${BOOT} | cut -d '"' -f2) /boot ext4 defaults 0 1" >$TARGET/etc/fstab
echo "UUID=$(/sbin/blkid | grep ${EFI} | cut -d '"' -f4) /boot/efi vfat umask=0077 0 1" >>$TARGET/etc/fstab
echo "/dev/mapper/$ROOT_MAPPER_NAME / btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@$ROOT_NAME 0 1" >>$TARGET/etc/fstab
echo "/dev/mapper/$ROOT_MAPPER_NAME /.snapshots btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@.snapshots 0 1" >>$TARGET/etc/fstab
echo "/dev/mapper/$ROOT_MAPPER_NAME /var/lib/libvirt btrfs noatime,nodiratime,autodefrag,$COMPRESSION,subvol=@libvirt 0 1" >>$TARGET/etc/fstab
echo "tmpfs /var/log tmpfs defaults 0 0" >>$TARGET/etc/fstab
echo "tmpfs /var/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 "/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
2022-12-07 14:24:20 -07:00
}
accounts() {
2023-03-27 23:41:15 -06:00
echo
echo "Set Password for $USER"
useradd -m -s /bin/bash $USER
echo "$USER:$USER_PASSWORD" | chpasswd
gpasswd -a $USER wheel
gpasswd -a $USER network
gpasswd -a $USER video
gpasswd -a $USER libvirt
gpasswd -a $USER netdev
echo "$USER ALL=(ALL) ALL" >/etc/sudoers
echo "root ALL=(ALL) ALL" >>/etc/sudoers
echo
echo "Setting ROOT Password:"
echo "root:$ROOT_PASSWORD" | chpasswd
/usr/bin/hostnamectl set-hostname $ROOT_NAME
2022-12-07 14:24:20 -07:00
}
btrfs-tweaks() {
2023-03-27 23:41:15 -06:00
DISABLE_COW=("/var/lib/docker" "/var/lib/containers" "/volumes" "/var/lib/mysql" "/var/lib/libvirt")
2022-12-07 14:24:20 -07:00
2023-03-27 23:41:15 -06:00
for i in "${DISABLE_COW[@]}"; do
chattr -R +C $i
done
2022-12-07 14:24:20 -07:00
}
custom_service_files() {
2023-03-27 23:41:15 -06:00
echo "systemctl set-default graphical.target" >>$TARGET/setup.sh
2023-02-14 16:29:59 -07:00
2023-03-27 23:41:15 -06:00
echo "[Unit]" >$TARGET/etc/systemd/system/powertop.service
echo "Description=Powertop tunings" >>$TARGET/etc/systemd/system/powertop.service
echo "[Service]" >>$TARGET/etc/systemd/system/powertop.service
echo "Type=oneshot" >>$TARGET/etc/systemd/system/powertop.service
echo "ExecStart=/usr/sbin/powertop --auto-tune" >>$TARGET/etc/systemd/system/powertop.service
echo "[Install]" >>$TARGET/etc/systemd/system/powertop.service
echo "WantedBy=multi-user.target" >>$TARGET/etc/systemd/system/powertop.service
2022-12-07 14:24:20 -07:00
}
services() {
2023-03-27 23:41:15 -06:00
for i in "${SERVICES[@]}"; do
echo "systemctl enable $i" >>$TARGET/setup.sh
done
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
server-config() {
2023-03-27 23:41:15 -06:00
cp -f etc/smb.conf /etc/samba/
cp- f etc/minidlna.conf /etc/
cp -f etc/99-sysctl.conf /etc/sysctl.d/
cp -f systemd/*.service /etc/systemd/system/
cp -f etc/exports /etc/
crontab >crontab
2023-04-04 21:24:39 -06:00
SERVICES+=(minidlna vip containers pmie pmielogger nfs-server.service exim4 cockpit.socket smbd)
2023-03-27 23:41:15 -06:00
for i in "${SERVICES[@]}"; do
systemctl enable $i
done
systemctl mask apparmor
systemctl disable --now exim4
systemctl mask exim4
rm -f /etc/systemd/system/default.target
ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
systemctl isolate multi-user.target
apt autoremove -y
2023-02-07 22:43:52 -07:00
}
2022-12-07 14:24:20 -07:00
initialize-disk() {
2023-03-27 23:41:15 -06:00
parted /dev/$HARD_DISK mklabel gpt
parted /dev/$HARD_DISK mkpart primary fat32 1MiB 200MiB
parted /dev/$HARD_DISK mkpart primary ext3 200MiB 700MiB
parted /dev/$HARD_DISK set 1 esp on
parted /dev/$HARD_DISK mkpart P2 ext3 700MiB 100%
printf "$DISK_PASSWORD\n$DISK_PASSWORD" | cryptsetup luksFormat ${BTRFS}
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
echo
echo "Formatting....."
echo y | mkfs.btrfs /dev/mapper/$ROOT_MAPPER_NAME --force
2022-12-07 14:24:20 -07:00
}
wifi() {
2023-03-27 23:41:15 -06:00
iwctl --passphrase $WIRELESS_PASSWORD station $WIRELESS_INTERFACE connect $SSID
2022-12-07 14:24:20 -07:00
}
show-help() {
2023-03-27 23:41:15 -06:00
echo
echo "debian.sh arguments:"
echo
echo "./debian.sh install [disk]"
echo "./debian.sh backup [device name] [home]"
echo "./debian.sh restore [disk] [backup name] [home] [tar dir]"
echo "./debian.sh secure-boot [disk]"
echo "./debian.sh chroot [disk]"
echo "./debian.sh wifi"
echo "./debian.sh bootloader [disk]"
echo "./debian.sh initialize [disk]"
echo "./debian.sh tar [device name] [location]"
echo "./debian.sh snapshot"
echo "./debian.sh reomve-snapshot"
echo "./debian.sh btrfs-tweaks"
echo
2022-12-07 14:24:20 -07:00
}
if [ "$1" = "install" ]; then
2023-03-27 23:41:15 -06:00
install "$2"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "desktop" ]; then
2023-04-04 21:24:39 -06:00
desktop
2023-02-18 21:05:31 -07:00
elif [ "$1" = "tar" ]; then
2023-03-27 23:41:15 -06:00
create-os-snapshots "$2" "$3"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "kernel-packages" ]; then
2023-03-27 23:41:15 -06:00
kernel-packages
2022-12-07 14:24:20 -07:00
elif [ "$1" = "upgrade-system" ]; then
2023-03-27 23:41:15 -06:00
upgrade-system
2022-12-14 19:54:02 -07:00
elif [ "$1" = "additional-software" ]; then
2023-03-27 23:41:15 -06:00
additional-software
2022-12-07 14:24:20 -07:00
elif [ "$1" = "chroot" ]; then
2023-03-27 23:41:15 -06:00
enter_chroot
2022-12-07 14:24:20 -07:00
elif [ "$1" = "initialize" ]; then
2023-03-27 23:41:15 -06:00
initialize-disk
2022-12-07 14:24:20 -07:00
elif [ "$1" = "wifi" ]; then
2023-03-27 23:41:15 -06:00
wifi
2023-03-25 12:47:08 -06:00
elif [ "$1" = "accounts" ]; then
2023-03-27 23:41:15 -06:00
accounts
2022-12-07 14:24:20 -07:00
elif [ "$1" = "flatpaks" ]; then
2023-03-27 23:41:15 -06:00
flatpaks
2022-12-07 14:24:20 -07:00
elif [ "$1" = "bootloader" ]; then
2023-03-27 23:41:15 -06:00
bootloader "$2"
2023-04-04 21:24:39 -06:00
elif [ "$1" = "make-image" ]; then
make-image "$2"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "snapshot" ]; then
2023-03-27 23:41:15 -06:00
snapshots
2023-03-26 23:01:14 -06:00
elif [ "$1" = "secure-boot" ]; then
2023-03-27 23:41:15 -06:00
secure-boot "$2"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "backup" ]; then
2023-03-27 23:41:15 -06:00
os-backup "$2" "$3"
2023-02-07 22:43:52 -07:00
elif [ "$1" = "server-config" ]; then
2023-03-27 23:41:15 -06:00
server-config
2022-12-07 14:24:20 -07:00
elif [ "$1" = "grub-snapshots" ]; then
2023-03-27 23:41:15 -06:00
grub-snapshots
2022-12-07 14:24:20 -07:00
elif [ "$1" = "btrfs-tweaks" ]; then
2023-03-27 23:41:15 -06:00
btrfs-tweaks
2022-12-07 14:24:20 -07:00
elif [ "$1" = "restore" ]; then
2023-03-27 23:41:15 -06:00
os-restore "$2" "$3" "$4" "$5"
2023-02-07 22:43:52 -07:00
elif [ "$1" = "remove-snapshot" ]; then
2023-03-27 23:41:15 -06:00
remove-snapshots
2023-02-07 22:43:52 -07:00
elif [ "$1" = "help" ]; then
2023-03-27 23:41:15 -06:00
show-help
2023-02-07 22:43:52 -07:00
else
2023-03-27 23:41:15 -06:00
show-help
2023-02-07 22:43:52 -07:00
fi