-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·88 lines (70 loc) · 2.47 KB
/
setup.sh
File metadata and controls
executable file
·88 lines (70 loc) · 2.47 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
#!/bin/bash
# Exit on any error
set -e
echo "Starting dotfiles setup..."
# --- Installations ---
# Install Rust
if ! command -v rustc &> /dev/null; then
echo "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
else
echo "Rust is already installed."
fi
# Install NVM and NodeJS
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
echo "Installing NVM..."
# Using a recent, valid version of the NVM install script
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
else
echo "NVM is already installed."
fi
# Source NVM to use it in the current script session
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install latest LTS Node.js and set it as default
if ! command -v node &> /dev/null; then
echo "Installing latest LTS version of NodeJS..."
nvm install --lts
nvm use --lts
nvm alias default 'lts/*'
else
echo "NodeJS is already installed."
fi
# Install oh-my-zsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
echo "Installing oh-my-zsh..."
# The empty "" is for passing arguments to the install script inside sh -c
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
else
echo "oh-my-zsh is already installed."
fi
# --- Configuration Backup and Symlinking ---
echo "Backing up existing configurations and creating symlinks..."
# Create a timestamped backup directory
BACKUP_DIR="$HOME/dotfiles_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
echo "Backup directory created at $BACKUP_DIR"
# Get the absolute path of the directory where the script is located
DOTFILES_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# List of configs to symlink
# format: "source_in_dotfiles;target_in_home"
CONFIGS=(
".zshrc;$HOME/.zshrc"
".config/kitty;$HOME/.config/kitty"
".config/zed;$HOME/.config/zed"
)
for config in "${CONFIGS[@]}"; do
# Safely read source and destination
IFS=';' read -r src dest <<< "$config"
# If target exists (as file or symlink), move it to the backup directory
if [ -e "$dest" ] || [ -L "$dest" ]; then
echo "Backing up '$dest' to '$BACKUP_DIR/'"
mv "$dest" "$BACKUP_DIR/"
fi
# Create the symlink from the dotfiles directory to the home directory
echo "Creating symlink for '$src' at '$dest'"
ln -s "$DOTFILES_DIR/$src" "$dest"
done
echo ""
echo "Setup complete!"
echo "Please restart your shell for all changes to take effect."