1
0
Files
dotfiles/install.sh

47 lines
1.3 KiB
Bash

#!/bin/bash
set -euo pipefail
DOTFILES_REPO="https://gitea.purpleraft.com/ryan/dotfiles"
DOTFILES_DIR="$HOME/.dotfiles"
# Check if stow is installed
if ! command -v stow &> /dev/null; then
echo "❌ GNU Stow is not installed. Please install it first:"
echo " Ubuntu/Debian: sudo apt install stow"
echo " macOS: brew install stow"
echo " Or use the alias: install_stow"
exit 1
fi
# Clone or update the repo
if [ -d "$DOTFILES_DIR/.git" ]; then
echo "Updating existing dotfiles repo..."
git -C "$DOTFILES_DIR" pull --quiet
else
echo "Cloning dotfiles into $DOTFILES_DIR..."
git clone "$DOTFILES_REPO" "$DOTFILES_DIR"
fi
# Change to parent directory of dotfiles for stow to work correctly
cd "$HOME"
# Backup existing files that would conflict with stow
for file in .bashrc .bash_aliases .inputrc .gitconfig; do
if [ -f "$HOME/$file" ] && [ ! -L "$HOME/$file" ]; then
echo "⚠️ Backing up existing file: $HOME/$file -> $HOME/${file}.bak"
mv "$HOME/$file" "$HOME/${file}.bak"
fi
done
# Use stow to create symlinks
echo "🔗 Using Stow to symlink dotfiles..."
stow -d "$HOME" -t "$HOME" .dotfiles
# Optionally source the new bashrc
if [[ $- == *i* ]]; then
echo "Reloading Bash config..."
source ~/.bashrc
fi
echo "✅ Dotfiles install complete."