Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified package install function #83

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions scripts/sharedFuncs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,34 @@ function package_installed() {
else
echo "false"
fi
else
else
if [ "$pkginstalled" -eq 0 ];then
show_message "package\033[1;36m $1\e[0m is installed..."
else
warning "package\033[1;33m $1\e[0m is not installed.\nplease make sure it's already installed"
ask_question "would you continue?" "N"
warning "package\033[1;33m $1\e[0m is not installed."
ask_question "would you like to install it now?" "Y"
if [ "$question_result" == "no" ];then
echo "exit..."
exit 5
fi
else
declare -A osInfo;
osInfo[/etc/redhat-release]=yum
osInfo[/etc/SuSE-release]=zypper
osInfo[/etc/debian_version]=apt-get

for f in ${!osInfo[@]}
do
if [[ -f $f ]];then
sudo ${osInfo[$f]} update
sudo ${osInfo[$f]} install $1
return
fi
done
# setup for arch-based systems
sudo pacman -Syu
Copy link

@ulises-jeremias ulises-jeremias Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this implementation could have some side effects for OSs that don't match with redhat, SuSE, debian and Arch. I think it is better if it prints an error when it is a non tested system. Also, for linux distros there is a file called /etc/os-release which has information about the distro and let us do something like this:

    # Find the current distribution
    if [ -f /etc/os-release ]; then
        if grep -q arch /etc/os-release; then
            os="arch-linux"
        elif grep -q debian /etc/os-release; then
            os="debian"
        elif grep -q void /etc/os-release; then
            os="void-linux"
        elif grep -q alpine /etc/os-release; then
            os="alpine"
        elif grep -q fedora /etc/os-release; then
            os="fedora"
        else
            echo "ERROR: I currently don't have support for your distro"
            exit 1
        fi
    fi

Also, to match OS it is possible to do something like this https://github.com/ulises-jeremias/dotfiles/blob/master/util/os.sh

Copy link

@ulises-jeremias ulises-jeremias Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I'll be fine with something like this after the for loop

if grep -q arch /etc/os-release; then
           # setup for arch-based systems
           sudo pacman -Syu
           sudo pacman -S coreutils
	   sudo pacman -S $
else
           echo "Error: I currently don't have support for your distro"
           exit 1
fi

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi thanks I will test it

sudo pacman -S coreutils
sudo pacman -S $1
fi
fi
fi
}
Expand Down