mirror of
https://github.com/Snigdha-OS/snigdhaos-system-installation.git
synced 2025-09-21 05:44:57 +02:00
82 lines
2.8 KiB
Bash
Executable File
82 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Author : Eshan Roy <eshan@snigdhaos.or>
|
|
# Author URL : https://eshanized.github.io/
|
|
|
|
LOG_FILE="/var/log/snigdhaos_vm_check.log"
|
|
ERROR_LOG="/var/log/snigdhaos_vm_check_error.log"
|
|
|
|
# Log a message to the log file
|
|
log_message() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
# Log an error message and exit
|
|
log_error() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR: $1" | tee -a "$ERROR_LOG"
|
|
exit 1
|
|
}
|
|
|
|
# Start of the process
|
|
log_message "Starting Snigdha OS Virtual Machine Check..."
|
|
|
|
# Detect virtualization platform
|
|
result=$(systemd-detect-virt)
|
|
if [ $? -ne 0 ]; then
|
|
log_error "Failed to detect virtualization platform."
|
|
fi
|
|
|
|
# Remove db.lck if it exists
|
|
log_message "Checking for Pacman lock (db.lck)..."
|
|
while [ -e "/var/lib/pacman/db.lck" ]; do
|
|
log_message "Pacman is not ready yet. Trying in 10 seconds."
|
|
sleep 10
|
|
if [ -e "/var/lib/pacman/db.lck" ]; then
|
|
log_message "Removing Pacman db.lck!"
|
|
rm /var/lib/pacman/db.lck || log_error "Failed to remove Pacman db.lck"
|
|
fi
|
|
done
|
|
|
|
log_message "You are on: $result"
|
|
|
|
# Define packages to remove for each virtualization platform
|
|
declare -A packages_to_remove
|
|
packages_to_remove[oracle]="open-vm-tools xf86-video-vmware qemu-guest-agent"
|
|
packages_to_remove[kvm]="open-vm-tools xf86-video-vmware virtualbox-guest-utils virtualbox-guest-utils-nox"
|
|
packages_to_remove[vmware]="virtualbox-guest-utils virtualbox-guest-utils-nox qemu-guest-agent"
|
|
packages_to_remove[none]="virtualbox-guest-utils virtualbox-guest-utils-nox qemu-guest-agent open-vm-tools xf86-video-vmware"
|
|
|
|
# Remove packages and disable services
|
|
log_message "Removing platform-specific packages and services..."
|
|
for package in ${packages_to_remove[$result]}; do
|
|
if pacman -Qi $package &> /dev/null; then
|
|
systemctl disable $package.service || log_error "Failed to disable service $package.service"
|
|
pacman -Rns $package --noconfirm || log_error "Failed to remove package $package"
|
|
log_message "[REMOVED] $package"
|
|
else
|
|
log_message "[SKIPPED] $package is not installed."
|
|
fi
|
|
done
|
|
|
|
# Remove additional files specific to VMware or other platforms
|
|
remove_file() {
|
|
local file=$1
|
|
if [ -f "$file" ]; then
|
|
rm -v "$file" || log_error "Failed to remove $file"
|
|
log_message "[REMOVED] $file"
|
|
else
|
|
log_message "[SKIPPED] $file does not exist."
|
|
fi
|
|
}
|
|
|
|
remove_file "/etc/xdg/autostart/vmware-user.desktop"
|
|
remove_file "/etc/systemd/system/multi-user.target.wants/vmtoolsd.service"
|
|
remove_file "/usr/local/bin/snigdhaos-virtual-machine-check"
|
|
remove_file "/etc/systemd/system/multi-user.target.wants/virtual-machine-check.service"
|
|
|
|
log_message "Virtual machine check completed successfully."
|
|
|
|
echo
|
|
echo "--->> End snigdhaos-virtual-machine-check <<---"
|
|
echo
|