-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.sh
executable file
·81 lines (69 loc) · 2.07 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /bin/bash
SKIPLIST=( '.gitconfigprivate' '.gitconfig' '.bash_history' '.viminfo' '.ssh' '..' '.' )
if [ "$2" = "skipcheck" ]; then
if [ "$1" = "install" ]; then
echo "installing: cp -r ./* ~/"
cp -r ./* ~/
elif [ "$1" = "upload" ]; then
echo "uploading: cp -r ~/\.* ./"
cp -r ~/\.* ./
else
echo "specify: install or upload"
exit 1
fi
exit 0
fi
function __contains () {
param=$1;
#echo "compare $1"
shift;
declare -a arr=("${!1}")
for elem in "${arr[@]}";
do
[[ "$param" == "$elem" ]] && return 1;
done;
#echo 'do not contain'
return 0
}
if [ "$1" = "install" ]; then
DEST_DIR="$HOME/"
SRC_DIR="./"
elif [ "$1" = "upload" ]; then
DEST_DIR="./"
SRC_DIR="$HOME/"
else
echo "specify: install or upload"
exit 1
fi
echo "DEST DIR: $DEST_DIR"
echo "SRC DIR: $SRC_DIR"
for d in $SRC_DIR.*
do
d=$(basename "$d")
__contains $d SKIPLIST[@];
if [[ $? -gt 0 || -z $(echo $d|egrep -v '*~') ]]; then
continue
fi
diff "$SRC_DIR$d" "$DEST_DIR$d" 2>/dev/null >/dev/null
RES=$?
echo "Comparing: $SRC_DIR$d vs $DEST_DIR$d res:$RES"
# 0 - no difference
# > 1 - error occured
if [[ $RES -eq 0 || $RES -gt 1 ]]; then
continue
fi
echo "\ninstalling $d:"
echo "===== diff start ====="
colordiff "$DEST_DIR$d" "$SRC_DIR$d" 2>/dev/null
echo "===== diff stop ====="
echo "Do you want to install $d?"
select yn in "y" "n" "q"; do
case "$REPLY" in
"y" ) echo "copy $SRC_DIR$d to $DEST_DIR"; cp -r $SRC_DIR$d $DEST_DIR; break;;
"n" ) break;;
"q" ) exit 0;;
* ) echo "print y, n or q";;
esac
done
done
exit 0