diff --git a/README.MD b/README.MD index d0f5c6c..f0f552f 100644 --- a/README.MD +++ b/README.MD @@ -45,6 +45,10 @@ Currently psh is only tested in the following environments: - Ubuntu - Debian - PopOs! +- Arch Linux +- CachyOS +- EndeavourOS +- Manjaro - Windows Subsystem for Linux 2 (WSL2) - macOS diff --git a/install.sh b/install.sh index a1a7f59..9a072d6 100755 --- a/install.sh +++ b/install.sh @@ -135,6 +135,8 @@ yes_no_abort_dialog "Do you want to install psh? (y/n): " "${start_arg_run_unatt # Import the right package manager depending on current distribution if [[ "$detected_os" = "Debian GNU/Linux" || "$detected_os" = "Ubuntu" || "$detected_os" = "Pop!_OS" ]]; then source "lib/distdep/deb_based/package_management.sh" +elif [[ "$detected_os" = "Arch Linux" || "$detected_os" = "CachyOS Linux" || "$detected_os" = "EndeavourOS" || "$detected_os" = "Manjaro Linux" ]]; then + source "lib/distdep/arch_based/package_management.sh" elif [[ "$detected_os" = "Darwin" ]]; then source "lib/distdep/darwin_based/package_management.sh" else diff --git a/lib/distdep/arch_based/package_management.sh b/lib/distdep/arch_based/package_management.sh new file mode 100644 index 0000000..d035d95 --- /dev/null +++ b/lib/distdep/arch_based/package_management.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# +# Copyright 2025 Pascal Zarrad +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +#================================================================== +# Script Name : psh-package-management +# Description : Sript that contains functions to work with +# packages on arch based systems. +# Args : - +# Author : Pascal Zarrad +# Email : P.Zarrad@outlook.de +#================================================================== + +# Check which dependencies are installed and which not +# +# @param $@ All dependencies that should be checked +function packages_installed() { + local dependencies=("$@") + local not_installed=() + for dependency in "${dependencies[@]}" + do + if ! pacman -Qi "$dependency" &>/dev/null; then + not_installed=("${not_installed[@]}" "${dependency}") + fi + done + echo "${not_installed[@]}" +} + +# Install dependencies. Use sudo if available. +# +# @param $1 Defines whether to prefix the commands with sudo or not +# @param $2 Defines if the unattended mode is being used +# @param $3 The pace separated packages that need to be installed +function install_apt_packages() { + local use_sudo="${1}" + local start_arg_run_unattended="${2}" + local package_install_command="${3}" + IFS=' ' read -r -a package_install_arguments <<< "$package_install_command" + print_message "The installer has to install the following packages through pacman (using sudo if available): " + print_message "${COLOR_CYAN}${package_install_command}${COLOR_RESET}" + yes_no_abort_dialog "Do you want to continue? (y/n): " "${start_arg_run_unattended}" + if [ "$use_sudo" -eq 1 ] + then + sudo pacman -S --noconfirm "${package_install_arguments[@]}" + else + pacman -S --noconfirm "${package_install_arguments[@]}" + fi + install_result="$?" + if [ "$install_result" -ne 0 ]; then + print_error "An error occured during installation of dependencies." + print_error "Please take a look at the problem and revolve the problem manually!" + exit 1 + fi +}