1
0
Files
dotfiles/install.sh

48 lines
1.4 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
# Backup existing files that would conflict with stow (excluding SSH config - it's machine-specific)
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
# Change to dotfiles directory and use stow to create symlinks
cd "$DOTFILES_DIR"
echo "🔗 Using Stow to symlink dotfiles..."
if ! stow --adopt -t "$HOME" . 2>/dev/null; then
echo "🔄 Adopting failed, trying regular stow..."
stow -t "$HOME" .
fi
# Optionally source the new bashrc
if [[ $- == *i* ]]; then
echo "Reloading Bash config..."
source ~/.bashrc
fi
echo "✅ Dotfiles install complete."