-
Notifications
You must be signed in to change notification settings - Fork 2
/
x-sync
executable file
·64 lines (55 loc) · 1.7 KB
/
x-sync
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
#!/bin/bash
#
# Synchronize local development machine with remote to be the same.
# It respects the .gitignore inputs
if [ "$#" -gt 1 ]; then
echo "Usage: x sync [pull|push]"
echo " no arguments - check local vs. remote and print sync state"
echo " pull - bring changes from remote"
echo " push - send changes to remote"
exit 1
fi
. $HOME/.x-tools
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $DIR/common
if [[ "$#" -ne 0 && r"$1" != r"pull" && r"$1" != r"push" ]]; then
echo "Unsupported option. Exiting ..."
exit 1
fi
CMD=$1
check_ssh_access $X_SYNC_REMOTE_SERVER
if [ "$REPLY" -ne 0 ]; then
echo "There is no SSH access to $X_SYNC_REMOTE_SERVER"
exit 1
fi
PROJECT=$( basename $PWD )
if [[ r"$CMD" == r"" ]]; then
echo "Not implemented yet ..."
#RET=$( rsync -avhz --dry-run --info=name0 --info=progress2 --delete-after $PWD $X_SYNC_REMOTE_SERVER::src/ | tail -n 1)
#echo $RET
#if [[ "$RET" != "$PROJECT/" ]]; then
# echo "No need in sync, directories are identical."
#else
# echo "There is a difference between local and remote directories."
#fi
fi
if [[ r"$CMD" == r"push" ]]; then
P_SRC=$PWD
P_DST="$X_SYNC_REMOTE_SERVER::src/"
K_SRC="$DIR/kconfig/config-minimal"
K_DST="$X_SYNC_REMOTE_SERVER::src/kernel/.config"
fi
if [[ r"$CMD" == r"pull" ]]; then
P_SRC="$X_SYNC_REMOTE_SERVER::src/$PROJECT"
P_DST="../"
K_SRC=" $X_SYNC_REMOTE_SERVER::src/kernel/.config"
K_DST=".config"
fi
rsync -avhz --info=name0 --info=progress2 --include='.git' --filter=':- .gitignore' --delete-after $P_SRC $P_DST
CURRDIR=$( basename `pwd` )
if [[ r"$CURRDIR" == r"kernel" ]]; then
rsync $K_SRC $K_DST
if [[ r"$CMD" == r"pull" ]]; then
git reset --hard HEAD
fi
fi