From 36a1d3395df6dabb0a68ae1f316bc46aeea7f9ae Mon Sep 17 00:00:00 2001 From: askiiart Date: Wed, 23 Aug 2023 21:25:12 -0500 Subject: [PATCH] Add package manager detection (partially) --- daily-use-pcs/fedora/setup-git.bash | 21 ++++++++++++++- zsh/zsh-setup.bash | 40 ++++++++++++++++++----------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/daily-use-pcs/fedora/setup-git.bash b/daily-use-pcs/fedora/setup-git.bash index 8a56103..0a28406 100755 --- a/daily-use-pcs/fedora/setup-git.bash +++ b/daily-use-pcs/fedora/setup-git.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Exit if there's an error set -e # Modify constants as needed @@ -9,6 +9,24 @@ EMAIL="dev@askiiart.net" # Note: This waits until enter is pressed # read -p "Press Enter to continue" < /dev/tty +command_exists() { type "$1" &> /dev/null; } + +if command_exists "apt-get"; then + PM="apt-get" +elif command_exists "yum"; then + PM="yum" +elif command_exists "pacman"; then + PM="pacman" +elif command_exists "zypp"; then + PM="zypp" +elif command_exists "emerge"; then + PM="emerge" +elif command_exists "apk"; then + PM="apk" +else + echo "Unsupported: unknown package manager" +fi + declare -A osInfo; osInfo[/etc/redhat-release]=yum osInfo[/etc/arch-release]=pacman @@ -24,6 +42,7 @@ do fi done + sudo ${PACKAGE_MANAGER} install pass git -y # Check if GCM is installed diff --git a/zsh/zsh-setup.bash b/zsh/zsh-setup.bash index e6f534b..ad26625 100755 --- a/zsh/zsh-setup.bash +++ b/zsh/zsh-setup.bash @@ -1,21 +1,31 @@ -#!/bin/bash +#!/usr/bin/env bash # Exit if there's an error set -e -declare -A osInfo; -osInfo[/etc/redhat-release]=yum -osInfo[/etc/arch-release]=pacman -osInfo[/etc/gentoo-release]=emerge -osInfo[/etc/SuSE-release]=zypp -osInfo[/etc/debian_version]=apt-get -osInfo[/etc/alpine-release]=apk -for f in ${!osInfo[@]} -do - if [[ -f $f ]];then - PACKAGE_MANAGER=${osInfo[$f]} - fi -done +if [ $(whoami) != "root" ]; then + $SUDO = "sudo" + exit 1 +fi +exit 0 +command_exists() { type "$1" &> /dev/null; } -sudo ${PACKAGE_MANAGER} install zsh -y +if command_exists "apt-get"; then + $SUDO apt-get install zsh -y +elif command_exists "yum"; then + $SUDO apt-get install zsh -y +elif command_exists "pacman"; then + $SUDO pacman -S zsh --noconfirm --needed +elif command_exists "zypper"; then + $SUDO zypper install zsh -y +elif command_exists "emerge"; then + $SUDO emerge --ask app-shells/zsh + $SUDO emerge --ask app-shells/zsh-completions + $SUDO emerge --ask app-shells/gentoo-zsh-completions +elif command_exists "apk"; then + $SUDO apk add zsh -y; +else + >&2 echo "Unsupported: unknown package manager" + exit 1 +fi cp -r zsh-files/* ~/ \ No newline at end of file