163 lines
5.1 KiB
Bash
Executable file
163 lines
5.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Function to check if a command is available
|
|
command_exists() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
# Function to install dependencies based on the package manager
|
|
install_dependencies() {
|
|
local package_manager=$1
|
|
shift
|
|
for dependency in "$@"; do
|
|
case $package_manager in
|
|
"brew") brew install "$dependency" ;;
|
|
"apt-get") sudo apt-get install -y "$dependency" ;;
|
|
"yum") sudo yum install -y "$dependency" ;;
|
|
*) echo "Unsupported package manager: $package_manager"; exit 1 ;;
|
|
esac
|
|
INSTALLED_DEPENDENCIES+=("$dependency ($package_manager)")
|
|
done
|
|
}
|
|
|
|
# Function to install dependencies from a list
|
|
install_dependency_list() {
|
|
local package_manager=$1
|
|
local dependencies_file=$2
|
|
while IFS=, read -r dependency link_or_path; do
|
|
if [ -n "$link_or_path" ]; then
|
|
if [[ "$link_or_path" =~ ^http ]]; then
|
|
echo "Installing $dependency from $link_or_path"
|
|
case $package_manager in
|
|
"brew") brew install "$link_or_path" ;;
|
|
"apt-get") wget "$link_or_path" -O /tmp/"$dependency".deb && sudo dpkg -i /tmp/"$dependency".deb ;;
|
|
"yum") wget "$link_or_path" -O /tmp/"$dependency".rpm && sudo yum localinstall -y /tmp/"$dependency".rpm ;;
|
|
esac
|
|
else
|
|
echo "Installing $dependency from local path $link_or_path"
|
|
case $package_manager in
|
|
"brew") brew install "$link_or_path" ;;
|
|
"apt-get") sudo dpkg -i "$link_or_path" ;;
|
|
"yum") sudo yum localinstall -y "$link_or_path" ;;
|
|
esac
|
|
fi
|
|
else
|
|
echo "Installing $dependency from default repository"
|
|
install_dependencies "$package_manager" "$dependency"
|
|
fi
|
|
INSTALLED_DEPENDENCIES+=("$dependency ($package_manager)")
|
|
done < "$dependencies_file"
|
|
}
|
|
|
|
# Function to determine the package manager and set it globally
|
|
set_package_manager() {
|
|
if [ "$(uname)" == "Darwin" ]; then
|
|
if ! command_exists brew; then
|
|
echo "Homebrew is not installed. Installing Homebrew..."
|
|
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
fi
|
|
PACKAGE_MANAGER="brew"
|
|
elif [ "$(uname)" == "Linux" ]; then
|
|
if command_exists apt-get; then
|
|
PACKAGE_MANAGER="apt-get"
|
|
elif command_exists yum; then
|
|
PACKAGE_MANAGER="yum"
|
|
else
|
|
echo "Unsupported package manager. Exiting."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Unsupported operating system. Exiting."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to handle auto-updates for Homebrew
|
|
handle_auto_update() {
|
|
if [ "$ENABLE_AUTO_UPDATE" == true ] && [ "$PACKAGE_MANAGER" == "brew" ]; then
|
|
brew autoupdate --start --upgrade --cleanup
|
|
fi
|
|
}
|
|
|
|
# Function to install and configure zsh
|
|
install_and_configure_zsh() {
|
|
if ! command_exists zsh; then
|
|
install_dependencies "$PACKAGE_MANAGER" zsh
|
|
if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
|
git clone https://github.com/ohmyzsh/ohmyzsh.git "$HOME/.oh-my-zsh"
|
|
fi
|
|
chsh -s "$(command -v zsh)"
|
|
fi
|
|
}
|
|
|
|
# Function to install essential tools
|
|
install_essential_tools() {
|
|
if ! command_exists git; then
|
|
install_dependencies "$PACKAGE_MANAGER" git fd ripgrep fzf tree
|
|
fi
|
|
if ! command_exists nvim; then
|
|
install_dependencies "$PACKAGE_MANAGER" neovim
|
|
fi
|
|
}
|
|
|
|
# Function to install programming languages
|
|
install_programming_languages() {
|
|
case $PACKAGE_MANAGER in
|
|
"brew") install_dependencies "$PACKAGE_MANAGER" go python ;;
|
|
"apt-get") install_dependencies "$PACKAGE_MANAGER" golang python3 python3-pip ;;
|
|
"yum") install_dependencies "$PACKAGE_MANAGER" golang python3 python3-pip ;;
|
|
esac
|
|
}
|
|
|
|
# Function to display installed dependencies
|
|
show_installed_dependencies() {
|
|
echo "Installed dependencies:"
|
|
for dependency in "${INSTALLED_DEPENDENCIES[@]}"; do
|
|
echo " - $dependency"
|
|
done
|
|
}
|
|
|
|
# Function to start Zsh if installed
|
|
start_shell() {
|
|
if command_exists zsh; then
|
|
zsh
|
|
else
|
|
echo "Zsh is not installed. Please install it manually."
|
|
fi
|
|
}
|
|
|
|
# Default values for flags
|
|
ENABLE_AUTO_UPDATE=true
|
|
DEPENDENCIES_FILE=""
|
|
ADDITIONAL_DEPENDENCIES=()
|
|
INSTALLED_DEPENDENCIES=()
|
|
|
|
# Parse command-line arguments
|
|
while [[ "$#" -gt 0 ]]; do
|
|
case $1 in
|
|
-a|--disable-auto-update) ENABLE_AUTO_UPDATE=false; shift ;;
|
|
-d|--dependencies) DEPENDENCIES_FILE="$2"; shift 2 ;;
|
|
*) ADDITIONAL_DEPENDENCIES+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
|
|
# Main script execution
|
|
set_package_manager
|
|
handle_auto_update
|
|
install_essential_tools
|
|
install_and_configure_zsh
|
|
install_programming_languages
|
|
|
|
# Install dependencies from provided file if specified
|
|
if [ -n "$DEPENDENCIES_FILE" ]; then
|
|
install_dependency_list "$PACKAGE_MANAGER" "$DEPENDENCIES_FILE"
|
|
fi
|
|
|
|
# Install additional dependencies provided as arguments
|
|
if [ "${#ADDITIONAL_DEPENDENCIES[@]}" -gt 0 ]; then
|
|
install_dependencies "$PACKAGE_MANAGER" "${ADDITIONAL_DEPENDENCIES[@]}"
|
|
fi
|
|
|
|
show_installed_dependencies
|
|
start_shell
|
|
|