Update gentoo.sh

This commit is contained in:
verita84 2023-11-14 21:27:11 +00:00
parent ea1b807a13
commit ae8ad442a3

288
gentoo.sh
View File

@ -8,6 +8,7 @@
# 3. The ability to build a custom and deployable image onto any machine
# 4. Easily create a bootable USB drive
# 5. Automatic Partitioning
# 6. Steam/Wine/Lutris Install
#
# INSTRUCTIONS
#
@ -36,15 +37,24 @@ WIRELESS_PASSWORD='123456'
SSID='123456'
WIRELESS_INTERFACE='wlan0'
COMPRESSION='compress=zstd:10'
FLATPAKS+=(io.exodus.Exodus us.zoom.Zoom app/net.lutris.Lutris)
FLATPAKS+=()
SERVICES+=(cronie libvirt smartd cronie avahi-daemon cups grub-btrfsd sddm NetworkManager dev-zram0.swap)
DESKTOP="KDE"
KERNEL="gentoo-kernel-bin"
MAKEOPTS="-j$(cat /proc/cpuinfo | grep -i processor | grep -vi 'model' | wc -l)"
USE_FLAGS="-hardened hwaccel sasl usb usbredir spice vhost-net virtfs vnc -gpm proprietary-codecs screencast systemd x264 pulseaudio firmware nfsv4 caps zeroconf dbus sound-server X -browser-integration desktop-portal minimal -gnome qt5 kde dvd alsa gui -wayland device-mapper efiemu themes truetype btrfs seccomp cgroup-hybrid geoclue -webengine boot browser keeshare network opengl"
DESKTOP_USE_FLAGS="wxwidgets jumbo-build kernel-install hwaccel sasl usb usbredir spice vhost-net virtfs vnc -gpm proprietary-codecs screencast systemd x264 pulseaudio firmware nfsv4 caps zeroconf dbus sound-server X -browser-integration desktop-portal minimal -gnome qt5 kde dvd alsa gui -wayland device-mapper efiemu themes truetype btrfs seccomp cgroup-hybrid geoclue -webengine boot browser keeshare network opengl"
SERVER_USE_FLAGS="-gtk kernel-install -pipewire -bluetooth udev -sound -gtk -ipv6 sasl usb usbredir spice vhost-net virtfs -vnc -wayland -gpm -proprietary-codecs -screencast systemd pulseaudio sound-server -x264 firmware nfsv4 caps zeroconf dbus -X -browser-integration desktop-portal minimal -gnome -qt5 -kde -dvd -alsa -gui device-mapper efiemu themes truetype btrfs seccomp cgroup-hybrid geoclue -webengine boot -browser -keeshare network -opengl"
BASE_PACKAGES=" mail-mta/postfix app-admin/sysstat sys-apps/smartmontools sys-process/cronie net-fs/samba net-fs/nfs-utils net-firewall/iptables dev-python/pip sys-fs/inotify-tools dev-util/sh net-analyzer/nmap x11-apps/xhost app-misc/screen app-portage/gentoolkit sys-fs/dosfstools app-admin/sudo sys-apps/systemd sys-boot/plymouth sys-apps/zram-generator app-eselect/eselect-repository dev-vcs/git sys-boot/refind sys-block/parted sys-boot/grub sys-block/zram-init sys-process/btop net-vpn/wireguard-tools sys-apps/flatpak app-editors/vim app-misc/fastfetch net-misc/yt-dlp app-containers/crun app-containers/podman net-fs/samba sys-fs/btrfs-progs net-print/cups app-emulation/virt-manager app-emulation/qemu app-emulation/libvirt sys-firmware/edk2-ovmf-bin "
DESKTOP_PACKAGES=" kde-apps/kcalc kde-apps/dolphin kde-apps/ark www-client/firefox plasma-meta app-editors/vscodium kde-apps/konsole media-gfx/krita kde-apps/kdegraphics-meta app-admin/keepassxc app-office/calligra net-im/telegram-desktop-bin net-misc/nextcloud-client net-im/neochat x11-misc/sddm media-video/vlc "
USE_FLAGS=""
PACKAGES=""
INSTALL_TYPE="desktop"
TMPFS_SIZE="32G"
BASE_PACKAGES=" kde-apps/kcalc sys-devel/distcc www-client/firefox kde-apps/ark kde-apps/dolphin mail-mta/postfix app-admin/sysstat sys-apps/smartmontools plasma-meta sys-process/cronie net-fs/samba net-fs/nfs-utils net-firewall/iptables dev-python/pip sys-fs/inotify-tools app-editors/vscodium kde-apps/konsole media-gfx/krita dev-util/sh net-analyzer/nmap x11-apps/xhost app-misc/screen net-im/neochat app-portage/gentoolkit sys-fs/dosfstools app-admin/sudo sys-apps/systemd sys-boot/plymouth sys-apps/zram-generator x11-misc/sddm app-eselect/eselect-repository dev-vcs/git sys-boot/refind sys-block/parted sys-boot/grub sys-block/zram-init media-video/vlc app-office/calligra sys-process/btop net-vpn/wireguard-tools sys-apps/flatpak app-editors/vim app-vim/airline app-misc/fastfetch net-misc/yt-dlp net-im/telegram-desktop-bin net-misc/nextcloud-client app-containers/crun app-containers/podman app-office/calligra media-gfx/krita net-fs/samba sys-fs/btrfs-progs kde-apps/kdegraphics-meta app-admin/keepassxc net-print/cups app-emulation/virt-manager app-emulation/qemu app-emulation/libvirt sys-firmware/edk2-ovmf-bin"
CPU_TYPE="znver3"
TAR_EXCLUDES="--exclude=/var/db/repos/* --exclude=/var/lib/systemd/coredump/* --exclude=/var/cache/distfiles --exclude=/var/lib/flatpak --exclude=/opt/stable-diffusion-webui --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 --exclude=/opt/chatgpt "
DISTCC_HOSTS+=(192.168.0.146/2 192.168.0.153/2 192.168.0.148/2 192.168.0.63/2 192.168.0.51/4 192.168.0.80/12)
DISTCC_LISTEN="192.168.0.0/24"
DISTCC_CORES="30"
#Add Masked Packages to the Array
MASKED_PACKAGES+=(media-libs/harfbuzz games-util/game-device-udev-rules dev-lang/python dev-python/pyrate-limiter dev-python/moddb dev-python/pypresence games-util/lutris games-util/steam-launcher app-misc/fastfetch net-im/telegram-desktop-bin dev-libs/yyjson)
partitionDetection() {
#This is used for the installer to do script-based actions
@ -123,7 +133,6 @@ os-restore() {
chown -R $USER:$USER $TARGET/home/$USER
auto_login
rm -f $TARGET/gentoo.sh
unmount
}
systemMounts() {
@ -135,73 +144,86 @@ systemMounts() {
mount -t tmpfs -o size=$TMPFS_SIZE tmpfs $TARGET/var/tmp/portage
}
install() {
partitions
if ! [ -f "$TARGET/bin/bash" ]; then
getInstallFiles
fi
unmaskPackages() {
echo "" >$TARGET/etc/portage/package.accept_keywords
for i in "${MASKED_PACKAGES[@]}"; do
echo "$i ~amd64" >>$TARGET/etc/portage/package.accept_keywords
done
if [ -f "$TARGET/bin/bash" ]; then
systemMounts
cp -f ./gentoo.sh $TARGET/usr/bin/
buildGentoo
auto_login
setup_script "$1"
fi
#unmount
}
getInstallFiles() {
cd /tmp
STAGE3_URL=$(curl https://www.gentoo.org/downloads/ | grep -i stage3-amd64-systemd | head -1 | cut -d '"' -f2-3 | cut -d '"' -f1)
wget "$STAGE3_URL"
STAGE3_FILE="/tmp/$(ls /tmp/stage3-* | head -1 | cut -d '/' -f3)"
if [ -f "$STAGE3_FILE" ]; then
echo "Stage3 already here"
else
wget "$STAGE3_URL"
STAGE3_FILE="/tmp/$(ls /tmp/stage3-* | head -1 | cut -d '/' -f3)"
fi
tar xfv $STAGE3_FILE -C $TARGET/
sed -i 's/-O2/-march=native -O2/i' $TARGET/etc/portage/make.conf
echo "USE=\"$USE_FLAGS\"" >>$TARGET/etc/portage/make.conf
echo "MAKEOPTS=\"$MAKEOPTS\"" >>$TARGET/etc/portage/make.conf
echo 'EMERGE_DEFAULT_OPTS="--jobs 3"' >>$TARGET/etc/portage/make.conf
echo 'ACCEPT_KEYWORDS="~amd64"' >>$TARGET/etc/portage/make.conf
cp -f /etc/resolv.conf $TARGET/etc/
mkdir -p $TARGET/var/tmp/portage
finishInstall() {
unmaskPackages
chroot $TARGET /usr/bin/bash /tmp/packages.sh
}
buildGentoo() {
if [ ! -d "$TARGET/var/db/repos/gentoo/x11-misc" ]; then
chroot $TARGET /usr/bin/emerge --sync
fi
if [ ! -f "$TARGET/usr/bin/gentoo.sh" ]; then
if [ -z "$DISTCC_LISTEN" ]; then
echo
echo "Error: $TARGET/usr/bin/gentoo.sh not found!"
echo
exit 1
echo
echo "[Not Using DistCC]"
echo
else
chroot $TARGET /usr/bin/eselect $(/usr/bin/eselect profile list | grep -i plasma | grep systemd | head -1 | cut -d '[' -f2 | cut -d ']' -f1)
mkdir -p $TARGET/etc/portage/package.license
echo "*/* *" >$TARGET/etc/portage/package.license/license
rm -rf $TARGET/etc/portage/package.accept_keywords
chroot $TARGET /usr/bin/emerge --verbose --update --deep --newuse @world --autounmask-write
chroot $TARGET etc-update -q --automode -5
chroot $TARGET /usr/bin/emerge --verbose --update --deep --newuse @world
locale
if [ "$KERNEL" = "gentoo-kernel-bin" ]; then
chroot $TARGET /usr/bin/emerge =sys-kernel/$(ls $TARGET/var/db/repos/gentoo/sys-kernel/gentoo-kernel-bin/gentoo-kernel-bin-6.* | cut -d '/' -f9 | sed 's/.ebuild//' | head -1) sys-kernel/linux-firmware
else
chroot $TARGET /usr/bin/emerge =sys-kernel/gentoo-sources-$(ls $TARGET/var/db/repos/gentoo/sys-kernel/gentoo-sources/gentoo-sources-6.* | cut -d '-' -f5-6 | grep -vi r | head -1 | sed 's/.ebuild//') sys-kernel/genkernel sys-kernel/linux-firmware
chroot $TARGET eselect kernel set 1
chroot $TARGET genkernel --cachedir=/var/tmp/portage --tmpdir=/var/tmp/portage --install all
fi
chroot $TARGET /usr/bin/emerge $BASE_PACKAGES --autounmask-write
chroot $TARGET etc-update -q --automode -5
chroot $TARGET /usr/bin/emerge $BASE_PACKAGES
echo
echo "[Building DistCC]"
echo
echo
chroot $TARGET /usr/bin/emerge sys-devel/distcc
echo "" >$TARGET/etc/distcc/hosts
for i in "${DISTCC_HOSTS[@]}"; do
echo $i >>$TARGET/etc/distcc/hosts
done
chroot $TARGET /usr/bin/distccd --no-detach --daemon --port 3632 -N 15 --allow $DISTCC_LISTEN &
fi
echo
echo
echo
echo "[Configuring Profiles]"
echo
echo
echo
if [[ $INSTALL_TYPE = *desktop* ]]; then
GENTOO_PROFILE=$(chroot $TARGET /usr/bin/eselect profile list | grep -i plasma | grep systemd | grep -i merged | head -1 | cut -d '[' -f2 | cut -d ']' -f1)
chroot $TARGET /usr/bin/eselect profile set $GENTOO_PROFILE
echo ">=net-dns/$(find $TARGET/var/db/repos/gentoo/net-dns/avahi/ | grep ebuild | tail -1 | cut -d '/' -f9 | sed 's/.ebuild//i') -gtk" >$TARGET/etc/portage/package.use/zz-autounmask
echo ">=x11-misc/$(find $TARGET/var/db/repos/gentoo/x11-misc/appmenu-gtk-module/ | grep ebuild | tail -1 | cut -d '/' -f9 | sed 's/.ebuild//i') wayland" >>$TARGET/etc/portage/package.use/zz-autounmask
else
chroot $TARGET /usr/bin/eselect profile set $(/usr/bin/eselect profile list | grep -Evi 'gnome|plasma' | grep systemd | grep -i merged | head -1 | cut -d '[' -f2 | cut -d ']' -f1)
fi
mkdir -p $TARGET/etc/portage/package.license
echo "*/* *" >$TARGET/etc/portage/package.license/license
rm -rf $TARGET/etc/portage/package.accept_keywords
echo
echo
echo
echo "[Installing Kernel]"
echo
echo
chroot $TARGET /usr/bin/emerge =sys-kernel/$(ls $TARGET/var/db/repos/gentoo/sys-kernel/gentoo-kernel-bin/gentoo-kernel-bin-6.* | cut -d '/' -f9 | sed 's/.ebuild//' | head -1) sys-kernel/linux-firmware
echo
echo
echo
echo "[Building Base System]"
echo
echo
chroot $TARGET /usr/bin/emerge --verbose --update --deep --newuse @world --autounmask-write
chroot $TARGET etc-update -q --automode -5
chroot $TARGET /usr/bin/emerge --verbose --update --deep --newuse @world
locale
echo "/usr/bin/emerge $PACKAGES --autounmask-write" >$TARGET/tmp/packages.sh
echo "/usr/sbin/etc-update -q --automode -5" >>$TARGET/tmp/packages.sh
echo "/usr/bin/emerge $PACKAGES" >>$TARGET/tmp/packages.sh
}
snapshots() {
@ -252,26 +274,12 @@ bootloader() {
echo "GRUB_TIMEOUT=1" >>/etc/default/grub
echo "GRUB_THEME=/boot/grub/themes/starfield/theme.txt" >>/etc/default/grub
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=gentoo
#genkernel --cachedir=/var/tmp/portage --tmpdir=/var/tmp/portage --install all
grub-mkconfig -o /boot/grub/grub.cfg
refind-install
fi
}
function setup_script() {
echo "bash /usr/bin/gentoo.sh bootloader $1 $ROOT_NAME $BTRFS" >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh grub-snapshots' >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh accounts' >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh desktop' >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh btrfs-tweaks' >>$TARGET/setup.sh
chmod +x $TARGET/usr/bin/gentoo.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
@ -308,9 +316,9 @@ desktop() {
installSteam() {
eselect repository enable steam-overlay
emerge --sync steam-overlay
emerge games-util/steam-launcher --autounmask-write
emerge games-util/steam-launcher app-emulation/wine-vanilla games-util/lutris --autounmask-write
etc-update -q --automode -5
emerge games-util/steam-launcher
emerge games-util/steam-launcher app-emulation/wine-vanilla games-util/lutris
}
mounts() {
@ -328,19 +336,6 @@ mounts() {
mkdir $TARGET/home/$USER
}
unmount() {
echo
echo "Unmounting....."
umount $TARGET/proc
umount $TARGET/dev
umount $TARGET/sys
umount $TARGET/boot
umount $TARGET/home
umount -lR $TARGET/*
umount -R $TARGET
umount -R $TARGET
}
locale() {
echo "ln -sf /usr/share/zoneinfo/US/Mountain /etc/localtime" >>$TARGET/setup.sh
echo "hwclock --systohc" >>$TARGET/setup.sh
@ -475,21 +470,107 @@ menu() {
echo
echo "[Welcome to the Poster.place Gentoo Installer System]"
echo
echo "[1] Install"
echo "[2] Backup"
echo "[3] Restore"
echo "[4] Tools and Tweaks"
echo "[5] Initialize Disk"
echo "[1] Setup Chroot Mounts"
echo "[2] Download Gentoo Installation Files"
echo "[3] Install Base System"
echo "[4] Install OS Packages"
echo "[5] Install the bootloader and User Accounts"
echo "[6] Backup"
echo "[7] Restore"
echo "[8] Tools and Tweaks"
echo "[9] Initialize Disk"
echo
read -p 'Your Choice: ' choice
if [[ $choice = 1 ]]; then
clear
echo "[Install OS]"
echo
echo
set-devices
install "$HARD_DISK"
partitions
sleep 5
menu
elif [[ $choice = 2 ]]; then
clear
echo "[Choose Deployment Type]"
echo
echo
read -p 'Desktop or Server : ' -e -i 'desktop' INSTALL_TYPE
if [[ $INSTALL_TYPE = *desktop* ]]; then
USE_FLAGS=$DESKTOP_USE_FLAGS
PACKAGES=$BASE_PACKAGES$DESKTOP_PACKAGES
INSTALL_TYPE="desktop"
else
USE_FLAGS=$SERVER_USE_FLAGS
PACKAGES=$BASE_PACKAGES
INSTALL_TYPE="server"
fi
STAGE3_URL=$(curl https://www.gentoo.org/downloads/ | grep -i stage3-amd64-systemd | head -1 | cut -d '"' -f2-3 | cut -d '"' -f1)
wget -O /tmp/stage3.tar.xz "$STAGE3_URL"
STAGE3_FILE="/tmp/stage3.tar.xz"
if [ -f "$STAGE3_FILE" ]; then
tar xfv $STAGE3_FILE -C $TARGET/
sed -i "s/-O2/-march=$CPU_TYPE -O2/i" $TARGET/etc/portage/make.conf
echo "USE=\"$USE_FLAGS\"" >>$TARGET/etc/portage/make.conf
if [ -z "$DISTCC_LISTEN" ]; then
echo
echo "Not using DistCC"
echo
echo "MAKEOPTS=\"$MAKEOPTS\"" >>$TARGET/etc/portage/make.conf
else
echo
echo "Using DistCC"
echo
MAKEOPTS="-j30 -l$(cat /proc/cpuinfo | grep -i processor | grep -vi 'model' | wc -l)"
echo "MAKEOPTS=\"$MAKEOPTS\"" >>$TARGET/etc/portage/make.conf
echo "FEATURES=\"distcc\"" >>$TARGET/etc/portage/make.conf
fi
echo 'EMERGE_DEFAULT_OPTS="--jobs 3"' >>$TARGET/etc/portage/make.conf
echo 'ACCEPT_KEYWORDS="amd64"' >>$TARGET/etc/portage/make.conf
cp -f /etc/resolv.conf $TARGET/etc/
mkdir -p $TARGET/var/tmp/portage
cp -f gentoo.sh $TARGET/usr/bin/
fi
menu
elif [[ $choice = 3 ]]; then
clear
echo "[Install Base System]"
echo
echo
read -p 'Desktop or Server : ' -e -i 'desktop' INSTALL_TYPE
if [[ $INSTALL_TYPE = *desktop* ]]; then
USE_FLAGS=$DESKTOP_USE_FLAGS
PACKAGES=$BASE_PACKAGES$DESKTOP_PACKAGES
INSTALL_TYPE="desktop"
else
USE_FLAGS=$SERVER_USE_FLAGS
PACKAGES=$BASE_PACKAGES
INSTALL_TYPE="server"
fi
set-devices
systemMounts
buildGentoo
#menu
elif [[ $choice = 4 ]]; then
set-devices
finishInstall "$HARD_DISK"
elif [[ $choice = 5 ]]; then
cp -f gentoo.sh $TARGET/usr/bin/gentoo.sh
if [ ! -f "$TARGET/usr/bin/gentoo.sh" ]; then
echo
echo "Error: $TARGET/usr/bin/gentoo.sh not found!"
echo
exit 1
fi
echo "bash /usr/bin/gentoo.sh bootloader $1 $ROOT_NAME $BTRFS" >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh grub-snapshots' >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh accounts' >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh desktop' >>$TARGET/setup.sh
echo 'bash /usr/bin/gentoo.sh btrfs-tweaks' >>$TARGET/setup.sh
auto_login
chmod +x $TARGET/usr/bin/gentoo.sh
chmod +x $TARGET/setup.sh
chroot $TARGET /setup.sh
rm -f $TARGET/setup.sh
elif [[ $choice = 6 ]]; then
clear
echo "[Backup OS]"
echo
@ -500,7 +581,7 @@ menu() {
else
os-backup "home" "$backup_directory" "$ROOT_NAME"
fi
elif [[ $choice = 3 ]]; then
elif [[ $choice = 7 ]]; then
clear
echo "[Restore from Backup]"
echo
@ -517,9 +598,9 @@ menu() {
else
os-restore "$HARD_DISK" "$backup_name" "home" "$restore_directory" "$BTRFS"
fi
elif [[ $choice = 4 ]]; then
elif [[ $choice = 8 ]]; then
tweaks
elif [[ $choice = 5 ]]; then
elif [[ $choice = 9 ]]; then
clear
echo "[Initialize Disk]"
echo
@ -529,7 +610,6 @@ menu() {
else
menu
fi
}
set-devices() {
@ -544,7 +624,7 @@ set-devices() {
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
read -p 'Disk Device to Use: ' -e -i $(lsblk | grep -i disk | grep -Evi 'zram|swap' | cut -d ' ' -f1 | head -$i | tail -1) device
if [[ ! -z $device ]]; then
i="n"
fi