Repository navigation
Expand file tree
/
Copy pathrsync
More file actions
executable file
·166 lines (152 loc) · 4.22 KB
/
Copy pathrsync
File metadata and controls
executable file
·166 lines (152 loc) · 4.22 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
#!/bin/bash
#
# This script intelligently syncs both system and user-level config files.
# It automatically elevates permissions with sudo (using x11-ssh-askpass if available).
set -e
# --- Auto-Elevation & Askpass Detection ---
if [[ $EUID -ne 0 ]]; then
ASKPASS_BIN="${SUDO_ASKPASS:-/usr/lib/ssh/x11-ssh-askpass}"
# If in a GUI session and askpass binary exists, use GUI prompt (-A)
if [[ -n "${DISPLAY:-$WAYLAND_DISPLAY}" ]] && [[ -x "$ASKPASS_BIN" ]]; then
export SUDO_ASKPASS="$ASKPASS_BIN"
exec sudo -A "$0" "$@"
else
# Otherwise, fall back to standard terminal sudo prompt
exec sudo "$0" "$@"
fi
fi
# --- User & Directory Detection ---
if [ -n "$SUDO_USER" ]; then
ORIGINAL_USER="$SUDO_USER"
HOME_DIR=$(getent passwd "$SUDO_USER" | cut -d: -f6)
else
ORIGINAL_USER="$USER"
HOME_DIR="$HOME"
fi
echo "🚀 Running as root, syncing files for user '$ORIGINAL_USER' from '$HOME_DIR'"
# --- Configuration ---
REPO_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
EXCLUDE_ARRAY=(--exclude='*.dat' --exclude='.git')
# --- ### List of Targets to Sync ### ---
# --- 1. System-level files and directories (ABSOLUTE PATHS) ---
SYSTEM_TARGETS=(
"/etc/fstab"
"/etc/environment"
"/etc/pacman.conf"
"/etc/sudoers"
"/etc/nftables.conf"
"/etc/i3"
"/etc/i3status.conf"
"/etc/hostname"
"/etc/locale.gen"
"/etc/vconsole.conf"
"/etc/keyd" # Sync the whole directory
"/usr/bin/keyd-application-mapper"
"/usr/bin/keyd-application-mapper.bak"
"/etc/sudoers.d"
"/usr/local/bin"
)
# --- 2. Home directory files and directories (RELATIVE PATHS) ---
HOME_TARGETS=(
".zshrc"
".zsh"
".tridactylrc"
".xinitrc"
".Xmodmap"
"learn"
"wiki"
".Xresources"
".zshenv"
".tmux.conf"
".xprofile"
".zprofile"
".xbindkeysrc"
".bashrc"
".vimrc"
"scripts"
"ai/prompts"
".oh-my-zsh/custom" # Syncs only the custom folder
".tmux"
".themes"
"themes"
"Documents/Bookmarks"
".config/yazi"
".config/voxtype"
".config/ai-domains.txt"
".config/feh"
".config/skippy-xd/skippy-xd.rc"
".config/sxhkd/sxhkdrc"
".dotfiles"
".config/fzf"
".config/kanata/config.kbd"
"tool"
".config/systemd"
".emacs"
".emacs.rc"
".emacs.snippets"
".emacs.local"
".config/warpd"
".config/zk"
".ipython"
".config/alacritty"
".config/kitty"
".config/pipewire"
".config/wireplumber"
".config/mimeapps.list"
".config/picom/picom.conf"
".config/espanso"
".config/copyq/copyq.conf"
".config/autostart"
".config/gtk-3.0"
".config/Thunar"
".config/vlc"
".config/qterminal.org"
".config/mpv"
".config/input-remapper-2"
".config/openbox"
".config/openrazer"
".config/i3"
# ".config/lazygit"
".config/rofi"
".config/zathura"
".config/zsh"
".config/tmux-sessionizer"
".local/share/applications"
".local/share/fonts"
".local/share/zathura"
".local/scripts"
".local/bin"
)
# --- SCRIPT LOGIC ---
echo ""
echo "👤 Syncing user-level targets from $HOME_DIR..."
for target in "${HOME_TARGETS[@]}"; do
source_path="$HOME_DIR/$target"
dest_path="$REPO_DIR/$target"
if [ -f "$source_path" ]; then
echo " - Syncing file: ~/$target"
mkdir -p "$(dirname "$dest_path")"
rsync -a "$source_path" "$dest_path"
elif [ -d "$source_path" ]; then
echo " - Syncing dir: ~/$target/"
mkdir -p "$dest_path"
rsync -a --delete "${EXCLUDE_ARRAY[@]}" "$source_path/" "$dest_path/"
else
echo " - WARNING: Target ~/$target not found. Skipping."
fi
done
echo ""
echo "⚙️ Syncing system-level targets..."
for target in "${SYSTEM_TARGETS[@]}"; do
if [ -e "$target" ]; then
echo " - Syncing: $target"
rsync -aR --delete "${EXCLUDE_ARRAY[@]}" "$target" "$REPO_DIR/"
else
echo " - WARNING: Target $target not found. Skipping."
fi
done
# --- Final Permission Fix ---
echo ""
echo "🔐 Fixing repository file ownership for user '$ORIGINAL_USER'..."
chown -R "$ORIGINAL_USER":"$(id -gn "$ORIGINAL_USER")" "$REPO_DIR"
echo "✅ All done. Repository is ready for you to use."