From 89d05994eae3fc54ba992f88f58ff8e284c60050 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 4 Mar 2023 01:32:38 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20cleanup=20VM=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archiso/airootfs/usr/local/bin/remove-nvidia | 157 +++++-------------- 1 file changed, 41 insertions(+), 116 deletions(-) diff --git a/archiso/airootfs/usr/local/bin/remove-nvidia b/archiso/airootfs/usr/local/bin/remove-nvidia index 4b341fa..88f79b4 100755 --- a/archiso/airootfs/usr/local/bin/remove-nvidia +++ b/archiso/airootfs/usr/local/bin/remove-nvidia @@ -1,123 +1,48 @@ #!/bin/bash -# grabed from https://github.com/xerolinux/xerolinux_iso -# -# driver=free or driver=nonfree - grub and efi -echo "Start cachyos-remove-nvidia" -kernel_cmdline(){ - for param in $(cat /proc/cmdline); do - case "${param}" in - $1=*) echo "${param##*=}"; return 0 ;; - "$1") return 0 ;; - *) continue ;; - esac - done - [ -n "${2}" ] && echo "${2}" - return 1 + +_remove_pacman_package() { + local _pkgname="$1" + pacman -Rsnc "$_pkgname" --noconfirm || true } -get_driver(){ - kernel_cmdline driver +# remove pkgs installed for VMs +_clean_vm_packages() { + + #remove virtualbox + if pacman -Qi virtualbox-guest-utils &> /dev/null; then + systemctl disable vboxservice.service + _remove_pacman_package virtualbox-guest-utils + fi + + if pacman -Qi virtualbox-guest-utils-nox &> /dev/null; then + systemctl disable vboxservice.service + _remove_pacman_package virtualbox-guest-utils-nox + fi + + #remove vmware + if [ -f /etc/xdg/autostart/vmware-user.desktop ]; then + rm /etc/xdg/autostart/vmware-user.desktop + fi + + if pacman -Qi open-vm-tools &> /dev/null; then + systemctl disable vmtoolsd.service + _remove_pacman_package open-vm-tools + fi + + if [ -f /etc/systemd/system/multi-user.target.wants/vmtoolsd.service ]; then + rm /etc/systemd/system/multi-user.target.wants/vmtoolsd.service + fi + + #remove qemu + if pacman -Qi qemu-guest-agent &> /dev/null; then + systemctl disable qemu-guest-agent.service + _remove_pacman_package qemu-guest-agent + fi } -get_virtmach(){ - kernel_cmdline virtmach -} - -while [ -e "/var/lib/pacman/db.lck" ]; -do - echo 'Pacman is not ready yet. Will try again in 10 seconds.' - seconds=$((seconds + 10)) - sleep 10 - if [[ "$seconds" == "30" ]]; then - echo 'Warning: removing pacman db.lck!' - rm /var/lib/pacman/db.lck - fi -done - -# free = remove nvidia keep nouveau -selection=$(get_driver) -echo "#################################" -echo "Selection was ""$selection" -echo "#################################" -if [[ $selection == "free" ]]; then - pacman -R --noconfirm nvidia-dkms nvidia-utils +_check_not_running_vm="$(systemd-detect-virt | grep -q 'none'; echo $?)" +if [[ "${_check_not_running_vm}" -eq 0 ]]; then + _clean_vm_packages fi -#freenonouveau = remove nvidia and nouveau -selection=$(get_driver) -echo "#################################" -echo "Selection was ""$selection" -echo "#################################" -if [[ $selection == "freenonouveau" ]]; then - pacman -R --noconfirm nvidia-dkms nvidia-utils - pacman -R --noconfirm xf86-video-nouveau -fi - -#nonfree = keepin nvidia and nouveau -selection=$(get_driver) -echo "Selection was ""$selection" -if [[ $selection == "nonfree" ]]; then - echo "#################################" - echo "We keep nvidia and nouveau onboard" - echo "#################################" -fi - -# nonfreenonouveau : keep nvidia and remove nouveau -selection=$(get_driver) -echo "#################################" -echo "Selection was ""$selection" -echo "#################################" -if [[ $selection == "nonfreenonouveau" ]]; then - pacman -R --noconfirm xf86-video-nouveau -fi - -# remove virtual machines -selection=$(get_virtmach) -echo "#################################" -echo "Selection was ""$selection" -echo "#################################" -if [[ $selection == "none" ]]; then - - #remove virtualbox - if pacman -Qi virtualbox-guest-utils &> /dev/null; then - systemctl disable vboxservice.service - pacman -Rns virtualbox-guest-utils --noconfirm - echo "Removed virtualbox-guest-utils" - fi - - if pacman -Qi virtualbox-guest-utils-nox &> /dev/null; then - systemctl disable vboxservice.service - pacman -Rns virtualbox-guest-utils-nox --noconfirm - echo "Removed virtualbox-guest-utils-nox" - fi - - #remove vmware - if [ -f /etc/xdg/autostart/vmware-user.desktop ]; then - rm /etc/xdg/autostart/vmware-user.desktop - echo "Removed vmware-user.desktop" - fi - - if pacman -Qi open-vm-tools &> /dev/null; then - systemctl disable vmtoolsd.service - echo "Disabled vmtoolsd.service" - pacman -Rns open-vm-tools --noconfirm - echo "Removed open-vm-tools" - fi - - if [ -f /etc/systemd/system/multi-user.target.wants/vmtoolsd.service ]; then - rm /etc/systemd/system/multi-user.target.wants/vmtoolsd.service - echo "Removed vmtoolsd.service if still exists" - fi - - #remove qemu - if pacman -Qi qemu-guest-agent &> /dev/null; then - systemctl disable qemu-guest-agent.service - pacman -Rns qemu-guest-agent --noconfirm - echo "Removed qemu-guest-agent" - fi - -fi - -echo "#################################" -echo "End cachyos-remove-nvidia" -echo "#################################" +# vim:set ft=bash sw=2 sts=2 et: