-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
executable file
·65 lines (55 loc) · 1.56 KB
/
sync.sh
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/sh
#
# Sync changes from local files into this repository so they can be committed
# for use on other machines.
set -e
R="$(dirname "$0")"
DIRECTION='in'
while getopts 'out:h' opt; do
case "$opt" in
o)
echo "Copying missing files to home directory..."
DIRECTION='out'
;;
O)
echo "Overwriting files in home directory..."
DIRECTION='overwrite'
;;
?|h)
echo "Usage: $(basename $0) [-a] [-b] [-c arg]"
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
# Sync all files in the repo home/ directory already.
for f in $(cd $R && find home -type f -not -name ".*" -not -name "*.md" | cut -c6-); do
# Copy the "." version from the home directory. We omit the "." here to
# make the times in the repo easier to work with.
live="$HOME/.$f"
store="$R/home/$f"
case "$DIRECTION" in
out)
if [ ! -f "$live" ]; then
echo "Initializing: $store -> $live"
mkdir -p "$(dirname "$live")"
cp "$store" "$live"
else
echo "File already present: $live"
fi
;;
overwrite)
echo "Overwriting: $store -> $live"
mkdir -p "$(dirname "$live")"
cp "$store" "$live"
;;
in)
if [ -f "$live" ]; then
echo "Syncing: $live -> $store"
cp "$live" "$store"
else
echo "Skipping sync for: $store"
fi
;;
esac
done