Files
code-tools/tf/scripts/dev-tools.sh

174 lines
5.9 KiB
Bash
Executable File

#!/bin/bash
set -e
# Set proper locale for emoji and UTF-8 support
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
echo "🔧 Installing development extensions and tools..."
# Function to safely install packages with error handling
safe_install() {
local package_name="$1"
local install_command="$2"
local fallback_command="$3"
echo "📦 Installing $package_name..."
if eval "$install_command"; then
echo "$package_name installed successfully"
return 0
else
echo "⚠️ $package_name installation failed"
if [ -n "$fallback_command" ]; then
echo "🔄 Trying fallback installation..."
eval "$fallback_command" || echo "❌ Fallback also failed for $package_name"
fi
return 1
fi
}
# Ensure we're running as root for system packages
if [ "$EUID" -ne 0 ]; then
echo "This script needs to run as root for system package installation"
exit 1
fi
echo "📦 Installing additional CLI tools..."
# Ensure curl is available first
type -p curl >/dev/null || (apt-get update && apt-get install curl -y)
# Function to install various development tools
install_development_tools() {
echo "🛠️ Installing development utilities..."
# GitHub CLI
if ! command -v gh &> /dev/null; then
echo "📥 Installing GitHub CLI..."
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
apt-get update
apt-get install gh -y
fi
# Docker Compose (if not already installed)
if ! command -v docker-compose &> /dev/null; then
echo "🐳 Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
fi
# Lazygit for better git UI
if ! command -v lazygit &> /dev/null; then
echo "🌿 Installing lazygit..."
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v*([^"]+)".*/\1/')
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf lazygit.tar.gz lazygit
install lazygit /usr/local/bin
rm lazygit.tar.gz lazygit
fi
# btop for system monitoring (fallback to htop if btop unavailable)
if ! command -v btop &> /dev/null; then
echo "📊 Installing btop..."
if apt-get install btop -y 2>/dev/null; then
echo "✅ btop installed successfully"
else
echo "⚠️ btop not available, installing htop as fallback..."
apt-get install htop -y
fi
fi
# fd-find for better file searching
if ! command -v fd &> /dev/null; then
echo "🔍 Installing fd-find..."
apt-get install fd-find -y
# Create symlink for easier usage
ln -sf /usr/bin/fdfind /usr/local/bin/fd
fi
# ripgrep for better text searching
if ! command -v rg &> /dev/null; then
echo "🔎 Installing ripgrep..."
apt-get install ripgrep -y
fi
# bat for better cat with syntax highlighting
if ! command -v bat &> /dev/null; then
echo "🦇 Installing bat..."
apt-get install bat -y
# Create symlink for easier usage
ln -sf /usr/bin/batcat /usr/local/bin/bat
fi
# eza for better ls (modern replacement for exa)
if ! command -v eza &> /dev/null; then
echo "📁 Installing eza..."
if curl -L "https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz" | tar xz -C /usr/local/bin 2>/dev/null; then
echo "✅ eza installed successfully"
else
echo "⚠️ eza installation failed, skipping..."
fi
fi
}
# Install all development tools
install_development_tools
# Switch to coder user for user-specific installations
echo "👤 Setting up user-specific tools..."
# Check if coder user exists, if not use the first non-root user or create coder user
CODER_USER=""
if id coder >/dev/null 2>&1; then
CODER_USER="coder"
else
# Try to find existing non-root user
EXISTING_USER=$(getent passwd | awk -F: '$3 >= 1000 && $3 != 65534 {print $1; exit}')
if [ -n "$EXISTING_USER" ]; then
CODER_USER="$EXISTING_USER"
echo "🔄 Using existing user: $CODER_USER"
else
# Create coder user if no suitable user exists
echo "👤 Creating coder user..."
useradd -m -s /bin/bash coder
CODER_USER="coder"
fi
fi
echo "👤 Setting up tools for user: $CODER_USER"
su - "$CODER_USER" << 'USER_SETUP_END'
# Add useful aliases to .bashrc if not already present
if ! grep -q "# Development tools aliases" ~/.bashrc; then
cat >> ~/.bashrc << 'ALIASES_END'
# Development tools aliases
alias cat='bat'
alias ls='eza'
alias ll='eza -la'
alias la='eza -la'
alias find='fd'
alias grep='rg'
alias git-ui='lazygit'
alias top='btop'
ALIASES_END
fi
# Install tldr for better man pages
if ! command -v tldr &> /dev/null; then
npm install -g tldr
fi
# Install fkill for better process management
if ! command -v fkill &> /dev/null; then
npm install -g fkill-cli
fi
echo "✅ Development tools installed and configured!"
USER_SETUP_END
echo "🎉 All development tools installed successfully!"
echo "💡 Available tools: gh, docker-compose, lazygit, btop, fd, rg, bat, eza, tldr, fkill"
echo "💡 Aliases configured: cat→bat, ls→eza, find→fd, grep→rg, git-ui→lazygit, top→btop"