-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·262 lines (237 loc) · 5.89 KB
/
setup.sh
File metadata and controls
executable file
·262 lines (237 loc) · 5.89 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
# setup.sh - Unified setup, deploy, and init script for GNU Stow dotfiles
set -euo pipefail
# Variables
DOTFILES_DIR="$HOME/dotfiles"
REMOTE_URL="https://github.com/Cyber-Syntax/dotfiles.git"
CONFIG_DIRS=(nvim zsh kitty tmux autotarcompress auto-penguin-setup alacritty hypr i3 polybar dunst picom waybar qtile auto-cpufreq gammastep starship MangoHud gtk-2.0 gtk-3.0 gtk-4.0 xdg-desktop-portal backintime gh btop sway doom)
CONFIG_FILES=(bashrc zshenv gitconfig markdownlint prettierrc)
# Help message
show_help() {
cat <<EOF
Usage: setup.sh [OPTION]
Options:
--move Run move: preview and move files to dotfiles structure
--stow Run stow: preview and apply stow symlinks
--clean Clean up backup files
--git (Experimental) Initialize the dotfiles Git repository
--help Show this help message
EOF
}
# Dry-move preview function
preview_move() {
echo "[+] Preview of files to be moved during setup:"
echo "[+] Dotfiles directory: $DOTFILES_DIR"
for dir in "${CONFIG_DIRS[@]}"; do
SRC="$HOME/.config/$dir"
DEST="$DOTFILES_DIR/dot-config/$dir"
if [ -L "$SRC" ]; then
echo " ✗ $SRC -> $DEST (already a symlink, likely stowed)"
elif [ -d "$SRC" ]; then
echo " ✓ $SRC -> $DEST"
else
echo " ✗ $SRC -> $DEST (source not found)"
fi
done
for file in "${CONFIG_FILES[@]}"; do
SRC="$HOME/.$file"
DEST="$DOTFILES_DIR/dot-$file"
if [ -L "$SRC" ]; then
echo " ✗ $SRC -> $DEST (already a symlink, likely stowed)"
elif [ -f "$SRC" ]; then
echo " ✓ $SRC -> $DEST"
else
echo " ✗ $SRC -> $DEST (source not found)"
fi
done
}
# Confirm before setup
confirm_setup() {
printf "Do you want to proceed with moving files to dotfiles structure? [y/N]: "
read -r answer
case "$answer" in
[Yy]*)
setup
;;
*)
echo "[!] Move aborted by user."
exit 1
;;
esac
}
# Setup function: move user configs into dotfiles repo structure
setup() {
echo "[+] Moving files to dotfiles directory structure..."
# Create dotfiles directory if it doesn't exist
if [ ! -d "$DOTFILES_DIR" ]; then
echo "[+] Creating dotfiles directory $DOTFILES_DIR"
mkdir -p "$DOTFILES_DIR"
fi
mkdir -p "$DOTFILES_DIR/dot-config"
for dir in "${CONFIG_DIRS[@]}"; do
SRC="$HOME/.config/$dir"
DEST="$DOTFILES_DIR/dot-config/$dir"
if [ -L "$SRC" ]; then
echo "[!] Skipping $SRC (already a symlink, likely stowed—unstow first.)"
elif [ -d "$SRC" ]; then
echo "[+] backing up $SRC"
cp -r "$SRC" "$SRC.backup"
echo "[+] moving $SRC to $DEST"
mv "$SRC" "$DEST"
else
echo "[!] Skipping $SRC (not found)"
fi
done
for file in "${CONFIG_FILES[@]}"; do
SRC="$HOME/.$file"
DEST="$DOTFILES_DIR/dot-$file"
if [ -L "$SRC" ]; then
echo "[!] Skipping $SRC (already a symlink, likely stowed—unstow first.)"
elif [ -f "$SRC" ]; then
echo "[+] backing up $SRC"
cp "$SRC" "$SRC.backup"
echo "[+] moving $SRC to $DEST"
mv "$SRC" "$DEST"
else
echo "[!] Skipping $SRC (not found)"
fi
done
echo "[+] Writing .stowrc"
#TESTING: globbing home in purpose
# This makes --target='home/$USER'
# Mine is `--target='/home/developer'`
cat >"$DOTFILES_DIR/.stowrc" <<EOF
--dotfiles
--target='$HOME'
--ignore=.stowrc
--ignore=setup.sh
--ignore=.stfolder
--ignore=.stignore
--ignore=stversions
--ignore=docs
--ignore=plans
EOF
}
# Dry-run function: Shows what will be symlinked
dry_run() {
echo "[+] Running dry-run..."
cd "$DOTFILES_DIR"
stow -n -v .
}
# Deploy function: Actually perform symlinking
deploy() {
echo "[+] Stowing dotfiles..."
cd "$DOTFILES_DIR"
stow .
echo "[+] Stowing complete."
}
# Confirm before deploy
confirm_deploy() {
printf "Do you want to proceed with actual stowing? [y/N]: "
read -r answer
case "$answer" in
[Yy]*)
deploy
;;
*)
echo "[!] Stowing aborted by user."
exit 1
;;
esac
}
# Cleanup backups function
cleanup_backups() {
echo "[+] Removing backup files..."
for dir in "${CONFIG_DIRS[@]}"; do
BACKUP="$HOME/.config/$dir.backup"
if [ -e "$BACKUP" ]; then
echo "[+] Removing $BACKUP"
rm -rf "$BACKUP"
fi
done
for file in "${CONFIG_FILES[@]}"; do
BACKUP="$HOME/.$file.backup"
if [ -e "$BACKUP" ]; then
echo "[+] Removing $BACKUP"
rm -f "$BACKUP"
fi
done
echo "[+] Cleanup complete."
}
# Dry-cleanup preview function
preview_cleanup() {
echo "[+] Preview of backup files to be removed:"
echo "[+] Checking for backups in $HOME"
for dir in "${CONFIG_DIRS[@]}"; do
BACKUP="$HOME/.config/$dir.backup"
if [ -e "$BACKUP" ]; then
echo " ✓ $BACKUP"
fi
done
for file in "${CONFIG_FILES[@]}"; do
BACKUP="$HOME/.$file.backup"
if [ -e "$BACKUP" ]; then
echo " ✓ $BACKUP"
fi
done
}
# Confirm before cleanup
confirm_cleanup() {
preview_cleanup
printf "Do you want to proceed with removing backup files? [y/N]: "
read -r answer
case "$answer" in
[Yy]*)
cleanup_backups
;;
*)
echo "[!] Cleanup aborted by user."
exit 1
;;
esac
}
# Git init function: Initializes dotfiles repo
init_git() {
echo "[+] Initializing Git repo in $DOTFILES_DIR"
cd "$DOTFILES_DIR"
if [ ! -d .git ]; then
echo "# dotfiles" >README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin "$REMOTE_URL"
git push -u origin main || echo "[!] Push failed (repo may already exist)"
else
echo "[+] Git repo already initialized."
fi
}
# Main logic: parse arguments
if [ $# -eq 0 ]; then
show_help
exit 0
fi
case "$1" in
--move)
preview_move
confirm_setup
;;
--stow)
dry_run
confirm_deploy
;;
--clean)
confirm_cleanup
;;
--git)
init_git
;;
--help)
show_help
;;
*)
echo "[!] Unknown option: $1"
show_help
exit 1
;;
esac