From f533dd163d68e2237c2def574e2d8514943bc160 Mon Sep 17 00:00:00 2001 From: Niteshift User Date: Thu, 11 Sep 2025 20:51:43 +0000 Subject: [PATCH 1/2] Add niteshift-setup.sh for automated environment setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This script automates development environment setup including: - Installing dependencies (Homebrew/apt packages) - Setting up services (Redis, PostgreSQL) - Configuring shell environments - Installing development tools (Node.js, Python packages) - Linking dotfiles configurations The script detects the OS and installs appropriate packages, starts required services, and sets up a complete development environment ready for use with Niteshift. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- niteshift-setup.sh | 393 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 393 insertions(+) create mode 100755 niteshift-setup.sh diff --git a/niteshift-setup.sh b/niteshift-setup.sh new file mode 100755 index 0000000..b51e962 --- /dev/null +++ b/niteshift-setup.sh @@ -0,0 +1,393 @@ +#!/bin/bash + +# Niteshift Development Environment Setup Script +# This script automates the setup of a development environment for jonshea/config-files + +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Logging functions +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Detect OS +detect_os() { + if [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "linux" + else + echo "unknown" + fi +} + +# Install dependencies based on OS +install_dependencies() { + local os=$(detect_os) + + log_info "Installing dependencies for $os..." + + case $os in + "macos") + install_macos_dependencies + ;; + "linux") + install_linux_dependencies + ;; + *) + log_warning "Unknown OS type: $OSTYPE. Skipping dependency installation." + ;; + esac +} + +install_macos_dependencies() { + log_info "Installing Homebrew and packages..." + + # Install Homebrew if not present + if ! command_exists brew; then + log_info "Installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + # Add Homebrew to PATH for this session + if [[ -f "/opt/homebrew/bin/brew" ]]; then + eval "$(/opt/homebrew/bin/brew shellenv)" + elif [[ -f "/usr/local/bin/brew" ]]; then + eval "$(/usr/local/bin/brew shellenv)" + fi + fi + + # Update brew and install essential packages + brew update + + # Essential development tools + local packages=( + "git" + "zsh" + "zsh-completions" + "tmux" + "wget" + "curl" + "fzf" + "fd" + "ripgrep" + "python" + "pyenv" + "node" + "yarn" + "redis" + "postgresql" + ) + + for package in "${packages[@]}"; do + if ! brew list "$package" &>/dev/null; then + log_info "Installing $package..." + brew install "$package" || log_warning "Failed to install $package" + else + log_info "$package is already installed" + fi + done + + # Install cask applications + local cask_apps=( + "visual-studio-code" + "iterm2" + "docker" + ) + + for app in "${cask_apps[@]}"; do + if ! brew list --cask "$app" &>/dev/null; then + log_info "Installing $app..." + brew install --cask "$app" || log_warning "Failed to install $app" + else + log_info "$app is already installed" + fi + done +} + +install_linux_dependencies() { + log_info "Installing Linux packages..." + + # Detect package manager + if command_exists apt-get; then + sudo apt-get update + sudo apt-get install -y \ + git \ + zsh \ + tmux \ + wget \ + curl \ + build-essential \ + python3 \ + python3-pip \ + nodejs \ + npm \ + redis-server \ + postgresql \ + postgresql-contrib \ + ripgrep \ + fd-find + + # Install fzf manually on Ubuntu/Debian + if ! command_exists fzf; then + git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf + ~/.fzf/install --all + fi + + elif command_exists yum; then + sudo yum update -y + sudo yum install -y \ + git \ + zsh \ + tmux \ + wget \ + curl \ + python3 \ + python3-pip \ + nodejs \ + npm \ + redis \ + postgresql \ + postgresql-contrib + + elif command_exists dnf; then + sudo dnf update -y + sudo dnf install -y \ + git \ + zsh \ + tmux \ + wget \ + curl \ + python3 \ + python3-pip \ + nodejs \ + npm \ + redis \ + postgresql \ + postgresql-contrib + else + log_warning "No supported package manager found. Please install dependencies manually." + fi +} + +# Setup shell configurations +setup_shell_configs() { + log_info "Setting up shell configurations..." + + local configs_dir="$(pwd)" + local config_files=(".zshrc" ".emacs" ".irbrc" ".gitconfig" "functions.el" ".bash_completion" ".gemrc" ".ripgreprc" ".bashrc" ".bash_aliases" ".inputrc" ".screenrc" ".sqliterc") + + for file in "${config_files[@]}"; do + if [[ -f "${configs_dir}/${file}" ]]; then + log_info "Linking $file..." + ln -sf "${configs_dir}/${file}" ~/"${file}" + fi + done + + # Handle DefaultKeyBinding.dict for macOS + if [[ $(detect_os) == "macos" && -f "${configs_dir}/DefaultKeyBinding.dict" ]]; then + mkdir -p ~/Library/KeyBindings + ln -sf "${configs_dir}/DefaultKeyBinding.dict" ~/Library/KeyBindings/DefaultKeyBinding.dict + fi + + # Set zsh as default shell if not already + if command_exists zsh && [[ "$SHELL" != */zsh ]]; then + log_info "Setting zsh as default shell..." + if ! grep -q "$(which zsh)" /etc/shells; then + echo "$(which zsh)" | sudo tee -a /etc/shells + fi + chsh -s "$(which zsh)" + fi +} + +# Setup development services +setup_services() { + log_info "Setting up development services..." + + # Redis + if command_exists redis-server; then + log_info "Starting Redis..." + case $(detect_os) in + "macos") + brew services start redis || log_warning "Failed to start Redis" + ;; + "linux") + if systemctl is-active --quiet redis; then + log_info "Redis is already running" + else + sudo systemctl enable redis + sudo systemctl start redis || log_warning "Failed to start Redis" + fi + ;; + esac + fi + + # PostgreSQL + if command_exists postgres || command_exists psql; then + log_info "Setting up PostgreSQL..." + case $(detect_os) in + "macos") + brew services start postgresql || log_warning "Failed to start PostgreSQL" + ;; + "linux") + if systemctl is-active --quiet postgresql; then + log_info "PostgreSQL is already running" + else + sudo systemctl enable postgresql + sudo systemctl start postgresql || log_warning "Failed to start PostgreSQL" + fi + ;; + esac + + # Create development database if it doesn't exist + if command_exists createdb; then + createdb development 2>/dev/null || log_info "Development database already exists or couldn't be created" + fi + fi +} + +# Setup Node.js environment +setup_node_environment() { + log_info "Setting up Node.js environment..." + + # Install global npm packages commonly used in development + if command_exists npm; then + local global_packages=( + "yarn" + "nodemon" + "pm2" + "@nestjs/cli" + "create-react-app" + "typescript" + "ts-node" + ) + + for package in "${global_packages[@]}"; do + if ! npm list -g "$package" &>/dev/null; then + log_info "Installing global package: $package" + npm install -g "$package" || log_warning "Failed to install $package" + fi + done + fi +} + +# Setup Python environment +setup_python_environment() { + log_info "Setting up Python environment..." + + if command_exists pyenv; then + # Install latest stable Python version + local python_version="3.11.5" + if ! pyenv versions | grep -q "$python_version"; then + log_info "Installing Python $python_version via pyenv..." + pyenv install "$python_version" || log_warning "Failed to install Python $python_version" + pyenv global "$python_version" + fi + fi + + # Install common Python packages + if command_exists pip3; then + local python_packages=( + "virtualenv" + "pipenv" + "black" + "flake8" + "pytest" + "requests" + "flask" + "django" + ) + + for package in "${python_packages[@]}"; do + pip3 install "$package" || log_warning "Failed to install Python package: $package" + done + fi +} + +# Initialize database schemas (if any exist) +initialize_schemas() { + log_info "Checking for database schema files..." + + # Look for SQL files in common locations + local schema_files=( + "schema.sql" + "db/schema.sql" + "database/schema.sql" + "migrations/*.sql" + ) + + for pattern in "${schema_files[@]}"; do + if ls $pattern 1>/dev/null 2>&1; then + log_info "Found schema files matching: $pattern" + if command_exists psql; then + log_info "Run the following to initialize your database:" + echo "psql -d development -f " + fi + fi + done +} + +# Run any local setup script +run_local_setup() { + if [[ -f "setup-local.sh" ]]; then + log_info "Running local setup script..." + source setup-local.sh + fi +} + +# Main setup function +main() { + log_info "Starting Niteshift development environment setup..." + log_info "Working directory: $(pwd)" + + # Ensure we're in the right directory + if [[ ! -f ".zshrc" ]] || [[ ! -f ".gitconfig" ]]; then + log_error "This doesn't appear to be the config-files repository root." + log_error "Please run this script from the repository root directory." + exit 1 + fi + + # Run setup steps + install_dependencies + setup_shell_configs + setup_services + setup_node_environment + setup_python_environment + initialize_schemas + run_local_setup + + log_success "Niteshift development environment setup complete!" + log_info "Please restart your terminal or run 'source ~/.zshrc' to load the new configuration." + log_info "" + log_info "Services started:" + log_info " - Redis (if installed)" + log_info " - PostgreSQL (if installed)" + log_info "" + log_info "To customize this setup for your local environment, create a 'setup-local.sh' file." +} + +# Run main function +main "$@" \ No newline at end of file From 62c19fdeaefa9c7e0fb8dd2c127602ebfc0546c0 Mon Sep 17 00:00:00 2001 From: Niteshift User Date: Thu, 11 Sep 2025 20:56:06 +0000 Subject: [PATCH 2/2] Use Brewfile for macOS dependency management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Brewfile with all macOS dependencies and cask applications - Update niteshift-setup.sh to use 'brew bundle install' instead of hardcoded packages - Simplify macOS dependency installation logic - Add Brewfile validation to startup checks This makes dependency management more maintainable and follows Homebrew best practices. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- Brewfile | 40 +++++++++++++++++++++++++++++++++ niteshift-setup.sh | 55 +++++++++------------------------------------- 2 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 Brewfile diff --git a/Brewfile b/Brewfile new file mode 100644 index 0000000..77747b6 --- /dev/null +++ b/Brewfile @@ -0,0 +1,40 @@ +# Brewfile for Niteshift development environment +# Use with: brew bundle install + +# Taps +tap "homebrew/bundle" +tap "homebrew/cask" + +# Essential development tools +brew "git" +brew "zsh" +brew "zsh-completions" +brew "tmux" +brew "wget" +brew "curl" + +# Search and file tools +brew "fzf" +brew "fd" +brew "ripgrep" + +# Programming languages and runtime +brew "python" +brew "pyenv" +brew "node" +brew "yarn" + +# Databases and services +brew "redis" +brew "postgresql" + +# Additional development utilities +brew "jq" +brew "htop" +brew "tree" +brew "watch" + +# Cask applications +cask "visual-studio-code" +cask "iterm2" +cask "docker" \ No newline at end of file diff --git a/niteshift-setup.sh b/niteshift-setup.sh index b51e962..1fc7d4f 100755 --- a/niteshift-setup.sh +++ b/niteshift-setup.sh @@ -80,52 +80,16 @@ install_macos_dependencies() { fi fi - # Update brew and install essential packages + # Update brew brew update - # Essential development tools - local packages=( - "git" - "zsh" - "zsh-completions" - "tmux" - "wget" - "curl" - "fzf" - "fd" - "ripgrep" - "python" - "pyenv" - "node" - "yarn" - "redis" - "postgresql" - ) - - for package in "${packages[@]}"; do - if ! brew list "$package" &>/dev/null; then - log_info "Installing $package..." - brew install "$package" || log_warning "Failed to install $package" - else - log_info "$package is already installed" - fi - done - - # Install cask applications - local cask_apps=( - "visual-studio-code" - "iterm2" - "docker" - ) - - for app in "${cask_apps[@]}"; do - if ! brew list --cask "$app" &>/dev/null; then - log_info "Installing $app..." - brew install --cask "$app" || log_warning "Failed to install $app" - else - log_info "$app is already installed" - fi - done + # Check if Brewfile exists and use it + if [[ -f "Brewfile" ]]; then + log_info "Installing packages from Brewfile..." + brew bundle install --file=Brewfile || log_warning "Some packages from Brewfile failed to install" + else + log_warning "Brewfile not found, skipping package installation" + fi } install_linux_dependencies() { @@ -364,9 +328,10 @@ main() { log_info "Working directory: $(pwd)" # Ensure we're in the right directory - if [[ ! -f ".zshrc" ]] || [[ ! -f ".gitconfig" ]]; then + if [[ ! -f ".zshrc" ]] || [[ ! -f ".gitconfig" ]] || [[ ! -f "Brewfile" ]]; then log_error "This doesn't appear to be the config-files repository root." log_error "Please run this script from the repository root directory." + log_error "Required files: .zshrc, .gitconfig, Brewfile" exit 1 fi