forked from Parrot-Developers/slamdunk_ros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathros_target.sh
executable file
·159 lines (143 loc) · 4.95 KB
/
ros_target.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#
# Copyright (c) 2016 Parrot S.A.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Parrot Company nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE PARROT COMPANY BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Usage()
{
cat << EOF
Usage: $1 [ -h ] [ -c ] [ -g ] [ -u <user> ] [ -d <device> ] -p package_name [ args...]
-h: this help
-c: copy to remote device
-g: generate on remote device
-u: remote user (default: ${SLAMDUNK_USER})
-d: remote device (default: ${SLAMDUNK_DEVICE})
-p: package name
Before to be used, you have to:
* initialize a ROS workspace on your Parrot S.L.A.M.dunk
* initialize a ROS workspace on your PC
It's recommended to copy your public SSH key on the Parrot S.L.A.M.dunk.
EOF
}
display_packages()
{
LIST=$( cd src ; /bin/ls | cat )
echo -n "Available packages:"
for x in ${LIST}; do
[ -d "src/${x}" ] && echo -n " ${x}"
done
echo
}
display_env_help()
{
echo "Remote environment not ready"
echo "ssh -t ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} \"sudo apt-get update && sudo apt-get install build-essential git\""
echo "ssh ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} \"source /opt/ros/indigo/setup.bash && mkdir -p ~/slamdunk_catkin_ws/src && cd ~/slamdunk_catkin_ws/src && catkin_init_workspace && cd ~/slamdunk_catkin_ws/ && catkin_make -j2\""
echo "Or follow instructions in \"/opt/ros-slamdunk/share/slamdunk_node/README.md\""
}
REMOTE_COPY=
REMOTE_GENERATE=
SLAMDUNK_USER="slamdunk"
SLAMDUNK_DEVICE="slamdunk-usb.local"
PACKAGE_NAME=
while getopts "hcgu:d:p:" opt; do
case $opt in
h)
Usage $0
exit 0
;;
c)
REMOTE_COPY="1"
;;
g)
REMOTE_GENERATE="1"
;;
u)
SLAMDUNK_USER=${OPTARG}
;;
d)
SLAMDUNK_DEVICE=${OPTARG}
;;
p)
PACKAGE_NAME=${OPTARG}
;;
esac
done
shift $((OPTIND-1))
ARGS=$*
# check that public key is used
ssh -o PasswordAuthentication=no ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} true >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "Please install SSH Key"
echo "ssh-copy-id ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE}"
exit 1
fi
CURRENT_DATE=$(date '+%s')
DEVICE_DATE=$(ssh ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} date '+%s')
DIFF_DATE=$((${CURRENT_DATE}-${DEVICE_DATE}))
if [ "${DEVICE_DATE}" -gt "${CURRENT_DATE}" ] || [ "${DIFF_DATE}" -gt "1" ]; then
echo "Setting Parrot S.L.A.M.dunk date ..."
ssh -t ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} "echo slamdunk | sudo -S date -s '@$(date +%s)'"
fi
if [ -n "${REMOTE_COPY}" ]; then
if [ ! -d "src" ]; then
echo "Cannot find directory src"
exit 1
fi
if [ -z "${PACKAGE_NAME}" ]; then
echo "Cannot find package name (option -p)"
display_packages
exit 1
fi
if [ ! -d "src/${PACKAGE_NAME}" ]; then
echo "Cannot find directory src/${PACKAGE_NAME}"
display_packages
exit 1
fi
ssh ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} "true"
if [ "$?" != "0" ]; then
echo "Cannot reach ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE}"
exit 1
fi
ssh ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} "[ ! -d slamdunk_catkin_ws/src ] && exit 1 || exit 0"
if [ "$?" != "0" ]; then
display_env_help
exit 1
fi
rsync -avz src/${PACKAGE_NAME} ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE}:slamdunk_catkin_ws/src/
fi
if [ -n "${REMOTE_GENERATE}" ]; then
ssh ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} "[ ! -r slamdunk_catkin_ws/devel/setup.bash ] && exit 1 || exit 0"
if [ "$?" != "0" ]; then
display_env_help
exit 1
fi
ssh ${SLAMDUNK_USER}@${SLAMDUNK_DEVICE} "cd slamdunk_catkin_ws && source devel/setup.bash && catkin_make ${ARGS}"
fi
if [ -z "${ROS_MASTER_URI}" ]; then
echo "Warning: ROS_MASTER_URI is not set"
fi
if [ -z "${ROS_HOSTNAME}" ]; then
echo "Warning: ROS_HOSTNAME is not set"
fi