link.sh (5149B)
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 5 PROGRAMS_DIR="$SCRIPT_DIR/programs" 6 SCRIPTS_DIR="$SCRIPT_DIR/scripts" 7 CONFIG_DIR="$HOME/.config" 8 9 # Detect OS and run appropriate script 10 if [[ "$(uname -s)" == "Darwin" ]]; then 11 echo "macOS detected, running macos/link.sh..." 12 exec "$SCRIPT_DIR/macos/link.sh" 13 exit 14 fi 15 16 echo "🔗 Symlinking config files..." 17 18 link_path() { 19 local src="$1" 20 local dest="$2" 21 22 echo "→ Linking $src → $dest" 23 24 if [ -L "$dest" ] || [ -d "$dest" ]; then 25 echo "→ Removing existing $dest" 26 rm -rf "$dest" 27 elif [ -e "$dest" ]; then 28 echo "→ Backing up existing $dest to $dest.bak" 29 mv "$dest" "$dest.bak" 30 fi 31 32 mkdir -p "$(dirname "$dest")" 33 ln -s "$src" "$dest" 34 echo "✅ Linked $dest" 35 } 36 37 # Autostart 38 link_path "$SCRIPT_DIR/autostart" "$HOME/.config/autostart" 39 40 # Fish 41 link_path "$PROGRAMS_DIR/fish/config.fish" "$CONFIG_DIR/fish/config.fish" 42 link_path "$PROGRAMS_DIR/fish/fish_plugins" "$CONFIG_DIR/fish/fish_plugins" 43 link_path "$PROGRAMS_DIR/fish/secrets.fish" "$CONFIG_DIR/fish/secrets.fish" 44 45 # Neovim 46 link_path "$PROGRAMS_DIR/nvim" "$CONFIG_DIR/nvim" 47 48 # Btop 49 link_path "$PROGRAMS_DIR/btop/btop.conf" "$CONFIG_DIR/btop/btop.conf" 50 51 # Git 52 link_path "$PROGRAMS_DIR/git/config" "$HOME/.gitconfig" 53 54 # GitHub CLI 55 link_path "$PROGRAMS_DIR/gh/config.yml" "$CONFIG_DIR/gh/config.yml" 56 57 # Applications 58 link_path "$PROGRAMS_DIR/applications/helium.desktop" "$HOME/.local/share/applications/helium.desktop" 59 60 # OpenCode 61 link_path "$PROGRAMS_DIR/opencode/opencode.json" "$CONFIG_DIR/opencode/opencode.json" 62 link_path "$PROGRAMS_DIR/opencode/command" "$CONFIG_DIR/opencode/command" 63 link_path "$PROGRAMS_DIR/opencode/plugin" "$CONFIG_DIR/opencode/plugin" 64 65 # Codex 66 link_path "$PROGRAMS_DIR/codex/config.toml" "$HOME/.codex/config.toml" 67 68 # SSH 69 link_path "$PROGRAMS_DIR/ssh/config" "$HOME/.ssh/config" 70 71 # Karabiner 72 link_path "$PROGRAMS_DIR/karabiner/karabiner.json" "$CONFIG_DIR/karabiner/karabiner.json" 73 link_path "$PROGRAMS_DIR/karabiner/assets" "$CONFIG_DIR/karabiner/assets" 74 75 # Zed 76 link_path "$PROGRAMS_DIR/zed/settings.jsonc" "$HOME/.var/app/dev.zed.Zed/config/zed/settings.json" 77 link_path "$PROGRAMS_DIR/zed/keymap.jsonc" "$HOME/.var/app/dev.zed.Zed/config/zed/keymap.json" 78 link_path "$SCRIPTS_DIR/zed" "$HOME/.local/bin/zed" 79 link_path "$SCRIPTS_DIR/zed-terminal" "$HOME/.local/bin/zed-terminal" 80 81 # Toshy 82 link_path "$PROGRAMS_DIR/toshy/toshy_config.py" "$CONFIG_DIR/toshy/toshy_config.py" 83 84 # Tuned profiles 85 if [ -d "$PROGRAMS_DIR/tuned" ]; then 86 echo "→ Installing tuned profiles..." 87 for profile_dir in "$PROGRAMS_DIR/tuned"/*; do 88 [ -d "$profile_dir" ] || continue 89 profile_name=$(basename "$profile_dir") 90 dest_dir="/etc/tuned/profiles/$profile_name" 91 echo " → Installing tuned profile: $profile_name" 92 if [ -L "$dest_dir" ] || [ -d "$dest_dir" ]; then 93 sudo rm -rf "$dest_dir" 94 elif [ -e "$dest_dir" ]; then 95 sudo mv "$dest_dir" "$dest_dir.bak" 96 fi 97 sudo mkdir -p "$dest_dir" 98 sudo cp -r "$profile_dir"/* "$dest_dir/" 99 find "$dest_dir" -name "*.sh" -exec sudo chmod +x {} \; 100 echo " ✅ Installed $dest_dir" 101 done 102 fi 103 104 # Modprobe configs 105 if [ -d "$PROGRAMS_DIR/modprobe" ]; then 106 echo "→ Installing modprobe configs..." 107 for config_file in "$PROGRAMS_DIR/modprobe"/*.conf; do 108 [ -f "$config_file" ] || continue 109 config_name=$(basename "$config_file") 110 dest_file="/etc/modprobe.d/$config_name" 111 echo " → Installing modprobe config: $config_name" 112 if [ -e "$dest_file" ]; then 113 sudo mv "$dest_file" "$dest_file.bak" 114 fi 115 sudo cp "$config_file" "$dest_file" 116 echo " ✅ Installed $dest_file" 117 done 118 fi 119 120 # Systemd configs (system-wide, requires sudo) 121 if [ -d "$PROGRAMS_DIR/systemd" ]; then 122 echo "→ Installing systemd configs..." 123 124 # Install logind.conf 125 if [ -f "$PROGRAMS_DIR/systemd/logind.conf" ]; then 126 echo " → Installing logind.conf" 127 if [ -e "/etc/systemd/logind.conf" ]; then 128 sudo mv "/etc/systemd/logind.conf" "/etc/systemd/logind.conf.bak" 129 fi 130 sudo cp "$PROGRAMS_DIR/systemd/logind.conf" "/etc/systemd/logind.conf" 131 echo " ✅ Installed logind.conf" 132 fi 133 134 # Install sleep.conf 135 if [ -f "$PROGRAMS_DIR/systemd/sleep.conf" ]; then 136 echo " → Installing sleep.conf" 137 if [ -e "/etc/systemd/sleep.conf" ]; then 138 sudo mv "/etc/systemd/sleep.conf" "/etc/systemd/sleep.conf.bak" 139 fi 140 sudo cp "$PROGRAMS_DIR/systemd/sleep.conf" "/etc/systemd/sleep.conf" 141 echo " ✅ Installed sleep.conf" 142 fi 143 fi 144 145 # Systemd user services 146 link_path "$PROGRAMS_DIR/systemd/user/1password-ssh-agent.service" "$CONFIG_DIR/systemd/user/1password-ssh-agent.service" 147 systemctl --user daemon-reload 148 systemctl --user enable --now g14-volume-sync.service 2>/dev/null || true 149 150 # Scripts 151 mkdir -p "$HOME/.local/bin" 152 find "$SCRIPTS_DIR" -type f -executable | while IFS= read -r script; do 153 script_name=$(basename "$script") 154 dest_file="$HOME/.local/bin/$script_name" 155 echo " → Linking script: $script_name" 156 if [ -L "$dest_file" ] || [ -f "$dest_file" ]; then 157 echo " → Removing existing $dest_file" 158 rm -f "$dest_file" 159 fi 160 ln -s "$script" "$dest_file" 161 echo " ✅ Linked $dest_file" 162 done 163 164 echo "✅ Config symlinks complete!"