You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
dotfiles/.aliases.d/auto-installer.sh

43 lines
1013 B

auto-pkg-install() {
if [ "$EUID" -eq 0 ]; then
USE_SUPER=""
elif groups "$USER" | grep -o "sudo" >/dev/null 2>/dev/null; then
USE_SUPER="sudo"
elif groups "$USER" | grep -o "doas" >/dev/null 2>/dev/null; then
USE_SUPER="doas"
elif groups "$USER" | grep -o "wheel" >/dev/null 2>/dev/null; then
USE_SUPER="sudo"
elif groups "$USER" | grep -o "admin" >/dev/null 2>/dev/null; then
USE_SUPER="sudo"
else
USE_SUPER="error"
fi
if [ "$USE_SUPER" == "error" ]; then
echo "Please run as root!"
return 1
fi
if [ -z "$1" ]; then
echo "Please give a package name to install!"
return 1
fi
declare -A osInfo;
osInfo[/etc/redhat-release]="yum install"
osInfo[/etc/arch-release]="pacman -S"
osInfo[/etc/gentoo-release]="emerge"
osInfo[/etc/SuSE-release]="zypper install"
osInfo[/etc/debian_version]="apt install"
osInfo[/etc/alpine-release]="apk add --no-cache"
for f in "${!osInfo[@]}"
do
if [[ -f $f ]];then
${USE_SUPER} ${osInfo[$f]} "$1"
fi
done
}
alias aip='auto-pkg-install'