diff --git a/fresh-install/aur_packages.txt b/fresh-install/aur_packages.txt index 9131d6e..0afbd0d 100644 --- a/fresh-install/aur_packages.txt +++ b/fresh-install/aur_packages.txt @@ -1,7 +1,8 @@ +local-arch-wiki https://aur.archlinux.org/local-arch-wiki.git visual-studio-code-bin https://aur.archlinux.org/visual-studio-code-bin.git thorium-browser-bin https://aur.archlinux.org/thorium-browser-bin.git mkinitcpio-git https://aur.archlinux.org/mkinitcpio-git.git -yay-git https://aur.archlinux.org/yay-git.git +yay https://aur.archlinux.org/yay.git http-parser-git https://aur.archlinux.org/http-parser-git.git python310 https://aur.archlinux.org/python310.git slack-electron https://aur.archlinux.org/slack-electron.git diff --git a/fresh-install/detect_gpu_and_install.sh b/fresh-install/detect_gpu_and_install.sh new file mode 100755 index 0000000..56b5f05 --- /dev/null +++ b/fresh-install/detect_gpu_and_install.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Detect GPU vendor and (if NVIDIA) install required driver packages. +# Exports GPU_VENDOR and SKIP_NVIDIA_PACKAGES variables for caller scripts. +set -e + +GPU_VENDOR="unknown" + +# Get all display / 3D / VGA controllers +PCI_GPU_INFO=$(lspci -nn | grep -Ei 'vga|3d|display' || true) + +if echo "$PCI_GPU_INFO" | grep -qi nvidia; then + GPU_VENDOR="nvidia" +elif echo "$PCI_GPU_INFO" | grep -Eqi 'amd|advanced micro devices|ati'; then + GPU_VENDOR="amd" +elif echo "$PCI_GPU_INFO" | grep -qi intel; then + GPU_VENDOR="intel" +fi + +export GPU_VENDOR + +NVIDIA_PACKAGES=(nvidia nvidia-utils lib32-nvidia-utils) + +if [ "$GPU_VENDOR" = "nvidia" ]; then + echo "Detected NVIDIA GPU. Ensuring NVIDIA packages are installed." + for pkg in "${NVIDIA_PACKAGES[@]}"; do + if pacman -Qi "$pkg" >/dev/null 2>&1; then + echo " $pkg already installed" + else + echo " Installing $pkg" + yes | sudo pacman -Sy --noconfirm "$pkg" + fi + done + export SKIP_NVIDIA_PACKAGES="false" +else + echo "Detected GPU vendor: $GPU_VENDOR (not NVIDIA). Skipping NVIDIA driver installation." + # If any NVIDIA packages are present, remove them. + to_remove=() + for pkg in "${NVIDIA_PACKAGES[@]}"; do + if pacman -Qi "$pkg" >/dev/null 2>&1; then + to_remove+=("$pkg") + fi + done + if [ ${#to_remove[@]} -gt 0 ]; then + echo "Removing NVIDIA specific packages: ${to_remove[*]}" + # Use --noconfirm and Rns to remove packages with their unused deps. + yes | sudo pacman -Rns --noconfirm "${to_remove[@]}" || true + else + echo "No NVIDIA packages installed to remove." + fi + export SKIP_NVIDIA_PACKAGES="true" +fi diff --git a/fresh-install/main.sh b/fresh-install/main.sh index eaf3e0c..3490b9b 100755 --- a/fresh-install/main.sh +++ b/fresh-install/main.sh @@ -17,25 +17,56 @@ trap 'play_error_sound' ERR sudo -v git config --global init.defaultBranch main +# GPU detection and conditional NVIDIA driver installation +if [ -f "./detect_gpu_and_install.sh" ]; then + . ./detect_gpu_and_install.sh +else + echo "GPU detection script not found; continuing without conditional NVIDIA install." +fi + install_from_aur() { if [ ! -d "$HOME/aur" ]; then - mkdir ~/aur + mkdir -p "$HOME/aur" fi - cd ~/aur + cd "$HOME/aur" local repo_url=$1 local pkg_name=$2 + local repo_dir="$(basename "$repo_url" .git)" - if [ ! -d "$(basename $repo_url .git)" ]; then - git clone $repo_url + if [ ! -d "$repo_dir" ]; then + git clone "$repo_url" else - echo "Repository $(basename $repo_url .git) already cloned" + echo "Repository $repo_dir already cloned; updating" + (cd "$repo_dir" && git fetch --all -q && git reset --hard origin/HEAD -q || git pull --ff-only || true) fi - cd $(basename $repo_url .git) - if ! pacman -Qi $pkg_name > /dev/null 2>&1; then - yes | makepkg -s --nocheck --skipchecksums --skipinteg --skippgpcheck --noconfirm --needed - yes | sudo pacman -U *.pkg.tar.zst - else + cd "$repo_dir" + + if pacman -Qi "$pkg_name" >/dev/null 2>&1; then echo "$pkg_name is already installed" + return 0 + fi + + echo "Cleaning old package artifacts to avoid duplicate -U targets" + find . -maxdepth 1 -type f -name '*.pkg.tar.*' -delete 2>/dev/null || true + + echo "Building $pkg_name (clean build)" + # -c (clean up work dirs after) -C (clean build - remove src/ and pkg/ first) + if ! yes | makepkg -s -c -C --noconfirm --nocheck --skipchecksums --skipinteg --skippgpcheck --needed; then + echo "Build failed for $pkg_name" >&2 + return 1 + fi + + # Collect only the freshly built packages (should now be only current version) + mapfile -t built_pkgs < <(ls -1 *.pkg.tar.zst 2>/dev/null || true) + if [ ${#built_pkgs[@]} -eq 0 ]; then + echo "No package files produced for $pkg_name" >&2 + return 1 + fi + + echo "Installing built package(s): ${built_pkgs[*]}" + if ! yes | sudo pacman -U --noconfirm "${built_pkgs[@]}"; then + echo "Installation failed for $pkg_name" >&2 + return 1 fi } @@ -90,9 +121,42 @@ sudo cp ./pacman.conf /etc/pacman.conf # sudo cp /etc/mkinitcpio.conf /etc/mkinitcpio.conf.bak # sudo cp ./mkinitcpio.conf /etc/mkinitcpio.conf # mkinitcpio -P -yes | sudo pacman -Sy --noconfirm reflector -sudo systemctl enable reflector.service -sudo systemctl start reflector.service +# Reflector install / service management (idempotent & resilient) +if pacman -Qi reflector >/dev/null 2>&1; then + echo "reflector already installed" +else + yes | sudo pacman -Sy --noconfirm reflector || echo "Warning: reflector install failed (continuing)" +fi +# Prefer timer over service (Arch default) +if systemctl list-unit-files | grep -q '^reflector.timer'; then + if systemctl is-enabled reflector.timer >/dev/null 2>&1; then + echo "reflector.timer already enabled" + else + sudo systemctl enable reflector.timer || echo "Warning: could not enable reflector.timer" + fi + if systemctl is-active reflector.timer >/dev/null 2>&1; then + echo "reflector.timer already active" + else + if ! sudo systemctl start reflector.timer; then + echo "Warning: failed to start reflector.timer (check: systemctl status reflector.timer; journalctl -xeu reflector.timer)" + fi + fi +elif systemctl list-unit-files | grep -q '^reflector.service'; then + if systemctl is-enabled reflector.service >/dev/null 2>&1; then + echo "reflector.service already enabled" + else + sudo systemctl enable reflector.service || echo "Warning: could not enable reflector.service" + fi + if systemctl is-active reflector.service >/dev/null 2>&1; then + echo "reflector.service already running" + else + if ! sudo systemctl start reflector.service; then + echo "Warning: failed to start reflector.service (check: systemctl status reflector.service; journalctl -xeu reflector.service)" + fi + fi +else + echo "reflector systemd unit not found (neither timer nor service)" +fi # Read pacman packages from file declare -a pacman_packages while IFS= read -r line; do @@ -103,6 +167,11 @@ while IFS= read -r line; do done < "pacman_packages.txt" for pkg in "${pacman_packages[@]}"; do + # Skip NVIDIA packages if GPU is not NVIDIA + if [ "$GPU_VENDOR" != "nvidia" ] && { [ "$pkg" = "nvidia" ] || [ "$pkg" = "nvidia-utils" ] || [ "$pkg" = "lib32-nvidia-utils" ]; }; then + echo "Skipping $pkg (GPU vendor: $GPU_VENDOR)" + continue + fi # Check for texlive subpackages if [ "$pkg" == "texlive" ]; then sub_pkgs=( diff --git a/fresh-install/pacman_packages.txt b/fresh-install/pacman_packages.txt index ffff58c..e9b876a 100644 --- a/fresh-install/pacman_packages.txt +++ b/fresh-install/pacman_packages.txt @@ -1,3 +1,4 @@ +arch-wiki-docs # duh - using default linux for most compatibility linux # needed for compiling basically anything @@ -140,7 +141,6 @@ gst-plugins-base libgphoto2 lapacke opencv -cuda vulkan-validation-layers libltc libavtp @@ -196,9 +196,6 @@ lib32-libvpx libsoup lib32-libsoup lib32-speex -nvidia -nvidia-utils -lib32-nvidia-utils steam steam-native-runtime fontforge @@ -223,9 +220,9 @@ pyside6 python-pyaml python-zstandard zip -virtualbox -virtualbox-guest-iso -virtualbox-ext-vnc +#virtualbox +#virtualbox-guest-iso +#virtualbox-ext-vnc imath embree jdk-openjdk