arch/debian.sh

738 lines
25 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-07-15 21:22:27 -06:00
# An automatic installer for Debian Stable with the following features:
# 1. BTRFS with Grub Snapshots
# 2. Full-disk-encryption
# 3. Hibernation
# 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
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
#
2023-05-07 21:21:17 -06:00
# For new disk installs, initialize the disk to setup Encryption and partitions from the main menu.
2022-12-08 08:26:11 -07:00
#
2023-05-07 21:21:17 -06:00
# Before running the install, ensure that you have Internet access.
2022-12-09 09:49:37 -07:00
#
2023-05-07 21:21:17 -06:00
# Please be sure to change USER,USER_PASSWORD,DISK_PASSWORD, and ROOT_PASSWORD strings in this file
2022-12-08 08:26:11 -07:00
#
2023-05-07 21:21:17 -06:00
# To install a new OS to a disk, run debian.sh and choose option 1 from the main menu
2023-02-14 16:29:59 -07:00
#
2022-12-08 08:26:11 -07:00
########################
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
2023-07-16 13:57:08 -06:00
TARGET='/install'
mkdir $TARGET
2022-12-07 14:24:20 -07:00
######################################
echo
2022-12-07 16:15:01 -07:00
HARD_DISK=$2
2022-12-07 14:24:20 -07:00
######################################
2023-05-07 21:21:17 -06:00
USER="user"
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'
2023-05-08 08:04:15 -06:00
SSID='wifi'
2022-12-07 14:24:20 -07:00
WIRELESS_INTERFACE='wlan0'
2023-07-10 13:17:51 -06:00
DISK_PASSWORD='REM&rap234'
COMPRESSION='compress=none'
2023-02-09 10:40:38 -07:00
AUTO_DECRYPT='True'
2023-07-07 14:44:39 -06:00
FLATPAKS+=(io.exodus.Exodus com.nextcloud.desktopclient.nextcloud com.tutanota.Tutanota)
2022-12-07 14:24:20 -07:00
#Packages
2023-07-07 14:44:39 -06:00
BASE_PACKAGES=" linux-image-amd64 grub-efi efibootmgr plymouth plymouth-themes btrfs-progs cryptsetup-initramfs linux-headers-amd64 firmware-iwlwifi firmware-linux firmware-linux-nonfree podman-compose podman-toolbox cockpit cockpit-podman packagekit cockpit-packagekit cockpit-storaged shfmt aardvark-dns power-profiles-daemon iptables-persistent resolvconf wireguard wireguard-tools nmap libsecret-tools libglu1-mesa preload flatpak powertop acpi btop inotify-tools debootstrap 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 cryptsetup network-manager-openvpn ntp screen docbook-xsl alsa-utils sysstat fuse3 build-essential unzip bash-completion parted dosfstools wget curl "
2023-07-10 13:17:51 -06:00
#DESKTOP_ENV=" calligra print-manager plasma-discover-backend-flatpak kwin-addons kde-standard konsole dolphin kde-spectacle "
2023-07-15 18:18:08 -06:00
DESKTOP_ENV=" gnome gnome-shell-extension-gsconnect gnome-tweaks synaptic gimp "
2023-07-10 13:17:51 -06:00
SHARED_DESKTOP_APPS=" handbrake yt-dlp "
2023-02-11 08:05:40 -07:00
VIRTUALIZATION=" virt-manager qemu-system libvirt-daemon-system ovmf cockpit-machines"
2023-07-10 13:17:51 -06:00
PACKAGES=$BASE_PACKAGES$SHARED_DESKTOP_APPS$DESKTOP_ENV
2023-07-07 14:44: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/postgresql --exclude=/var/lib/containers"
2023-06-30 17:46:50 -06:00
installVPN() {
2023-05-14 21:25:04 -06:00
cd /tmp
2023-07-07 14:44:39 -06:00
rm -f *.deb
2023-05-14 21:25:04 -06:00
wget --content-disposition https://mullvad.net/download/app/deb/latest
apt install -y /tmp/*.deb
systemctl enable --now mullvad-daemon
}
2023-05-07 21:21:17 -06:00
partitionDetection() {
#This is used for the installer to do script-based actions
2023-05-12 07:07:59 -06:00
EFI=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -1 | tail -1)
BOOT=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -2 | tail -1)
BTRFS=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -3 | tail -1)
2023-07-15 18:18:08 -06:00
SWAP=$(blkid | grep $HARD_DISK | sort | cut -d ":" -f1 | head -4 | tail -1)
2023-05-07 21:21:17 -06:00
}
2023-07-15 18:18:08 -06:00
2023-05-07 21:21:17 -06:00
partitionDetection
2023-02-14 16:29:59 -07:00
auto_login() {
2023-07-10 13:17:51 -06:00
if [[ $DESKTOP_ENV == *"plasma"* ]]; then
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
else
2023-07-15 18:18:08 -06:00
sed -i '/daemon/a AutomaticLoginEnable=True' $TARGET/etc/gdm3/daemon.conf
sed -i "/daemon/a AutomaticLogin = $USER" $TARGET/etc/gdm3/daemon.conf
2023-07-10 13:17:51 -06:00
fi
2022-12-07 14:24:20 -07:00
}
2023-07-15 18:18:08 -06:00
hibernate-setup() {
echo "[Sleep]" >/etc/systemd/sleep.conf
echo "AllowSuspend=yes" >>/etc/systemd/sleep.conf
echo "AllowHibernation=yes" >>/etc/systemd/sleep.conf
echo "AllowSuspendThenHibernate=yes" >>/etc/systemd/sleep.conf
echo "HibernateState=disk" >>/etc/systemd/sleep.conf
echo "HibernateMode=shutdown" >>/etc/systemd/sleep.conf
echo "HibernateDelaySec=300" >>/etc/systemd/sleep.conf
echo "HandleLidSwitch=suspend-then-hibernate" >>/etc/systemd/logind.conf
echo "HandleLidSwitchExternalPower=suspend-then-hibernate" >>/etc/systemd/logind.conf
2023-07-16 13:57:08 -06:00
unlink /usr/lib/systemd/system/systemd-suspend.service
rm -f /usr/lib/systemd/system/systemd-suspend.service
ln -s /usr/lib/systemd/system/systemd-suspend-then-hibernate.service /usr/lib/systemd/system/systemd-suspend.service
2023-07-15 18:18:08 -06:00
}
2023-02-14 16:29:59 -07:00
create-os-snapshots() {
2023-03-27 23:41:15 -06:00
echo
2023-05-12 07:07:59 -06:00
mkdir $2
echo "[Creating new OS snapshot to $2/$3.tgz]"
echo
echo
2023-06-30 17:46:50 -06:00
NEW_TAR_EXCLUDES="$TAR_EXCLUDES --exclude=/minio --exclude=$TARGET/*"
2023-05-12 07:07:59 -06:00
echo
time tar cpzf $2/$3.tgz $NEW_TAR_EXCLUDES /
chown $USER:$USER $2/$3.tgz
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
2023-05-07 21:21:17 -06:00
printf "$DISK_PASSWORD" | cryptsetup open ${BTRFS} $ROOT_MAPPER_NAME
2023-03-27 23:41:15 -06:00
2023-05-07 21:21:17 -06:00
if [[ -e "/dev/mapper/$ROOT_MAPPER_NAME" ]]; then
2023-03-27 23:41:15 -06:00
echo
echo "[Mounting.....]"
echo
2023-05-07 21:21:17 -06:00
mount /dev/mapper/$ROOT_MAPPER_NAME $TARGET
2023-03-27 23:41:15 -06:00
2023-05-07 21:21:17 -06:00
if [[ -e "$TARGET/@$ROOT_NAME/usr/bin/bash" ]]; then
if [ "$1" = "home" ]; then
2023-03-27 23:41:15 -06:00
homeBackup
fi
2023-05-07 21:21:17 -06:00
create-os-snapshots "$1" "$2" "$3"
2023-03-27 23:41:15 -06:00
else
echo
2023-05-07 21:21:17 -06:00
echo "Aborting Install, $TARGET/@$ROOT_MAPPER_NAME/usr/bin/bash not found!"
2023-03-27 23:41:15 -06:00
echo
echo
exit 1
fi
else
echo
2023-05-07 21:21:17 -06:00
echo "Aborting Install, /dev/mapper/$ROOT_MAPPER_NAME not found!"
2023-03-27 23:41:15 -06:00
echo
echo
exit 1
fi
ls $TARGET/
umount $TARGET
2023-05-07 21:21:17 -06:00
cryptsetup close $ROOT_MAPPER_NAME
2022-12-07 14:24:20 -07:00
}
2023-02-14 12:10:41 -07:00
os-restore() {
2023-03-27 23:41:15 -06:00
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
2023-05-07 21:21:17 -06:00
clear
echo "[Restoring OS tarfile from $4/$2.tgz]"
2023-03-27 23:41:15 -06:00
echo
2023-05-07 21:21:17 -06:00
tar xfp $4/$2.tgz -C $TARGET/
2023-03-27 23:41:15 -06:00
if [ "$3" = "home" ]; then
2023-05-07 21:21:17 -06:00
echo "[Restoring /home]"
echo
2023-03-27 23:41:15 -06:00
rsync -a --delete /home/ $TARGET/home/
fi
fstab
cp -f debian.sh $TARGET/
systemMounts
chmod +x $TARGET/debian.sh
2023-05-07 21:21:17 -06:00
chroot $TARGET /debian.sh bootloader $1 $2 $5
2023-03-27 23:41:15 -06:00
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-07-10 13:17:51 -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
2023-05-07 21:21:17 -06:00
printf "$DISK_PASSWORD" | cryptsetup luksKillSlot $1 $i
2023-03-27 23:41:15 -06:00
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
2023-05-07 21:21:17 -06:00
printf "$DISK_PASSWORD" | cryptsetup luksAddKey $1 /etc/$KEYFILE
2023-03-27 23:41:15 -06: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
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
2023-07-07 14:44:39 -06:00
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt install -y $PACKAGES "
2023-03-27 23:41:15 -06:00
else
2023-04-10 18:28:07 -06:00
echo "deb https://deb.debian.org/debian $DEBIAN_RELEASE main contrib non-free non-free-firmware" >$TARGET/etc/apt/sources.list
2023-03-27 23:41:15 -06: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-04-10 18:28:07 -06:00
echo "deb https://deb.debian.org/debian $DEBIAN_RELEASE-backports main" >>$TARGET/etc/apt/sources.list
2023-03-27 23:41:15 -06:00
chroot $TARGET /usr/bin/apt update
2023-07-07 14:44:39 -06:00
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt install -y $PACKAGES "
2023-04-10 18:28:07 -06:00
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt dist-upgrade -y -t $DEBIAN_RELEASE-backports"
2023-05-08 22:00:31 -06:00
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt install -y $TROUBLESOME_PACKAGES"
2023-03-27 23:41:15 -06:00
chroot $TARGET /usr/bin/bash -c "export DEBIAN_FRONTEND=noninteractive;/usr/bin/apt auto-remove -y"
fi
2023-05-12 12:34:53 -06:00
#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
2023-07-07 14:44:39 -06:00
mount -t tmpfs tmpfs -o size=15G,dev,exec $TARGET
2023-04-04 21:24:39 -06:00
debootstrap --arch amd64 $DEBIAN_RELEASE $TARGET https://deb.debian.org/debian
configure-repository
locale
custom_service_files
2023-07-07 14:44:39 -06:00
rm -rf $TARGET/var/lib/flatpak
2023-04-04 21:24:39 -06:00
cp -f debian.sh $TARGET/usr/bin/
2023-07-16 14:02:33 -06:00
echo 'bash /usr/bin/debian.sh hibernate' >>$TARGET/setup.sh
2023-05-07 21:21:17 -06:00
echo "bash /usr/bin/debian.sh bootloader $1 $ROOT_NAME $ROOT_MAPPER_NAME" >>$TARGET/setup.sh
2023-04-04 21:24:39 -06:00
echo 'bash /usr/bin/debian.sh grub-snapshots' >>$TARGET/setup.sh
echo 'bash /usr/bin/debian.sh desktop' >>$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]"
2023-07-07 14:44:39 -06:00
time tar cpzf $1/$ROOT_NAME.tgz --exclude=proc/* .
2023-04-04 21:24:39 -06:00
cd $1
2023-07-07 14:44:39 -06:00
du -h $1/$ROOT_NAME.tgz | tail -1
unmount
2023-04-04 21:24:39 -06:00
}
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
locale
auto_login
custom_service_files
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-07-10 13:17:51 -06:00
SERVICES+=(mullvad-daemon pmcd pmie pmlogger pmproxy exim4 cockpit.socket apparmor nfs-server smbd rpbind rpcbind.socket avahi-daemon bluetooth)
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-07-15 18:18:08 -06:00
if [[ $DESKTOP_ENV == *"plasma"* ]]; then
echo
echo "Performing KDE Bloat Removal"
echo
else
echo
echo "Performing GNOME 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+=(iagno aisleriot gnome-mahjongg gnome-software lightsoff zutty gnome-taquin gnome-tetravex simple-scan gnome-text-editor gnome-chess gnome-contacts gnome-clocks unattended-upgrades apparmor gnome-sound-recorder hitori shotwell quadrapassel quadrapassel gnome-sudoku swell-foop gnome-maps transmission-gtk cheese libgnome-games-support-common firefox-esr chromium chromium-common chromium-sandbox epiphany-browser epiphany-browser-data)
for i in "${BLOAT_APPS[@]}"; do
echo "Removing: $i"
apt remove --purge -y $i
apt autoremove -y
done
fi
2023-05-12 07:07:59 -06:00
installBrowser
2023-06-30 17:46:50 -06:00
installElement
2023-07-07 14:44:39 -06:00
installCodium
installVPN
2023-03-27 23:41:15 -06:00
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}
2023-05-02 12:21:18 -06:00
#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
}
flatpaks() {
2023-07-10 13:17:51 -06:00
echo
echo "Installing Flatpaks......"
echo
2023-07-07 14:44:39 -06:00
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
2023-03-27 23:41:15 -06:00
for i in "${FLATPAKS[@]}"; do
echo $i
2023-07-07 14:44:39 -06:00
flatpak install --system $i -y
2023-03-27 23:41:15 -06:00
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
2023-05-02 12:21:18 -06:00
make install
systemctl enable --now grub-btrfsd.service
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
2023-05-07 21:21:17 -06:00
ROOT_MAPPER_NAME="$3"
ROOT_NAME="$2"
2023-05-09 14:55:46 -06:00
plymouth-set-default-theme -r
2023-03-27 23:41:15 -06:00
echo "$ROOT_MAPPER_NAME UUID=$(/sbin/blkid | grep $BTRFS | cut -d '"' -f2) none luks" >/etc/crypttab
if [ "$AUTO_DECRYPT" == "True" ]; then
2023-05-07 21:21:17 -06:00
decryptBoot "${BTRFS}"
2023-03-27 23:41:15 -06:00
fi
/sbin/update-initramfs -c -k all
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash\"" >/etc/default/grub
2023-07-15 18:18:08 -06:00
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} mitigations=-off" >>/etc/default/grub
2023-05-01 13:59:48 -06:00
echo "GRUB_ENABLE_CRYPTODISK=n" >>/etc/default/grub
echo "GRUB_DISABLE_OS_PROBER=true" >>/etc/default/grub
2023-07-15 18:18:08 -06:00
echo "GRUB_TIMEOUT=1" >>/etc/default/grub
2023-03-27 23:41:15 -06:00
/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/
#sed -i 's/most/dep/i' $TARGET/etc/initramfs-tools/initramfs.conf
2023-07-15 18:18:08 -06:00
echo 'bash /usr/bin/debian.sh hibernate' >>$TARGET/setup.sh
2023-05-07 21:21:17 -06:00
echo "bash /usr/bin/debian.sh bootloader $1 $ROOT_NAME $ROOT_MAPPER_NAME" >>$TARGET/setup.sh
2023-03-27 23:41:15 -06:00
echo 'bash /usr/bin/debian.sh grub-snapshots' >>$TARGET/setup.sh
2023-07-10 13:17:51 -06:00
echo 'bash /usr/bin/debian.sh accounts' >>$TARGET/setup.sh
2023-03-27 23:41:15 -06:00
echo 'bash /usr/bin/debian.sh desktop' >>$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
}
2023-07-10 13:17:51 -06:00
installCodium() {
2023-07-07 14:44:39 -06:00
curl -fSsL https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg | gpg --dearmor | tee /usr/share/keyrings/vscodium.gpg >/dev/null
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/vscodium.gpg] https://download.vscodium.com/debs vscodium main" | tee /etc/apt/sources.list.d/vscodium.list
apt update
apt install codium -y
}
installBrowser() {
#Brave
2023-07-10 13:17:51 -06:00
#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
#Vivaldi
2023-07-15 18:18:08 -06:00
#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 | sudo tee /etc/apt/sources.list.d/vivaldi.list
#apt update
#apt install -y vivaldi-stable
#Edge
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
2023-07-07 14:44:39 -06:00
}
installElement() {
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-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
2023-05-07 21:21:17 -06:00
umount -lR $TARGET/*
2023-03-27 23:41:15 -06:00
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
2023-07-15 18:18:08 -06:00
mkswap -f $SWAP
2023-03-27 23:41:15 -06:00
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
2023-04-06 08:15:33 -06:00
echo "tmpfs /var/log tmpfs defaults,dev,exec 0 0" >>$TARGET/etc/fstab
echo "tmpfs /tmp tmpfs defaults 0 0" >>$TARGET/etc/fstab
2023-03-27 23:41:15 -06:00
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
2023-07-15 18:18:08 -06:00
echo "/dev/mapper/$SWAP none swap 0 0" >>$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
2023-04-15 17:01:37 -06:00
gpasswd -a $USER adm
2023-03-27 23:41:15 -06:00
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
}
initialize-disk() {
2023-03-27 23:41:15 -06:00
parted /dev/$HARD_DISK mklabel gpt
2023-05-24 21:28:18 -06:00
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 set 1 esp on
2023-07-15 18:18:08 -06:00
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 700MiB 98%
parted -a optimal /dev/$HARD_DISK mkpart P2 ext3 98% 100%
2023-05-24 21:28:18 -06:00
partitionDetection
2023-03-27 23:41:15 -06:00
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
2023-05-12 07:07:59 -06:00
echo
echo "Initialize Complete. Please reboot your machine to avoid any issues"
echo
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-05-07 21:21:17 -06:00
clear
2023-03-27 23:41:15 -06:00
echo
2023-05-07 21:21:17 -06:00
echo "[debian.sh arguments]"
2023-03-27 23:41:15 -06:00
echo
echo "./debian.sh wifi"
2023-05-07 21:21:17 -06:00
echo "./debian.sh bootloader [disk] [ROOT_NAME] [ROOT_MAPPER_NAME]"
echo "./debian.sh initialize"
2023-03-27 23:41:15 -06:00
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
}
2023-05-07 21:21:17 -06:00
menu() {
clear
echo
echo "[Welcome to Verita84's Debian Installer System]"
echo
echo "[1] Install"
echo "[2] Backup"
echo "[3] Restore"
echo "[4] Create a deployable System Image"
echo "[5] Enable/Disable Disk Password at Boot"
echo "[6] Initialize Disk"
echo
read -p 'Your Choice: ' choice
if [[ $choice = 1 ]]; then
clear
echo "[Install] OS]"
echo
echo
2023-05-08 08:04:15 -06:00
read -p 'Debian Version: ' -e -i "stable" DEBIAN_RELEASE
2023-05-07 21:21:17 -06:00
set-devices
install "$HARD_DISK"
elif [[ $choice = 2 ]]; then
clear
echo "[Backup OS]"
echo
set-devices
read -p 'Backup Home Directory? : ' -e -i 'y' home_backup
read -p 'OS Backup Directory Location : ' -e -i "/install/\@$ROOT_NAME/var/backups" backup_directory
if [[ $home_backup = *n* ]]; then
os-backup "none" "$backup_directory" "$ROOT_NAME"
else
os-backup "home" "$backup_directory" "$ROOT_NAME"
fi
elif [[ $choice = 3 ]]; then
clear
echo "[Restore from Backup]"
echo
echo
set-devices
read -p 'Restore Directory Image Source: ' -e -i "/var/backups" restore_directory
read -p 'Restore Home Directory? : ' -e -i 'n' home_restore
read -p 'Backup file name to restore: ' -e -i 'debian' backup_name
if [[ $home_restore = *n* ]]; then
os-restore "$HARD_DISK" "$backup_name" "none" "$restore_directory" "$ROOT_MAPPER_NAME"
else
os-restore "$HARD_DISK" "$backup_name" "home" "$restore_directory" "$ROOT_MAPPER_NAME"
fi
elif [[ $choice = 4 ]]; then
clear
echo
echo "[Create Debian Image]"
echo
read -p 'Location to Store Image: ' -e -i "/home/$USER" image_directory
read -p 'Image File Name: ' -e -i "debian" ROOT_NAME
2023-05-08 08:04:15 -06:00
read -p 'Debian Version: ' -e -i "stable" DEBIAN_RELEASE
2023-05-07 21:21:17 -06:00
ROOT_MAPPER_NAME="/dev/foo"
make-image "$image_directory"
elif [[ $choice = 5 ]]; then
clear
echo "[Password Protection at Boot]"
echo
echo
set-devices
2023-05-24 19:59:19 -06:00
read -p 'Unlock Disk without password at boot time? ' -e -i "y" pass_change
2023-05-07 21:21:17 -06:00
if [[ $pass_change = *n* ]]; then
2023-05-09 14:55:46 -06:00
AUTO_DECRYPT="False"
2023-05-07 21:21:17 -06:00
bootloader "$HARD_DISK" "$ROOT_NAME" "$ROOT_MAPPER_NAME"
else
2023-05-09 14:55:46 -06:00
AUTO_DECRYPT="True"
bootloader "$HARD_DISK" "$ROOT_NAME" "$ROOT_MAPPER_NAME"
2023-05-07 21:21:17 -06:00
fi
elif [[ $choice = 6 ]]; then
clear
echo "[Initialize Disk]"
echo
echo
set-devices
initialize-disk
else
menu
fi
}
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
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
partitionDetection
ROOT_NAME=$root_name
ROOT_MAPPER_NAME=$device_mapper_name
}
if [ "$1" = "desktop" ]; then
desktop
2023-02-18 21:05:31 -07:00
elif [ "$1" = "tar" ]; then
2023-05-07 21:21:17 -06:00
create-os-snapshots "null" "$3" "$2"
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-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
2023-07-15 18:18:08 -06:00
elif [ "$1" = "hibernate" ]; then
hibernate-setup
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-05-07 21:21:17 -06:00
bootloader "$2" "$3" "$4"
2022-12-07 14:24:20 -07:00
elif [ "$1" = "snapshot" ]; then
2023-03-27 23:41:15 -06:00
snapshots
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
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-05-07 21:21:17 -06:00
menu
2023-02-07 22:43:52 -07:00
fi