make install.sh script compatible for running on non-arch systems

This commit is contained in:
Zechert, Frank (EXTERN: Capgemini)
2026-05-19 11:19:06 +02:00
parent 83891fa61c
commit 0e9f9cf418
+21 -8
View File
@@ -1,16 +1,19 @@
#!/bin/bash #!/bin/bash
packagefile="packages.txt" PACKAGEFILE="packages.txt"
# Ensure we are in the correct directory # Ensure we are in the correct directory
pushd "$(dirname "$(realpath "$0")")" &> /dev/null pushd "$(dirname "$(realpath "$0")")" &> /dev/null
# Check if commands are available
command -v yay &> /dev/null && CMD_YAY=true || CMD_YAY=false
# Read packages.txt and install packages on system using yay # Read packages.txt and install packages on system using yay
function install_packages { function install_packages {
local install local install
for pkg in $(sed -E -e 's/\s*#.*$//g' -e 's/^\s+//g' "$packagefile" | sed -E ':a;N;$!ba;s/\s+/\n/g'); do for pkg in $(sed -E -e 's/\s*#.*$//g' -e 's/^\s+//g' "$PACKAGEFILE" | sed -E ':a;N;$!ba;s/\s+/\n/g'); do
# check if package is installed # check if package is installed
local installed local installed
yay -Q "$(echo "$pkg")" &> /dev/null && installed=1 || installed=0 $CMD_YAY && yay -Q "$(echo "$pkg")" &> /dev/null && installed=1 || installed=0
if [ $installed -eq 0 ]; then if [ $installed -eq 0 ]; then
# needs to be installed # needs to be installed
install="$install"$'\n'"$pkg" install="$install"$'\n'"$pkg"
@@ -18,9 +21,19 @@ function install_packages {
done done
[ -z "$install" ] || { [ -z "$install" ] || {
echo "Packages to be installed: " if $CMD_YAY; then
echo "$install" echo "Packages to be installed: "
yay -S $install echo "$install"
yay -S $install
else
echo "Yay package manager is not available"
echo "Please make sure that the following tools"
echo "are available in your system"
echo ""
echo "$install"
echo ""
read -p "Press Enter to continue" < /dev/tty
fi
} }
} }
@@ -33,7 +46,7 @@ function install_treesitter_language {
local directory=$(basename "$repository") local directory=$(basename "$repository")
# Clone the repository or update it # Clone the repository or update it
if [ ! -d "tree-sitter-source" ]; then if [ ! -d "tree-sitter-source" ]; then
mkdir tree-sitter-source mkdir tree-sitter-source
fi fi
@@ -56,7 +69,7 @@ function install_treesitter_language {
pushd "tree-sitter-source/$directory" &> /dev/null pushd "tree-sitter-source/$directory" &> /dev/null
tree-sitter build tree-sitter build
popd &> /dev/null popd &> /dev/null
# Copy parser # Copy parser
if [ ! -d "parser" ]; then if [ ! -d "parser" ]; then
mkdir "parser" mkdir "parser"