-
Notifications
You must be signed in to change notification settings - Fork 5
/
dac
executable file
·65 lines (51 loc) · 2.36 KB
/
dac
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
#!/bin/bash
# dac -- manage dotfiles and configs
# There seem to be hundreds of tools that allow you to manage your dotfiles
# using a git repo. Sadly, all of them are missing an important feature I
# need: **do not force a change if I don't want it right now**, whether it is
# committing a change **to** the repo, or accepting a change **from** the repo
# into the local filespace.
# Note that this script runs as root, since it manages dot files for multiple
# users as well as various system config files.
# Please see https://github.com/sitaramc/notes/blob/master/dac.mkd for
# detailed documentation.
# ----------------------------------------------------------------------
set -u
die() { echo >&2 "$@"; exit 1; }
patchid() { git diff $1 $2 | git patch-id | cut -f1 -d' '; }
copy() {
# "copy f s d" is best read as "copy [file] f [from] s [to] d"
f=$1; s=$2; d=$3
user=root; [[ ${d%/*} == /home ]] && user=${d##*/}
(
cd $s
cp --parents $f $d
chown $user:$user $d/$f
echo >&2 " ===> '$f' copied from '$s' to '$d'"
)
}
while read -u 3 dest sourcedirs; do
[[ $dest =~ ^# ]] && continue
echo; echo "--- $dest ---";
for s in $sourcedirs; do
for f in $(cd $s; find . -type f|cut -c3-); do
# new file
[[ -f $dest/$f ]] || { copy $f $s $dest ; continue; }
# if the source and destination are equal, we're done
cmp --quiet $s/$f $dest/$f && continue
# is this a change we already saw and decided to leave it be?
patchid $s/$f $dest/$f | grep -q -f - .skiplist && { echo "skipping '$s/$f'"; continue; }
# let the user decide what changes to propagate in either direction
vimdiff --cmd 'set shm=O' -c 0 $s/$f $dest/$f
# are they equal *now* ?
cmp --quiet $s/$f $dest/$f && continue
# nope; user left some differences. Compute and store patch-id so
# we don't bother the user with this exact change on the next run
patchid $s/$f $dest/$f >> .skiplist
echo $s/$f $dest/$f >> .skiplist
# the patchid is the only important thing; the second line is more
# for the user's benefit, if he wants to examine the skiplist and
# maybe delete some entries manually
done
done
done 3< dac.dirs