-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·238 lines (198 loc) · 7.48 KB
/
setup.sh
File metadata and controls
executable file
·238 lines (198 loc) · 7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
#
# Linux Setup Script for rcfiles
# Run this script on a fresh Linux installation to set up your environment
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ Linux Development Environment Setup ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[OK]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; }
######################################################################
# Detect package manager
######################################################################
if command -v apt &>/dev/null; then
PKG_MANAGER="apt"
PKG_UPDATE="sudo apt update"
PKG_INSTALL="sudo apt install -y"
elif command -v dnf &>/dev/null; then
PKG_MANAGER="dnf"
PKG_UPDATE="sudo dnf check-update || true"
PKG_INSTALL="sudo dnf install -y"
elif command -v yum &>/dev/null; then
PKG_MANAGER="yum"
PKG_UPDATE="sudo yum check-update || true"
PKG_INSTALL="sudo yum install -y"
elif command -v pacman &>/dev/null; then
PKG_MANAGER="pacman"
PKG_UPDATE="sudo pacman -Sy"
PKG_INSTALL="sudo pacman -S --noconfirm"
else
error "Could not detect package manager (apt, dnf, yum, or pacman)"
exit 1
fi
info "Detected package manager: $PKG_MANAGER"
######################################################################
# Install packages
######################################################################
info "Updating package lists..."
eval "$PKG_UPDATE"
info "Installing essential packages..."
# Package names that are consistent across distros
PACKAGES=(
zsh
vim
git
curl
wget
htop
tree
tmux
most
)
# Install FZF from git since package versions are often outdated
for pkg in "${PACKAGES[@]}"; do
info "Installing $pkg..."
eval "$PKG_INSTALL $pkg" || warn "Failed to install $pkg"
done
success "Base packages installed"
######################################################################
# Install FZF
######################################################################
if [[ ! -d "$HOME/.fzf" ]]; then
info "Installing fzf from git..."
git clone --depth 1 https://github.com/junegunn/fzf.git "$HOME/.fzf"
"$HOME/.fzf/install" --all --no-bash --no-fish
success "FZF installed"
else
success "FZF already installed"
fi
######################################################################
# Install Zplug
######################################################################
if [[ ! -d "$HOME/.zplug" ]]; then
info "Installing zplug..."
git clone https://github.com/zplug/zplug "$HOME/.zplug"
success "Zplug installed"
else
success "Zplug already installed"
fi
######################################################################
# Copy configuration files
######################################################################
info "Installing configuration files..."
# Backup existing files
backup_file() {
if [[ -e "$1" && ! -L "$1" ]]; then
backup="$1.backup.$(date +%Y%m%d_%H%M%S)"
warn "Backing up existing $1 to $backup"
mv "$1" "$backup"
fi
}
# Install dotfiles
install_dotfile() {
local src="$1"
local dest="$2"
if [[ -e "$SCRIPT_DIR/$src" ]]; then
backup_file "$dest"
cp -r "$SCRIPT_DIR/$src" "$dest"
success "Installed $src to $dest"
else
warn "Source file $src not found, skipping"
fi
}
install_dotfile ".zshrc" "$HOME/.zshrc"
install_dotfile ".vimrc" "$HOME/.vimrc"
install_dotfile ".vim" "$HOME/.vim"
install_dotfile ".screenrc" "$HOME/.screenrc"
######################################################################
# Set zsh as default shell
######################################################################
ZSH_PATH="$(which zsh)"
if [[ "$SHELL" != "$ZSH_PATH" ]]; then
info "Setting zsh as default shell..."
chsh -s "$ZSH_PATH"
success "Default shell changed to zsh"
else
success "zsh is already the default shell"
fi
######################################################################
# Git configuration
######################################################################
info "Configuring git..."
# Set up useful git aliases
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
# Prompt for user info if not set
if [[ -z "$(git config --global user.name)" ]]; then
echo ""
read -p "Enter your Git name: " git_name
git config --global user.name "$git_name"
fi
if [[ -z "$(git config --global user.email)" ]]; then
read -p "Enter your Git email: " git_email
git config --global user.email "$git_email"
fi
# Sensible defaults
git config --global init.defaultBranch main
git config --global pull.rebase false
git config --global core.editor vim
git config --global color.ui auto
success "Git configured"
######################################################################
# Create useful directories
######################################################################
info "Creating directories..."
mkdir -p "$HOME/bin"
mkdir -p "$HOME/.local/bin"
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
mkdir -p "$HOME/.zsh/cache"
success "Directories created"
######################################################################
# SSH key setup
######################################################################
if [[ ! -f "$HOME/.ssh/id_ed25519" && ! -f "$HOME/.ssh/id_rsa" ]]; then
echo ""
read -p "Generate SSH key? [y/N]: " gen_ssh
if [[ "$gen_ssh" =~ ^[Yy]$ ]]; then
read -p "Enter email for SSH key: " ssh_email
ssh-keygen -t ed25519 -C "$ssh_email"
success "SSH key generated"
echo ""
info "Add this public key to GitHub/GitLab:"
echo ""
cat "$HOME/.ssh/id_ed25519.pub"
echo ""
fi
else
success "SSH key already exists"
fi
######################################################################
# Done!
######################################################################
echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ Setup Complete! 🎉 ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
info "Please restart your terminal or run: source ~/.zshrc"
echo ""
info "Optional: Create ~/.zshrc.local for machine-specific settings"
echo ""