2023-08-17 18:56:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# _ _ _
|
|
|
|
# | | (_) |__ _ __ __ _ _ __ _ _
|
|
|
|
# | | | | '_ \| '__/ _` | '__| | | |
|
|
|
|
# | |___| | |_) | | | (_| | | | |_| |
|
|
|
|
# |_____|_|_.__/|_| \__,_|_| \__, |
|
|
|
|
# |___/
|
|
|
|
#
|
|
|
|
# by Stephan Raabe (2023)
|
|
|
|
# -----------------------------------------------------
|
|
|
|
|
|
|
|
# ------------------------------------------------------
|
|
|
|
# Function: Is package installed
|
|
|
|
# ------------------------------------------------------
|
|
|
|
_isInstalledPacman() {
|
|
|
|
package="$1";
|
|
|
|
check="$(sudo pacman -Qs --color always "${package}" | grep "local" | grep "${package} ")";
|
|
|
|
if [ -n "${check}" ] ; then
|
|
|
|
echo 0; #'0' means 'true' in Bash
|
|
|
|
return; #true
|
|
|
|
fi;
|
|
|
|
echo 1; #'1' means 'false' in Bash
|
|
|
|
return; #false
|
|
|
|
}
|
|
|
|
|
|
|
|
_isInstalledYay() {
|
|
|
|
package="$1";
|
|
|
|
check="$(yay -Qs --color always "${package}" | grep "local" | grep "${package} ")";
|
|
|
|
if [ -n "${check}" ] ; then
|
|
|
|
echo 0; #'0' means 'true' in Bash
|
|
|
|
return; #true
|
|
|
|
fi;
|
|
|
|
echo 1; #'1' means 'false' in Bash
|
|
|
|
return; #false
|
|
|
|
}
|
|
|
|
|
2023-11-25 15:53:12 +00:00
|
|
|
_isFolderEmpty() {
|
|
|
|
folder="$1"
|
|
|
|
if [ -d $folder ] ;then
|
|
|
|
if [ -z "$(ls -A $folder)" ]; then
|
|
|
|
echo 0
|
|
|
|
else
|
|
|
|
echo 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-08-17 18:56:53 +00:00
|
|
|
# ------------------------------------------------------
|
|
|
|
# Function Install all package if not installed
|
|
|
|
# ------------------------------------------------------
|
|
|
|
_installPackagesPacman() {
|
|
|
|
toInstall=();
|
|
|
|
for pkg; do
|
|
|
|
if [[ $(_isInstalledPacman "${pkg}") == 0 ]]; then
|
|
|
|
echo "${pkg} is already installed.";
|
|
|
|
continue;
|
|
|
|
fi;
|
2023-12-25 13:45:11 +00:00
|
|
|
toInstall+=("${pkg}");
|
|
|
|
done;
|
2023-08-17 18:56:53 +00:00
|
|
|
|
2023-12-25 13:45:11 +00:00
|
|
|
if [[ "${toInstall[@]}" == "" ]] ; then
|
|
|
|
# echo "All pacman packages are already installed.";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
# printf "Package not installed:\n%s\n" "${toInstall[@]}";
|
|
|
|
sudo pacman --noconfirm -S "${toInstall[@]}";
|
|
|
|
}
|
|
|
|
|
|
|
|
_forcePackagesPacman() {
|
|
|
|
toInstall=();
|
|
|
|
for pkg; do
|
2023-08-17 18:56:53 +00:00
|
|
|
toInstall+=("${pkg}");
|
|
|
|
done;
|
|
|
|
|
|
|
|
if [[ "${toInstall[@]}" == "" ]] ; then
|
|
|
|
# echo "All pacman packages are already installed.";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
|
2023-12-25 13:45:11 +00:00
|
|
|
# printf "Package not installed:\n%s\n" "${toInstall[@]}";
|
2023-12-25 13:49:10 +00:00
|
|
|
sudo pacman --noconfirm -S "${toInstall[@]}" --ask 4;
|
2023-08-17 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_installPackagesYay() {
|
|
|
|
toInstall=();
|
|
|
|
for pkg; do
|
|
|
|
if [[ $(_isInstalledYay "${pkg}") == 0 ]]; then
|
|
|
|
echo "${pkg} is already installed.";
|
|
|
|
continue;
|
|
|
|
fi;
|
2023-12-25 13:45:11 +00:00
|
|
|
toInstall+=("${pkg}");
|
|
|
|
done;
|
2023-08-17 18:56:53 +00:00
|
|
|
|
2023-12-25 13:45:11 +00:00
|
|
|
if [[ "${toInstall[@]}" == "" ]] ; then
|
|
|
|
# echo "All packages are already installed.";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
# printf "AUR packags not installed:\n%s\n" "${toInstall[@]}";
|
|
|
|
yay --noconfirm -S "${toInstall[@]}";
|
|
|
|
}
|
|
|
|
|
|
|
|
_forcePackagesYay() {
|
|
|
|
toInstall=();
|
|
|
|
for pkg; do
|
2023-08-17 18:56:53 +00:00
|
|
|
toInstall+=("${pkg}");
|
|
|
|
done;
|
|
|
|
|
|
|
|
if [[ "${toInstall[@]}" == "" ]] ; then
|
|
|
|
# echo "All packages are already installed.";
|
|
|
|
return;
|
|
|
|
fi;
|
|
|
|
|
2023-12-25 13:45:11 +00:00
|
|
|
# printf "AUR packags not installed:\n%s\n" "${toInstall[@]}";
|
2023-12-25 13:49:10 +00:00
|
|
|
yay --noconfirm -S "${toInstall[@]}" --ask 4;
|
2023-08-17 18:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# ------------------------------------------------------
|
|
|
|
# Create symbolic links
|
|
|
|
# ------------------------------------------------------
|
|
|
|
_installSymLink() {
|
2023-09-04 20:08:28 +00:00
|
|
|
name="$1"
|
|
|
|
symlink="$2";
|
|
|
|
linksource="$3";
|
|
|
|
linktarget="$4";
|
2023-09-04 19:21:39 +00:00
|
|
|
|
2023-11-10 21:12:15 +00:00
|
|
|
if [ -L "${symlink}" ]; then
|
|
|
|
rm ${symlink}
|
|
|
|
ln -s ${linksource} ${linktarget}
|
|
|
|
echo "Symlink ${linksource} -> ${linktarget} created."
|
|
|
|
else
|
|
|
|
if [ -d ${symlink} ]; then
|
|
|
|
rm -rf ${symlink}/
|
|
|
|
ln -s ${linksource} ${linktarget}
|
|
|
|
echo "Symlink for directory ${linksource} -> ${linktarget} created."
|
|
|
|
else
|
|
|
|
if [ -f ${symlink} ]; then
|
|
|
|
rm ${symlink}
|
|
|
|
ln -s ${linksource} ${linktarget}
|
|
|
|
echo "Symlink to file ${linksource} -> ${linktarget} created."
|
|
|
|
else
|
|
|
|
ln -s ${linksource} ${linktarget}
|
|
|
|
echo "New symlink ${linksource} -> ${linktarget} created."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2023-08-17 18:56:53 +00:00
|
|
|
}
|
2023-12-07 09:02:48 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------
|
|
|
|
# Installation in a KVM Virtual Machine
|
|
|
|
# ------------------------------------------------------
|
|
|
|
_isKVM() {
|
|
|
|
iskvm=$(sudo dmesg | grep "Hypervisor detected")
|
|
|
|
if [[ "$iskvm" =~ "KVM" ]] ;then
|
|
|
|
echo 0
|
|
|
|
else
|
|
|
|
echo 1
|
|
|
|
fi
|
|
|
|
}
|