diff --git a/install.sh b/install.sh index 5a300f9..229852d 100755 --- a/install.sh +++ b/install.sh @@ -27,35 +27,56 @@ else echo ".gitconfig does not exist, no backup created." fi -# Check if sudo is installed, if not, install it -if ! command -v sudo &> /dev/null; then - echo "sudo is not installed. Installing sudo..." - if command -v apt &> /dev/null; then - apt update && apt install -y sudo - elif command -v pacman &> /dev/null; then - pacman -S sudo - elif command -v dnf &> /dev/null; then - dnf install -y sudo - elif command -v yum &> /dev/null; then - yum install -y sudo - elif command -v brew &> /dev/null; then - brew install sudo - elif command -v pkg &> /dev/null; then - pkg install sudo +# Function to detect the operating system +detect_os() { + if [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ -f /etc/os-release ]]; then + . /etc/os-release + echo "$ID" else - echo "Package manager not found. Please install sudo manually." - exit 1 + echo "unknown" fi -fi +} +# Function to install packages +install_packages() { + local os=$(detect_os) + case $os in + macos) + if ! command -v brew &> /dev/null; then + echo "Homebrew is not installed. Installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + brew install zsh git wget fontconfig + ;; + ubuntu|debian) + sudo apt-get update + sudo apt-get install -y zsh git wget fontconfig + ;; + fedora) + sudo dnf install -y zsh git wget fontconfig + ;; + centos|rhel) + sudo yum install -y zsh git wget fontconfig + ;; + arch|manjaro) + sudo pacman -Syu --noconfirm zsh git wget fontconfig + ;; + *) + echo "Unsupported operating system. Please install zsh, git, wget, and fontconfig manually." + exit 1 + ;; + esac +} + +# Check if required packages are installed, if not, install them if command -v zsh &> /dev/null && command -v git &> /dev/null && command -v wget &> /dev/null && command -v fc-cache &> /dev/null; then echo -e "ZSH, Git, wget, and fontconfig are already installed\n" else - if sudo apt install -y zsh git wget fontconfig || sudo pacman -S zsh git wget fontconfig || sudo dnf install -y zsh git wget fontconfig || sudo yum install -y zsh git wget fontconfig || sudo brew install git zsh wget fontconfig || pkg install git zsh wget fontconfig ; then - echo -e "zsh, wget, git, and fontconfig Installed\n" - else - echo -e "Please install the following packages first, then try again: zsh, git, wget, fontconfig \n" && exit - fi + echo "Installing required packages..." + install_packages + echo -e "zsh, wget, git, and fontconfig Installed\n" fi if [ -f ~/.gitconfig.backup ]; then @@ -232,4 +253,4 @@ else fi fi -exit +exit \ No newline at end of file