Files
coredesktop/utils.sh
T
2026-10-19 13:56:54 -06:00

75 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Function to check if a package is installed
is_installed() {
pacman -Qi "$1" &> /dev/null
}
# Function to check if a package is installed
is_group_installed() {
pacman -Qg "$1" &> /dev/null
}
# Function to install packages if not already installed
install_packages() {
local packages=("$@")
local to_install=()
for pkg in "${packages[@]}"; do
if ! is_installed "$pkg" && ! is_group_installed "$pkg"; then
to_install+=("$pkg")
fi
done
if [ ${#to_install[@]} -ne 0 ]; then
echo "Installing: ${to_install[*]}"
yay -S --noconfirm --answerdiff=None --answeredit=None --answerclean=None "${to_install[@]}"
fi
}
# Function to remove pacman/AUR packages if installed
remove_packages() {
local packages=("$@")
local to_remove=()
for pkg in "${packages[@]}"; do
if is_installed "$pkg"; then
to_remove+=("$pkg")
fi
done
if [ ${#to_remove[@]} -ne 0 ]; then
echo "Removing: ${to_remove[*]}"
sudo pacman -Rns --noconfirm "${to_remove[@]}"
fi
}
# Function to remove flatpak applications if installed
remove_flatpaks() {
local flatpaks=("$@")
local to_remove=()
for pak in "${flatpaks[@]}"; do
if flatpak list | grep -qi "$pak"; then
to_remove+=("$pak")
fi
done
if [ ${#to_remove[@]} -ne 0 ]; then
echo "Removing flatpaks: ${to_remove[*]}"
flatpak uninstall --noninteractive "${to_remove[@]}"
fi
}
# Function to enable systemd services if not already enabled
enable_services() {
for service in "$@"; do
if ! systemctl is-enabled "$service" &> /dev/null; then
echo "Enabling $service..."
sudo systemctl enable "$service"
else
echo "$service is already enabled."
fi
done
}