forked from tue-robotics/tue-env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcucr-data.bash
119 lines (98 loc) · 3.3 KB
/
cucr-data.bash
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /usr/bin/env bash
LOCAL_DATA_DIR=~/ros/data
REMOTE_DATA_DIR=/home/data/data
function cucr-data
{
# Temporary check
if [ -d ~/ros/data ] && [ ! -d ~/ros/data/private ]
then
mv ~/ros/data ~/ros/data-tmp-dir
mkdir -p ~/ros/data
mv ~/ros/data-tmp-dir ~/ros/data/private
echo -e "\e[0;33m[IMPORTANT] I moved the data folder. '~/ros/data' has now become '~/ros/data/private'\e[0m"
echo ""
fi
if [ -z "$1" ]
then
# shellcheck disable=SC1078,SC1079
echo """cucr-data is a tool for uploading data to and downloading data from the TU/e robotics server.
Usage: cucr-data COMMAND [ARG1 ARG2 ...]
Possible commands:
list - Lists contents of current folder on server
update - Downloads contents of current folder from server
update-dirs - Locally updates the data folder structure
store - Uploads current folder to server
"""
return 1
fi
local cmd
cmd=$1
shift
if [[ $cmd == "update-dirs" ]]
then
rsync -a --include='*/' --exclude='*' $ROBOTICSSRV_LOGIN:$REMOTE_DATA_DIR/ $LOCAL_DATA_DIR/ --progress
elif [[ $cmd == "list" ]]
then
# Check if user is in the data directory
if [[ $PWD != "$LOCAL_DATA_DIR"* ]]
then
echo "You are not in the data folder ('$LOCAL_DATA_DIR')"
return 1
fi
# Determine current directory relative to local data dir root
local rel_dir
rel_dir=${PWD#"${LOCAL_DATA_DIR}"}
# shellcheck disable=SC2029
ssh $ROBOTICSSRV_LOGIN "ls $REMOTE_DATA_DIR/$rel_dir -alh"
elif [[ $cmd == "update" ]]
then
# Check if user is in the data directory
if [[ $PWD != "$LOCAL_DATA_DIR"* ]]
then
echo "You are not in the data folder ('$LOCAL_DATA_DIR')"
return 1
fi
# Determine current directory relative to local data dir root
local rel_dir
rel_dir=${PWD#"${LOCAL_DATA_DIR}"}
rsync "$ROBOTICSSRV_LOGIN":"$REMOTE_DATA_DIR"/"$rel_dir"/ . -av --progress --exclude=".git"
elif [[ $cmd == "store" ]]
then
if [ -z "$1" ]
then
# shellcheck disable=SC1078,SC1079
echo """Usage: cucr-data store <FILE-OR-FOLDER>
For example, to store everything in the current folder, use:
cucr-data store .
"""
return 1
fi
local target
target="$1"
if [[ $target != "/"* ]]
then
target="$PWD/$target"
fi
# Check if user is in the data directory
if [[ $target != "$LOCAL_DATA_DIR"* ]]
then
echo "You are not in the data folder ('$LOCAL_DATA_DIR')"
return 1
fi
# Determine current directory relative to local data dir root
local rel_dir
rel_dir=${target#"${LOCAL_DATA_DIR}"}
rsync "$LOCAL_DATA_DIR"/./"$rel_dir" "$ROBOTICSSRV_LOGIN":"$REMOTE_DATA_DIR"/ -av --relative --progress --exclude=".git"
fi
}
function _cucr-data
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}
if [ "$COMP_CWORD" -eq 1 ]
then
mapfile -t COMPREPLY < <(compgen -W "update-dirs list update store" -- "$cur")
fi
}
complete -F _cucr-data cucr-data