Files
linux-scripts/arch-setup.sh
2025-03-25 13:47:50 +01:00

574 lines
18 KiB
Bash
Executable File

#!/bin/bash
# Function name: Install packages
# Description: Install packages from an array
# Arguments:
# $1: Package list (array)
install_packages() {
local packages=("${!1}")
for package in "${packages[@]}"; do
sudo pacman -S --needed --noconfirm "$package"
done
}
# Function name: Install package
# Description: Install a package
# Arguments:
# $1: Package name
install_package() {
sudo pacman -S --needed --noconfirm "$1"
}
# Function name: Install dependencies
# Description: Install dependencies
# Arguments:
# $1: Package name
install_dependencies() {
sudo pacman -S --needed --noconfirm --asdeps "$1"
}
# Function name: Check whiptail
# Description: Check if whiptail is installed else install it
check_whiptail() {
if ! command -v whiptail &>/dev/null; then
sudo pacman -S --needed --noconfirm --asdeps libnewt
fi
}
# Function name: Add repositories
# Description: Ask the user if they want to add specific repositories
add_repositories() {
options=(
"CachyOS" "Add CachyOS repository" OFF
"Chromatic" "Add Chromatic repository" ON
"BlackArch" "Add BlackArch repository" OFF
"Chaotic.cx" "Add Chaotic.cx repository" ON
)
selected_repos=$(whiptail --title "Add Repositories" --checklist \
"Choose the repositories you want to add:" 20 78 4 \
"${options[@]}" 3>&1 1>&2 2>&3)
for repo in $selected_repos; do
case $repo in
"\"CachyOS\"")
if ! grep -q "\[cachyos\]" /etc/pacman.conf; then
curl https://mirror.cachyos.org/cachyos-repo.tar.xz -o /tmp/cachyos-repo.tar.xz
tar xvf /tmp/cachyos-repo.tar.xz -C /tmp
cd /tmp/cachyos-repo || exit
sudo ./cachyos-repo.sh
else
echo "CachyOS repository is already installed."
fi
;;
"\"Chromatic\"")
if ! grep -q "\[chromatic\]" /etc/pacman.conf; then
sudo pacman-key --recv-key 6EFB412EBDDD1853DF71F4B625AE803AA8C39062
sudo pacman-key --lsign-key 6EFB412EBDDD1853DF71F4B625AE803AA8C39062
sudo pacman -U --noconfirm 'https://mirror.trap.moe/chromatic/x86_64/chromatic-keyring-1.0-1-any.pkg.tar.zst'
sudo pacman -U --noconfirm 'https://mirror.trap.moe/chromatic/x86_64/chromatic-mirrorlist-20250315-1-any.pkg.tar.zst' --overwrite /etc/pacman.d/chromatic-mirrorlist
echo '[chromatic]' | sudo tee -a /etc/pacman.conf
echo 'Include = /etc/pacman.d/chromatic-mirrorlist' | sudo tee -a /etc/pacman.conf
sudo pacman -Sy --noconfirm chromatic-keyring chromatic-mirrorlist
else
echo "Chromatic repository is already installed."
fi
;;
"\"BlackArch\"")
if ! grep -q "\[blackarch\]" /etc/pacman.conf; then
curl -O https://blackarch.org/strap.sh
chmod +x strap.sh
sudo sed -i 's/msg '\''installing blackarch-officials meta-package...'\''/#msg '\''installing blackarch-officials meta-package...'\''/' strap.sh
sudo sed -i 's/pacman -S --noconfirm --needed blackarch-officials/#pacman -S --noconfirm --needed blackarch-officials/' strap.sh
sudo ./strap.sh
else
echo "BlackArch repository is already installed."
fi
;;
"\"Chaotic.cx\"")
if ! grep -q "\[chaotic-aur\]" /etc/pacman.conf; then
sudo pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
sudo pacman-key --lsign-key 3056513887B78AEB
sudo pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
sudo pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
echo '[chaotic-aur]' | sudo tee -a /etc/pacman.conf
echo 'Include = /etc/pacman.d/chaotic-mirrorlist' | sudo tee -a /etc/pacman.conf
else
echo "Chaotic.cx repository is already installed."
fi
;;
esac
done
}
# Function name: Update system
# Description: Update the system
update_system() {
sudo pacman -Syu --noconfirm
}
# Function name: Setup Pacman configuration
# Description: Setup Pacman configuration
setup_pacman() {
sudo sed -i 's/#Color/Color/' /etc/pacman.conf
sudo sed -i 's/#ILoveCandy/ILoveCandy/' /etc/pacman.conf
sudo sed -i 's/#VerbosePkgLists/VerbosePkgLists/' /etc/pacman.conf
sudo sed -i 's/#CheckSpace/CheckSpace/' /etc/pacman.conf
#sudo sed -i 's/#PrettyProgressBar/PrettyProgressBar/' /etc/pacman.conf
sudo sed -i 's/#ParallelDownloads = 5/ParallelDownloads = 10/' /etc/pacman.conf
sudo sed -i 's/#DisableDownloadTimeout/DisableDownloadTimeout/' /etc/pacman.conf
}
# Function name: GPU setup
# Description: Setup GPU depending on the available devices
gpu_setup() {
detected_gpu=$(lspci | grep -Ei "vga|3d|display")
case "$detected_gpu" in
*NVIDIA*)
options=(
"nvidia" "Official NVIDIA Drivers" ON
"nouveau" "Open Source nouveau drivers" OFF
)
selected_driver=$(whiptail --title "Select NVIDIA Drivers" --radiolist \
"Choose the NVIDIA driver you want to install:" 15 60 2 \
"${options[@]}" 3>&1 1>&2 2>&3)
if pacman -Qs nvidia > /dev/null; then
sudo pacman -R --noconfirm nvidia
elif pacman -Qs nvidia-dkms > /dev/null; then
sudo pacman -R --noconfirm nvidia-dkms
elif pacman -Qs xf86-video-nouveau > /dev/null; then
sudo pacman -R --noconfirm xf86-video-nouveau
fi
case $selected_driver in
"\"nvidia\"")
if pacman -Qs linux > /dev/null; then
sudo pacman -S --needed --noconfirm nvidia-open
fi
if pacman -Qs linux-lts > /dev/null; then
sudo pacman -S --needed --noconfirm nvidia-open-lts
fi
if pacman -Qs linux-cachyos > /dev/null; then
sudo pacman -S --needed --noconfirm linux-cachyos-nvidia-open
fi
if pacman -Qs linux-zen > /dev/null || pacman -Qs linux-hardened > /dev/null; then
sudo pacman -S --needed --noconfirm nvidia-open-dkms
fi
if ! lspci | grep -Ei "amd|intel" > /dev/null; then
sudo pacman -S --needed --noconfirm libva-nvidia-driver
fi
if (whiptail --title "Install Cuda" --yesno "Would you like to install Cuda?" 10 60) then
sudo pacman -S --needed --noconfirm cuda
fi
;;
"\"nouveau\"")
sudo pacman -S --needed --noconfirm mesa vulkan-nouveau
;;
esac
;;
*AMD*)
sudo pacman -S --needed --noconfirm mesa vulkan-radeon
;;
*Intel*)
sudo pacman -S --needed --noconfirm intel-media-driver vulkan-intel
;;
esac
}
# Function name: Setup plymouth
# Description: Setup plymouth
setup_plymouth() {
if whiptail --title "Setup Plymouth" --yesno "Would you like to setup Plymouth?" 10 60; then
echo "quiet splash" | sudo tee -a /etc/kernel/cmdline
sudo pacman -S --needed --noconfirm plymouth plymouth-kcm
if pacman -Qs plymouth-theme-catppuccin-mocha-git > /dev/null; then
sudo plymouth-set-default-theme -R catppuccin-mocha
else
sudo plymouth-set-default-theme -R spinner
fi
fi
}
# Packages group definitions
# Package groups
zsh_packages=(
grml-zsh-config
oh-my-zsh-git
zsh
zsh-autosuggestions
zsh-completions
zsh-history-substring-search
zsh-lovers
zsh-syntax-highlighting
)
theme_packages=(
btop-theme-catppuccin
catppuccin-cursors-mocha
catppuccin-gtk-theme-mocha
papirus-folders-catppuccin-git
plymouth-theme-catppuccin-mocha-git
#refind-theme-catppuccin-git
sddm-theme-catppuccin-git
)
plasma_kde_apps=(
kate
okular
dolphin
gwenview
kcalc
spectacle
gparted
)
gnome_apps=(
gnome-console
gnome-disk-utility
gnome-firmware
)
games_packages=(
steam-native-runtime
heroic-games-launcher-bin
an-anime-game-launcher-bin
honkers-launcher-bin
sleepy-launcher-bin
the-honkers-railway-launcher-bin
umu-launcher
goverlay
gamemode
gamescope
mangohud
)
pipewire_packages=(
pipewire
pipewire-pulse
pipewire-jack
pipewire-alsa
wireplumber
)
cups_packages=(
cups
cups-pdf
cups-filters
system-config-printer
)
networkmanager_packages=(
networkmanager
networkmanager-openvpn
networkmanager-pptp
networkmanager-vpnc
networkmanager-strongswan
networkmanager-l2tp
wpa_supplicant
)
bluetooth_packages=(
bluez
bluez-utils
bluez-hid2hci
bluedevil
)
virtualization_packages=(
qemu-full
virt-manager
virt-viewer
swtpm
)
containers_packages=(
podman
distrobox
waydroid
lxc
)
thunderbird_packages=(
thunderbird
thunderbird-i18n-en-us
thunderbird-dark-reader
thunderbird-ublock-origin
)
# function name : setup browser
# Description: setup browser
setup_browser() {
options=(
"Firefox" "Install Firefox" ON
"Chromium" "Install Chromium" OFF
"Brave" "Install Brave" OFF
"Vivaldi" "Install Vivaldi" OFF
"Google Chrome" "Install Google Chrome" OFF
"Zen Browser" "Install Zen Browser" OFF
"Tor Browser" "Install Tor Browser" OFF
"Mullvad Browser" "Install Mullvad Browser" OFF
"Edge Stable" "Install Edge Stable" OFF
"LibreWolf" "Install LibreWolf" OFF
"Floorp" "Install Floorp" OFF
"Chromium Widevine" "Install Chromium Widevine" OFF
"Links" "Install Links" OFF
)
selected_browsers=$(whiptail --title "Setup Browser" --checklist \
"Choose the browsers you want to install:" 20 78 13 \
"${options[@]}" 3>&1 1>&2 2>&3)
for browser in $selected_browsers; do
case $browser in
"\"Firefox\"")
sudo pacman -S --needed --noconfirm firefox
;;
"\"Chromium\"")
sudo pacman -S --needed --noconfirm chromium
;;
"\"Brave\"")
sudo pacman -S --needed --noconfirm brave-bin
;;
"\"Vivaldi\"")
sudo pacman -S --needed --noconfirm vivaldi
;;
"\"Google Chrome\"")
yay -S --needed --noconfirm google-chrome
;;
"\"Zen Browser\"")
yay -S --needed --noconfirm zen-browser-bin
;;
"\"Tor Browser\"")
sudo pacman -S --needed --noconfirm tor-browser-bin
;;
"\"Mullvad Browser\"")
yay -S --needed --noconfirm mullvad-browser-bin
;;
"\"Edge Stable\"")
yay -S --needed --noconfirm microsoft-edge-stable-bin
;;
"\"LibreWolf\"")
yay -S --needed --noconfirm librewolf
;;
"\"Floorp\"")
yay -S --needed --noconfirm floorp-bin
;;
"\"Chromium Widevine\"")
sudo pacman -S --needed --noconfirm chromium-widevine
;;
"\"Links\"")
sudo pacman -S --needed --noconfirm links
;;
esac
done
}
# function name : setup u2f
# Description: setup u2f
setup_u2f() {
install_package pam-u2f
mkdir ~/.config/Yubico
echo "Registering U2F device..."
pamu2fcfg -o "pam://$HOST" -i "pam://$HOST" > ~/.config/Yubico/u2f_keys
sudo touch /etc/pam.d/u2f-required
sudo touch /etc/pam.d/u2f-sufficient
echo "auth required pam_u2f.so cue origin=pam://$HOST appid=pam://$HOST" | sudo tee -a /etc/pam.d/u2f-required
echo "auth sufficient pam_u2f.so cue origin=pam://$HOST appid=pam://$HOST" | sudo tee -a /etc/pam.d/u2f-sufficient
sudo sed -i '/^password\s*include\s*system-auth/i auth include u2f-sufficient' /etc/pam.d/su
sudo sed -i '/^auth\s*include\s*system-auth/i auth include u2f-sufficient' /etc/pam.d/sudo
sudo sed -i '/^auth\s*include\s*system-auth/i auth include u2f-sufficient' /etc/pam.d/passwd
sudo sed -i '/^auth\s*include\s*system-auth/i auth include u2f-sufficient' /etc/pam.d/system-login
sudo cp /usr/lib/pam.d/polkit-1 /etc/pam.d/polkit-1
sudo sed -i '/^auth\s*include\s*system-auth/i auth include u2f-sufficient' /etc/pam.d/polkit-1
}
# function name : setup OpenRGB
# Description: setup OpenRGB
setup_openrgb() {
install_package openrgb
sudo gpasswd -a "$USER" plugdev
sudo systemctl enable --now openrgb
}
# function name : Install packages group
# Description: Install packages group by asking with a selection menu which group would you like to install
install_packages_group() {
options=(
"Zsh" "Install Zsh packages" OFF
"Theme" "Install Theme packages" OFF
"Plasma Apps" "Install KDE Plasma Apps" OFF
"Gnome Apps" "Install Gnome Apps" OFF
"Games" "Install Games packages" OFF
"Pipewire" "Install Pipewire packages" OFF
"Cups" "Install Cups packages" OFF
"NetworkManager" "Install NetworkManager packages" OFF
"Bluetooth" "Install Bluetooth packages" OFF
"Virtualization" "Install Virtualization packages" OFF
"Containers" "Install Containers packages" OFF
"U2F" "Setup U2F" OFF
"OpenRGB" "Setup OpenRGB" OFF
"Thunderbird" "Install Thunderbird" OFF
)
selected_groups=$(whiptail --title "Install Packages Group" --checklist \
"Choose the packages group you want to install:" 20 78 13 \
"${options[@]}" 3>&1 1>&2 2>&3)
for group in $selected_groups; do
case $group in
"\"Zsh\"")
install_packages zsh_packages[@]
if (whiptail --title "Change default shell to Zsh" --yesno "Would you like to change the default shell to Zsh?" 10 60) then
chsh -s /bin/zsh
fi
;;
"\"Theme\"")
install_packages theme_packages[@]
;;
"\"Games\"")
install_packages games_packages[@]
;;
"\"Pipewire\"")
install_packages pipewire_packages[@]
;;
"\"Cups\"")
install_packages cups_packages[@]
;;
"\"NetworkManager\"")
install_packages networkmanager_packages[@]
;;
"\"Bluetooth\"")
install_packages bluetooth_packages[@]
sudo systemctl enable --now bluetooth
;;
"\"Virtualization\"")
install_packages virtualization_packages[@]
sudo systemctl enable --now libvirtd
;;
"\"Containers\"")
install_packages containers_packages[@]
# if nvidia gpu is detected
if lspci | grep -Ei "nvidia" > /dev/null; then
install_package nvidia-container-toolkit
fi
;;
"\"U2F\"")
setup_u2f
;;
"\"OpenRGB\"")
setup_openrgb
;;
"\"Thunderbird\"")
install_packages thunderbird_packages[@]
;;
esac
done
}
# function name : setup_firewall
# Description: setup firewall
setup_firewall() {
options=(
"ufw" "Install UFW" ON
"firewalld" "Install Firewalld" OFF
"iptables" "Install Iptables" ON
"nftables" "Install Nftables" OFF
)
selected_groups=$(whiptail --title "Setup Firewall" --checklist "Choose the firewall you want to install:" 20 78 4 "${options[@]}")
case $selected_groups in
"ufw")
install_package ufw
install_dependencies ufw-extras
sudo systemctl enable --now ufw
sudo ufw enable
;;
"firewalld")
install_package firewalld
sudo systemctl enable --now firewalld
;;
"iptables")
install_package iptables
;;
"nftables")
install_package nftables
install_package iptables-nft
;;
esac
}
# function name : setup_flatpak
# Description: setup flatpak
setup_flatpak() {
if whiptail --title "Setup Flatpak" --yesno "Would you like to setup Flatpak?" 10 60; then
install_package flatpak
flatpak remote-add --if-not-exists --system flathub https://flathub.org/repo/flathub.flatpakrepo
fi
}
# function name : setup_fwupd
# Description: setup fwupd
setup_fwupd() {
if whiptail --title "Setup fwupd" --yesno "Would you like to setup fwupd?" 10 60; then
install_package fwupd
install_dependencies fwupd-efi
sudo systemctl enable --now fwupd
sudo systemctl enable --now fwupd-refresh
fi
}
# function name : setup_kdeconnect
# Description: setup kdeconnect
setup_kdeconnect() {
if whiptail --title "Setup KDE Connect" --yesno "Would you like to setup KDE Connect?" 10 60; then
options=(
"kdeconnect" "Install KDE Connect" OFF
"gsconnect" "Install GSConnect" OFF
)
selected_option=$(whiptail --title "Setup KDE Connect" --radiolist "Choose the package you want to install:" 20 78 2 "${options[@]}" 3>&1 1>&2 2>&3)
case $selected_option in
"\"kdeconnect\"")
install_package kdeconnect
;;
"\"gsconnect\"")
install_package gnome-shell-extension-gsconnect
;;
esac
fi
}
# function name : setup_office_suite
# Description: setup office suite
setup_office_suite() {
options=(
"LibreOffice" "Install LibreOffice" OFF
"OnlyOffice" "Install OnlyOffice" OFF
"WPS Office" "Install WPS Office" OFF
"FreeOffice" "Install FreeOffice" OFF
)
selected_option=$(whiptail --title "Setup Office Suite" --radiolist "Choose the office suite you want to install:" 20 78 4 "${options[@]}" 3>&1 1>&2 2>&3)
case $selected_option in
"\"LibreOffice\"")
install_package libreoffice-fresh
;;
"\"OnlyOffice\"")
install_package onlyoffice-bin
;;
"\"WPS Office\"")
install_package wps-office
;;
"\"FreeOffice\"")
install_package freeoffice
;;
esac
}
# Main script
check_whiptail
add_repositories
update_system
setup_pacman
setup_browser
install_packages_group
setup_plymouth
gpu_setup
setup_firewall
setup_flatpak
setup_fwupd
setup_kdeconnect
setup_office_suite