-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhidesyncdf
More file actions
executable file
·73 lines (54 loc) · 1.8 KB
/
hidesyncdf
File metadata and controls
executable file
·73 lines (54 loc) · 1.8 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
#!/usr/bin/env bash
#
# copy hidden files from this repository into the HOME directory if the copy in
# the repository is newer--after backing up the version in the HOME directory.
#
function dgst {
openssl dgst "$1" | cut -d " " -f2
return $?
}
mkdir home-backup repo-backup 2>/dev/null
chmod -v -- 0700 home-backup repo-backup 2>/dev/null
## TODO: same thing for find ~/.* -type f
for adot in $(find ./ -type f -mindepth 1 -maxdepth 1 -name 'dot*' -exec basename {} \; 2>/dev/null); do
df=`echo "$adot" | sed 's!^dot!.!'`
ho="${HOME}/${df}"
dgst_df=`dgst "$df"` dgst_ho=`dgst "$ho"`
if [ ! "$dgst_df" -a "$dgst_ho" ]; then
echo '*** Backing up ' $df ' to repo-backup'
cp -av -- "$df" repo-backup
echo '*** Overwriting ' $df ' with ' $ho
cp -av -- "$ho" .
continue
else
if [ ! "$dgst_ho" -a "$dgst_df" ]; then
echo '*** Backing up ' $ho ' to home-backup'
cp -av -- "$ho" home-backup
echo '*** Overwriting ' $df ' with ' $ho
cp -av -- "$df" "$ho"
continue
else
if [ "$dgst_df" == "$dgst_ho" ]; then
echo '*** Contents of files are equal: ' $df ' and ' $ho
continue
else
if [ "$df" -nt "$ho" ]; then
echo '*** ' $df ' has a newer modification time than ' $ho
echo '*** Backing up ' $ho ' to home-backup'
cp -av -- "$ho" home-backup
cp -av -- "$df" "$ho"
echo '*** Wrote over ' $ho ' with ' $df
else
if [ "$ho" -nt "$df" ]; then
echo '*** ' $ho ' has a newer modification time than ' $df
echo '*** Backing up ' $ho ' to repo-backup'
cp -av -- "$df" repo-backup
cp -av -- "$ho" "$df"
echo '*** Wrote over ' $df ' with ' $ho
fi
fi
fi
fi
fi
done
exit 0