107 lines
2.9 KiB
Bash
107 lines
2.9 KiB
Bash
|
#!/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
|
||
|
}
|
||
|
|
||
|
# ------------------------------------------------------
|
||
|
# Function Install all package if not installed
|
||
|
# ------------------------------------------------------
|
||
|
_installPackagesPacman() {
|
||
|
toInstall=();
|
||
|
|
||
|
for pkg; do
|
||
|
if [[ $(_isInstalledPacman "${pkg}") == 0 ]]; then
|
||
|
echo "${pkg} is already installed.";
|
||
|
continue;
|
||
|
fi;
|
||
|
|
||
|
toInstall+=("${pkg}");
|
||
|
done;
|
||
|
|
||
|
if [[ "${toInstall[@]}" == "" ]] ; then
|
||
|
# echo "All pacman packages are already installed.";
|
||
|
return;
|
||
|
fi;
|
||
|
|
||
|
printf "Packages not installed:\n%s\n" "${toInstall[@]}";
|
||
|
sudo pacman --noconfirm -S "${toInstall[@]}";
|
||
|
}
|
||
|
|
||
|
_installPackagesYay() {
|
||
|
toInstall=();
|
||
|
|
||
|
for pkg; do
|
||
|
if [[ $(_isInstalledYay "${pkg}") == 0 ]]; then
|
||
|
echo "${pkg} is already installed.";
|
||
|
continue;
|
||
|
fi;
|
||
|
|
||
|
toInstall+=("${pkg}");
|
||
|
done;
|
||
|
|
||
|
if [[ "${toInstall[@]}" == "" ]] ; then
|
||
|
# echo "All packages are already installed.";
|
||
|
return;
|
||
|
fi;
|
||
|
|
||
|
printf "AUR ackages not installed:\n%s\n" "${toInstall[@]}";
|
||
|
yay --noconfirm -S "${toInstall[@]}";
|
||
|
}
|
||
|
|
||
|
|
||
|
# ------------------------------------------------------
|
||
|
# Create symbolic links
|
||
|
# ------------------------------------------------------
|
||
|
_installSymLink() {
|
||
|
symlink="$1";
|
||
|
linksource="$2";
|
||
|
linktarget="$3";
|
||
|
if [ -L "${symlink}" ]; then
|
||
|
echo "Link ${symlink} exists already."
|
||
|
else
|
||
|
if [ -d ${symlink} ]; then
|
||
|
echo "Directory ${symlink}/ exists."
|
||
|
ln -s ${linksource} ${linktarget}
|
||
|
else
|
||
|
if [ -f ${symlink} ]; then
|
||
|
echo "File ${symlink} exists."
|
||
|
ln -s ${linksource} ${linktarget}
|
||
|
else
|
||
|
ln -s ${linksource} ${linktarget}
|
||
|
echo "Link ${linksource} -> ${linktarget} created."
|
||
|
fi
|
||
|
fi
|
||
|
fi
|
||
|
}
|