♻️ (install.sh): refactor package installation to support multiple OSes
✨ (install.sh): add OS detection and package installation functions for modularity
This commit is contained in:
65
install.sh
65
install.sh
@@ -27,35 +27,56 @@ else
|
|||||||
echo ".gitconfig does not exist, no backup created."
|
echo ".gitconfig does not exist, no backup created."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if sudo is installed, if not, install it
|
# Function to detect the operating system
|
||||||
if ! command -v sudo &> /dev/null; then
|
detect_os() {
|
||||||
echo "sudo is not installed. Installing sudo..."
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
if command -v apt &> /dev/null; then
|
echo "macos"
|
||||||
apt update && apt install -y sudo
|
elif [[ -f /etc/os-release ]]; then
|
||||||
elif command -v pacman &> /dev/null; then
|
. /etc/os-release
|
||||||
pacman -S sudo
|
echo "$ID"
|
||||||
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
|
|
||||||
else
|
else
|
||||||
echo "Package manager not found. Please install sudo manually."
|
echo "unknown"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
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
|
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"
|
echo -e "ZSH, Git, wget, and fontconfig are already installed\n"
|
||||||
else
|
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 "Installing required packages..."
|
||||||
|
install_packages
|
||||||
echo -e "zsh, wget, git, and fontconfig Installed\n"
|
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f ~/.gitconfig.backup ]; then
|
if [ -f ~/.gitconfig.backup ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user