.local-bin/setup_config
2023-11-23 16:42:35 -05:00

129 lines
3.5 KiB
Bash
Executable file

#!/bin/bash
# Function to check if a command is available
command_exists() {
command -v "$1" &> /dev/null
}
# Function to install dependencies based on the package manager
install_dependencies() {
case $PACKAGE_MANAGER in
"brew") $PACKAGE_MANAGER install "$@" ;;
"apt-get") sudo $PACKAGE_MANAGER install -y "$@" ;;
"yum") sudo $PACKAGE_MANAGER install -y "$@" ;;
esac
}
# Check if running on macOS or Linux
if [ "$(uname)" == "Darwin" ]; then
# Check if Homebrew is not installed
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)"
PACKAGE_MANAGER="brew"
fi
elif [ "$(uname)" == "Linux" ]; then
# Check if on Linux and use the appropriate package manager
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
fi
# Clone or initialize dotfiles repository
DOTFILES_DIR="$HOME/.dotfiles"
if [ -d "$DOTFILES_DIR" ]; then
if [ -d "$DOTFILES_DIR/.git" ]; then
echo "Updating existing dotfiles repository..."
(cd "$DOTFILES_DIR" && git pull origin master)
else
git -C "$DOTFILES_DIR" init
git -C "$DOTFILES_DIR" clone https://github.com/jfraeys/.dotfiles.git "$DOTFILES_DIR"
fi
else
echo "Creating dotfiles directory..."
mkdir -p "$DOTFILES_DIR"
git -C "$DOTFILES_DIR" init
git -C "$DOTFILES_DIR" clone https://github.com/jfraeys/.dotfiles.git "$DOTFILES_DIR"
fi
# Check and install git and other tools
if ! command_exists git; then
install_dependencies git fd ripgrep fzf tree
fi
# Check and install zsh
if ! command_exists zsh; then
install_dependencies zsh
# Clone Oh-My-Zsh if not already present
if [ ! -d "$HOME/.oh-my-zsh" ]; then
git clone https://github.com/ohmyzsh/ohmyzsh.git "$HOME/.oh-my-zsh"
fi
# Set Zsh as the default shell
chsh -s "$(command -v zsh)"
fi
# Check and install tmux
if ! command_exists tmux; then
install_dependencies tmux
fi
# Install Go
case $PACKAGE_MANAGER in
"brew")
$PACKAGE_MANAGER install go
;;
"apt-get")
sudo $PACKAGE_MANAGER install -y golang
;;
"yum")
sudo $PACKAGE_MANAGER install -y golang
;;
esac
# Install Python and pip
case $PACKAGE_MANAGER in
"brew")
$PACKAGE_MANAGER install python
;;
"apt-get")
sudo $PACKAGE_MANAGER install -y python3 python3-pip
;;
"yum")
sudo $PACKAGE_MANAGER install -y python3 python3-pip
;;
esac
# Install some common linters (uncomment if needed)
# case $PACKAGE_MANAGER in
# "brew")
# $PACKAGE_MANAGER install shellcheck
# ;;
# "apt-get")
# sudo $PACKAGE_MANAGER install -y shellcheck
# ;;
# "yum")
# sudo $PACKAGE_MANAGER install -y shellcheck
# ;;
# esac
# Create symbolic links for dotfiles
ln -s "$DOTFILES_DIR/zsh/.zshrc" ~/.zshrc
ln -s "$DOTFILES_DIR/tmux/.tmux.conf" ~/.tmux.conf
ln -s "$DOTFILES_DIR/nvim" ~/.config/nvim
# Source configurations for the current session
source ~/.zshrc
tmux source ~/.tmux.conf
# Inform the user and wait for input
echo "Zsh, Tmux, Neovim, Go, and development tools configurations applied. Press Enter to start Zsh and Tmux."
read -r
# Start Zsh and Tmux
zsh