-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgsync.sh
More file actions
executable file
·35 lines (29 loc) · 856 Bytes
/
gsync.sh
File metadata and controls
executable file
·35 lines (29 loc) · 856 Bytes
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
#!/bin/sh
print_help() {
echo "This command syncs a go project to another machine with a configured \$GOPATH"
echo ""
echo "Usage: $0 source-go-project user@destinationHost "
echo ""
}
sync_go_projects(){
DEST_GO_PATH_FULL=$(ssh $DESTINATION "env" | grep GOPATH)
DEST_GO_PATH="$(echo $DEST_GO_PATH_FULL | cut -d "=" -f2)"
SOURCE_RELATIVE="$(echo $SOURCE | sed -e s,$GOPATH/,,g)"
DEST_ABSOLUTE="${DEST_GO_PATH}/${SOURCE_RELATIVE}"
echo "Local: \$GOPATH/${SOURCE_RELATIVE}"
echo "Full Dest: ${DEST_ABSOLUTE}"
ssh $DESTINATION "mkdir -p ${DEST_ABSOLUTE}"
rsync -aHep ssh $SOURCE/ $DESTINATION:$DEST_ABSOLUTE/
}
if [ -z "$1" ] || [ -z "$2" ]; then
print_help
exit 1
fi
SOURCE=`cd ${1};pwd`
if [[ $SOURCE =~ .*$GOPATH.* ]]; then
DESTINATION=$2
sync_go_projects
else
echo "$SOURCE is not in \$GOPATH, exiting..."
exit 1
fi