arch/debian.sh

557 lines
20 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
EFI="/dev/$(lsblk | grep $HARD_DISK | head -2 | tail -1 | cut -c 7-20 | cut -d ' ' -f1)"
BTRFS="/dev/$(lsblk | grep $HARD_DISK | head -4 | tail -1 | cut -c 7-20 | cut -d ' ' -f1)"
BOOT="/dev/$(lsblk | grep $HARD_DISK | head -3 | tail -1 | cut -c 7-20 | cut -d ' ' -f1)"
2023-02-14 16:29:59 -07:00
ROOT_NAME='debian'
ROOT_MAPPER_NAME='root'
2023-02-15 07:06:27 -07:00
BACKUP_DISK='/dev/disk/by-uuid/727916c5-a526-47d8-8351-9a0479463738'
2023-02-14 23:26:33 -07:00
BACKUP_DISK_MAPPER='usb'
2023-02-15 07:06:27 -07:00
BACKUP_DISK_ROOT_NAME='usbdebian'
2023-02-20 13:44:43 -07:00
#BACKUP_DISK_IMAGES='/home/verita84/Nextcloud/backups'
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-02-14 16:29:59 -07:00
FLATPAKS+=(app/net.brinkervii.grapejuice org.kde.kdenlive)
2022-12-07 14:24:20 -07:00
#Packages
2023-02-14 12:10:41 -07:00
PACKAGES=" minidlna libsecret-tools libglu1-mesa preload flatpak powertop blueman acpi neofetch cockpit cockpit-podman packagekit cockpit-packagekit cockpit-pcp cockpit-storaged redis "
BASE_PACKAGES=" 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-02-20 13:45:42 -07:00
SHARED_DESKTOP_APPS=" gnome-screenshot cinnamon lightdm shotwell rhythmbox firefox-esr yt-dlp keepassxc rssguard telegram-desktop gimp evolution nextcloud-desktop handbrake vlc libreoffice "
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)
2022-12-07 14:24:20 -07:00
2023-02-14 16:29:59 -07:00
auto_login() {
2022-12-07 14:24:20 -07:00
sed -i "/#WaylandEnable=false/a AutomaticLoginEnable=True" $TARGET/etc/gdm3/daemon.conf
sed -i "/True/a AutomaticLogin=$USER" $TARGET/etc/gdm3/daemon.conf
2023-02-20 13:44:43 -07:00
sed -i "s/#autologin-user=/autologin-user=$USER/" $TARGET/etc/lightdm/lightdm.conf
sed -i "s/#autologin-user-timeout=0/autologin-user-timeout=0/ " $TARGET/etc/lightdm/lightdm.conf
2022-12-07 14:24:20 -07:00
}
2023-02-14 16:29:59 -07:00
create-os-snapshots() {
echo
echo "[Creating new snapshots.....]"
echo
2023-02-18 21:05:31 -07:00
#mkdir -p $TARGET/\@$BACKUP_DISK_MAPPER/var/backups
2023-02-20 14:31:13 -07:00
time tar cvpzf $BACKUP_DISK_IMAGES/$1.tgz --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=$TARGET/* --exclude=/var/lib/libvirt/* --exclude=/dev/* --exclude=/sys/* --exclude=/home/* --exclude=/var/lib/flatpak --exclude=/var/lib/postgresql --exclude=/var/lib/containers /
2023-02-18 21:05:31 -07:00
chown $USER:$USER $BACKUP_DISK_IMAGES/$1.tgz
2022-12-07 14:24:20 -07:00
}
homeBackup() {
2023-02-14 16:29:59 -07:00
echo
echo "[Copying USER data....]"
echo
2023-02-18 21:05:31 -07:00
rsync --progress -avz --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() {
2022-12-07 14:24:20 -07:00
umount $TARGET
2023-02-14 18:34:11 -07:00
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
2023-02-18 21:05:31 -07:00
2023-02-15 07:06:27 -07:00
if [[ -e "$TARGET/@$BACKUP_DISK_ROOT_NAME/usr/bin/bash" ]]; then
2023-02-14 18:34:11 -07:00
if [ "$2" = "home" ]; then
homeBackup
fi
create-os-snapshots "$1"
else
echo
2023-02-15 07:06:27 -07:00
echo "Aborting Install, $TARGET/@$BACKUP_DISK_ROOT_NAME/usr/bin/bash not found!"
2023-02-14 18:34:11 -07:00
echo
echo
exit 1
fi
2022-12-07 14:24:20 -07:00
2023-02-14 18:34:11 -07:00
else
echo
echo "Aborting Install, /dev/mapper/$BACKUP_DISK_MAPPER not found!"
echo
echo
exit 1
2022-12-09 14:05:22 -07:00
fi
2023-02-14 16:29:59 -07:00
2022-12-07 14:24:20 -07:00
ls $TARGET/
umount $TARGET
2023-02-14 18:34:11 -07:00
cryptsetup close $BACKUP_DISK_MAPPER
2022-12-07 14:24:20 -07:00
}
2023-02-14 12:10:41 -07:00
os-restore() {
2022-12-07 14:24:20 -07:00
partitions
2023-02-14 16:29:59 -07:00
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
2023-02-18 21:05:31 -07:00
tar xfpv $BACKUP_DISK_IMAGES/$2.tgz -C $TARGET/
2022-12-09 14:05:22 -07:00
2022-12-26 10:59:45 -07:00
if [ "$3" = "home" ]; then
2023-02-14 16:29:59 -07:00
rsync -av --progress --delete /home/ $TARGET/home/
2022-12-09 14:05:22 -07:00
fi
2022-12-07 14:24:20 -07:00
fstab
cp -f debian.sh $TARGET/
systemMounts
2023-02-14 19:31:37 -07:00
chmod +x $TARGET/debian.sh
2022-12-07 20:05:53 -07:00
chroot $TARGET /debian.sh bootloader $1
2022-12-07 14:24:20 -07:00
chroot $TARGET /debian.sh btrfs-tweaks
rm -f $TARGET/debian.sh
unmount
}
2023-02-14 16:29:59 -07:00
systemMounts() {
2022-12-10 15:46:40 -07: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-02-09 10:40:38 -07:00
KEYFILE='keyfile.key'
2023-02-14 16:29:59 -07:00
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
2023-02-09 10:40:38 -07:00
done
2023-02-14 16:29:59 -07:00
dd if=/dev/urandom of=/etc/$KEYFILE bs=1024 count=4
2023-02-09 10:40:38 -07:00
chown root:root /etc/$KEYFILE
chmod 0400 /etc/$KEYFILE
2023-02-14 16:29:59 -07:00
echo
echo "Adding new key......"
echo
2023-02-09 10:40:38 -07:00
printf "$DISK_PASSWORD" | cryptsetup luksAddKey ${BTRFS} /etc/$KEYFILE
2023-02-14 16:29:59 -07:00
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() {
2022-12-14 19:54:02 -07: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
2023-02-14 16:29:59 -07:00
apt update
apt install -y codium
2022-12-27 19:33:31 -07:00
}
2023-02-14 16:29:59 -07:00
install-element() {
2022-12-27 19:33:31 -07: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
2023-02-14 16:29:59 -07:00
apt update
apt install -y element-desktop
2022-12-27 19:33:31 -07:00
}
2023-02-14 16:29:59 -07:00
additional-software() {
2023-01-28 13:42:37 -07:00
install-element
2022-12-27 19:33:31 -07:00
install-vscode
2022-12-14 19:54:02 -07:00
}
2023-02-14 16:29:59 -07:00
configure-repository() {
echo 'force-unsafe-io' >$TARGET/etc/dpkg/dpkg.cfg.d/docker-apt-speedup
2023-02-11 19:16:02 -07:00
2023-02-14 16:29:59 -07:00
if [ "$DEBIAN_RELEASE" == "testing" ]; then
2023-02-11 19:16:02 -07:00
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
2023-02-10 14:54:48 -07:00
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
2023-02-20 13:44:43 -07:00
echo "deb https://deb.debian.org/debian $CURRENT_STABLE_NAME-backports main" >>$TARGET/etc/apt/sources.list
2023-02-10 14:54:48 -07:00
chroot $TARGET /usr/bin/apt update
2023-02-11 19:16:02 -07:00
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt install -y $PACKAGES"
2023-02-10 14:54:48 -07:00
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
2023-02-11 19:16:02 -07:00
2023-02-14 16:29:59 -07:00
echo 'DPkg::Post-Invoke {"/usr/bin/debian.sh snapshot";};' >$TARGET/etc/apt/apt.conf
2023-02-10 14:54:48 -07:00
}
2022-12-07 14:24:20 -07:00
install() {
partitions
2022-12-07 15:43:41 -07:00
sed -i '/^SigLevel/s/^\(.*\)$/#\1\n/' /etc/pacman.conf
2022-12-12 10:29:43 -07:00
sed -i '/#SigLevel/a SigLevel = Never' /etc/pacman.conf
2022-12-07 15:43:41 -07:00
pacman -Sy archlinux-keyring debootstrap --noconfirm
2023-02-14 16:29:59 -07:00
apt update
apt install debootstrap -y
rm -rf /debootstrap
2022-12-09 13:30:36 -07:00
debootstrap --arch amd64 $DEBIAN_RELEASE $TARGET https://deb.debian.org/debian
2022-12-07 14:24:20 -07:00
systemMounts
cp -f /etc/resolv.conf $TARGET/etc/
2023-02-14 16:29:59 -07:00
echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >$TARGET/setup.sh
2023-02-10 14:54:48 -07:00
configure-repository
2023-02-04 21:09:44 -07:00
cp -f debian.tar $TARGET/etc/default/
2022-12-07 14:24:20 -07:00
locale
accounts
auto_login
custom_service_files
services
2022-12-07 20:05:53 -07:00
setup_script "$1"
2023-01-14 21:11:04 -07:00
echo -e "ALGO=zstd\nPERCENT=60" | tee -a $TARGET/etc/default/zramswap
2022-12-07 14:24:20 -07:00
unmount
}
2023-02-14 16:29:59 -07:00
desktop() {
2023-02-18 21:05:31 -07:00
SERVICES+=(pmcd pmie pmlogger pmproxy exim4 cockpit.socket redis-server apparmor nfs-server smbd rpbind rpcbind.socket avahi-daemon bluetooth minidlna openvpn)
2023-02-14 16:29:59 -07:00
for i in "${SERVICES[@]}"; do
systemctl disable --now $i
done
2023-02-07 21:36:19 -07:00
2022-12-14 17:34:13 -07:00
apt -y purge apparmor
2023-02-07 13:33:30 -07:00
apt remove unattended-upgrades chromium chromium-common chromium-sandbox epiphany-browser epiphany-browser-data -y
2023-01-06 18:41:33 -07:00
apt autoremove -y
2022-12-07 14:24:20 -07:00
}
snapshots() {
echo
echo "Creating Snapshots....."
echo
DATE=$(echo $(date +%Y-%m-%d-%H-%M-%S))
btrfs sub snapshot / /.snapshots/root-${DATE}
update-grub
}
remove-snapshots() {
btrfs sub delete /.snapshots/*
rm -f /boot/loader/entries/root-*
}
enter_chroot() {
2023-02-14 16:29:59 -07:00
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
2022-12-07 14:24:20 -07:00
mounts
2023-02-14 16:29:59 -07:00
systemMounts
2022-12-07 14:24:20 -07:00
chroot $TARGET /bin/bash
}
flatpaks() {
2023-02-14 16:29:59 -07:00
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
2022-12-07 14:24:20 -07:00
for i in "${FLATPAKS[@]}"; do
2023-02-14 16:29:59 -07:00
echo $i
2022-12-07 14:24:20 -07:00
flatpak install $i -y
done
}
2023-02-14 16:29:59 -07:00
grub-snapshots() {
2022-12-07 14:24:20 -07:00
cd /opt
git clone https://github.com/Antynea/grub-btrfs.git
cd /opt/grub-btrfs
make
}
2023-02-14 16:29:59 -07:00
kernel-packages() {
/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
}
bootloader() {
2023-02-04 21:09:44 -07:00
rm -rf /boot/grub/themes
2022-12-31 15:49:20 -07:00
mkdir /boot/grub/themes
2023-02-04 21:09:44 -07:00
tar xf /etc/default/debian.tar -C /boot/grub/themes/
2023-02-04 19:13:30 -07:00
plymouth-set-default-theme -R spacefun
2023-02-14 16:29:59 -07:00
echo "$ROOT_MAPPER_NAME UUID=$(/sbin/blkid | grep $BTRFS | cut -d '"' -f2) none luks" >/etc/crypttab
if [ "$AUTO_DECRYPT" == "True" ]; then
2023-02-09 10:40:38 -07:00
decryptBoot
fi
2022-12-07 14:24:20 -07:00
/sbin/update-initramfs -c -k all
2023-02-14 16:29:59 -07:00
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
2023-02-18 21:05:31 -07:00
echo "GRUB_DISABLE_OS_PROBER=false" >>/etc/default/grub
2023-02-14 16:29:59 -07:00
echo "GRUB_THEME=/boot/grub/themes/theme.txt" >>/etc/default/grub
2022-12-10 13:42:48 -07:00
/sbin/grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian
2022-12-07 14:24:20 -07:00
/sbin/update-grub
}
2023-02-14 16:29:59 -07:00
function setup_script() {
2022-12-07 14:24:20 -07:00
cp -f debian.sh $TARGET/usr/bin/
echo 'bash /usr/bin/debian.sh kernel-packages' >>$TARGET/setup.sh
2023-02-14 16:29:59 -07:00
sed -i 's/most/dep/i' $TARGET/etc/initramfs-tools/initramfs.conf
2022-12-07 20:05:53 -07:00
echo "bash /usr/bin/debian.sh bootloader $1" >>$TARGET/setup.sh
2022-12-07 20:14:55 -07:00
echo 'bash /usr/bin/debian.sh grub-snapshots' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh desktop' >>$TARGET/setup.sh
2022-12-14 19:54:02 -07:00
echo 'bash /usr/bin/debian.sh additional-software' >>$TARGET/setup.sh
2022-12-07 20:14:55 -07:00
echo 'bash /usr/bin/debian.sh btrfs-tweaks' >>$TARGET/setup.sh
2023-02-04 21:16:48 -07:00
2022-12-07 14:24:20 -07:00
chmod +x $TARGET/usr/bin/debian.sh
chmod +x $TARGET/setup.sh
chroot $TARGET /setup.sh
rm -f $TARGET/setup.sh
}
btrfs_filesytem() {
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
2023-02-10 14:54:48 -07:00
mount -o $COMPRESSION,subvol=@$ROOT_NAME /dev/mapper/$ROOT_MAPPER_NAME $TARGET
2022-12-07 14:24:20 -07:00
}
mounts() {
echo
echo "Mounting......."
2023-02-10 14:54:48 -07:00
mount /dev/mapper/$ROOT_MAPPER_NAME $TARGET
2022-12-07 14:24:20 -07:00
btrfs_filesytem
mkdir -p $TARGET/boot
mount -t ext4 $BOOT $TARGET/boot
mkdir -p $TARGET/boot/efi
mount $EFI $TARGET/boot/efi
2022-12-08 08:11:29 -07:00
#CONFIGURE DATA DIRS (HOME)
2022-12-07 14:24:20 -07:00
mkdir $TARGET/home
2023-02-10 14:54:48 -07:00
mount -o subvol=@home /dev/mapper/$ROOT_MAPPER_NAME $TARGET/home
2022-12-07 14:24:20 -07:00
}
unmount() {
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
2023-02-14 18:34:11 -07:00
cryptsetup close $ROOT_MAPPER_NAME
2022-12-07 14:24:20 -07:00
}
locale() {
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
}
partitions() {
echo
echo "Setting Up Partitions....."
2023-02-14 16:43:42 -07:00
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
2022-12-07 14:24:20 -07:00
2023-02-14 16:43:42 -07:00
if [[ -e "/dev/mapper/$ROOT_MAPPER_NAME" ]]; then
2023-02-14 16:29:59 -07:00
echo
echo "Formatting $EFI"
echo
echo y | mkfs.vfat $EFI
echo "Formatting $BOOT"
echo y | mkfs.ext4 $BOOT
mounts
fstab
else
echo
2023-02-14 16:43:42 -07:00
echo "Aborting Install, /dev/mapper/$ROOT_MAPPER_NAME not found!"
2023-02-14 16:29:59 -07:00
echo
echo
exit 1
fi
2022-12-07 14:24:20 -07:00
}
fstab() {
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
2023-02-10 14:54:48 -07:00
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
2022-12-07 14:24:20 -07:00
echo "tmpfs /var/log tmpfs defaults 0 0" >>$TARGET/etc/fstab
2022-12-19 13:53:47 -07:00
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
2022-12-27 14:01:56 -07:00
echo "tmpfs /home/${USER}/Downloads tmpfs rw,user,exec 0 0" >>$TARGET/etc/fstab
2023-02-10 14:54:48 -07:00
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() {
echo
echo "Set Password for $USER"
echo "useradd -m -s /bin/bash $USER" >>$TARGET/setup.sh
echo "echo \"$USER:$USER_PASSWORD\"| chpasswd " >>$TARGET/setup.sh
echo "gpasswd -a $USER wheel" >>$TARGET/setup.sh
echo "gpasswd -a $USER network" >>$TARGET/setup.sh
echo "gpasswd -a $USER video" >>$TARGET/setup.sh
echo "gpasswd -a $USER libvirt" >>$TARGET/setup.sh
2022-12-08 06:53:25 -07:00
echo "gpasswd -a $USER netdev" >>$TARGET/setup.sh
2022-12-07 14:24:20 -07:00
echo "$USER ALL=(ALL) ALL" >$TARGET/etc/sudoers
echo "root ALL=(ALL) ALL" >>$TARGET/etc/sudoers
echo
echo "Setting ROOT Password:"
echo "echo \"root:$ROOT_PASSWORD\"| chpasswd " >>$TARGET/setup.sh
2023-02-10 14:54:48 -07:00
echo "/usr/bin/hostnamectl set-hostname $ROOT_NAME" >>$TARGET/setup.sh
2022-12-07 14:24:20 -07:00
}
btrfs-tweaks() {
2023-02-14 16:29:59 -07: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-02-14 16:29:59 -07:00
for i in "${DISABLE_COW[@]}"; do
chattr -R +C $i
done
2022-12-07 14:24:20 -07:00
}
custom_service_files() {
echo "systemctl set-default graphical.target" >>$TARGET/setup.sh
2023-02-14 16:29:59 -07:00
2022-12-07 14:24:20 -07: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
}
services() {
2023-02-14 16:29:59 -07: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-02-18 21:05:31 -07: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/
2023-02-14 16:29:59 -07:00
crontab >crontab
SERVICES+=(minidlna vip containers pmie pmielogger nfs-server.service exim4 cockpit.socket redis-server smbd)
for i in "${SERVICES[@]}"; do
systemctl enable $i
done
2023-02-07 22:43:52 -07:00
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
}
2022-12-07 14:24:20 -07:00
initialize-disk() {
parted /dev/$HARD_DISK mklabel gpt
parted /dev/$HARD_DISK mkpart primary fat32 1MiB 200MiB
2023-02-06 08:26:57 -07:00
parted /dev/$HARD_DISK mkpart primary ext3 200MiB 700MiB
2022-12-07 14:24:20 -07:00
parted /dev/$HARD_DISK set 1 esp on
2023-02-06 08:26:57 -07:00
parted /dev/$HARD_DISK mkpart P2 ext3 700MiB 100%
2022-12-07 14:24:20 -07:00
printf "$DISK_PASSWORD\n$DISK_PASSWORD" | cryptsetup luksFormat ${BTRFS}
2023-02-14 16:29:59 -07:00
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
2022-12-07 14:24:20 -07:00
echo
echo "Formatting....."
2023-02-10 14:59:08 -07:00
echo y | mkfs.btrfs /dev/mapper/$ROOT_MAPPER_NAME --force
2022-12-07 14:24:20 -07:00
}
wifi() {
iwctl --passphrase $WIRELESS_PASSWORD station $WIRELESS_INTERFACE connect $SSID
}
show-help() {
echo
echo "debian.sh arguments:"
echo
2022-12-07 16:15:01 -07:00
echo "./debian.sh install [disk]"
2022-12-09 14:05:22 -07:00
echo "./debian.sh backup [device name] [home]"
2022-12-09 14:06:04 -07:00
echo "./debian.sh restore [disk] [backup name] [home]"
2022-12-07 20:05:53 -07:00
echo "./debian.sh chroot [disk]"
2022-12-07 14:24:20 -07:00
echo "./debian.sh wifi"
2022-12-07 20:14:55 -07:00
echo "./debian.sh bootloader [disk]"
2022-12-07 16:15:01 -07:00
echo "./debian.sh initialize [disk]"
2023-02-18 21:05:31 -07:00
echo "./debian.sh tar [disk]"
2022-12-07 14:24:20 -07:00
echo "./debian.sh snapshot"
echo "./debian.sh reomve-snapshot"
echo "./debian.sh btrfs-tweaks"
echo
}
if [ "$1" = "install" ]; then
2022-12-07 20:05:53 -07:00
install "$2"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "desktop" ]; then
desktop
2023-02-18 21:05:31 -07:00
elif [ "$1" = "tar" ]; then
create-os-snapshots "$2"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "kernel-packages" ]; then
kernel-packages
elif [ "$1" = "upgrade-system" ]; then
upgrade-system
2022-12-14 19:54:02 -07:00
elif [ "$1" = "additional-software" ]; then
additional-software
2022-12-07 14:24:20 -07:00
elif [ "$1" = "chroot" ]; then
enter_chroot
elif [ "$1" = "initialize" ]; then
initialize-disk
elif [ "$1" = "wifi" ]; then
wifi
elif [ "$1" = "flatpaks" ]; then
flatpaks
elif [ "$1" = "bootloader" ]; then
2023-02-14 12:10:41 -07:00
bootloader "$1"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "snapshot" ]; then
snapshots
elif [ "$1" = "backup" ]; then
2023-02-14 12:10:41 -07:00
os-backup "$2" "$3"
2023-02-07 22:43:52 -07:00
elif [ "$1" = "server-config" ]; then
server-config
2022-12-07 14:24:20 -07:00
elif [ "$1" = "grub-snapshots" ]; then
grub-snapshots
elif [ "$1" = "btrfs-tweaks" ]; then
btrfs-tweaks
elif [ "$1" = "restore" ]; then
2023-02-14 12:10:41 -07:00
os-restore "$2" "$3" "$4"
2023-02-07 22:43:52 -07:00
elif [ "$1" = "remove-snapshot" ]; then
remove-snapshots
elif [ "$1" = "help" ]; then
show-help
else
show-help
fi